SlideShare a Scribd company logo
TVM VTA (TSIM) ソースコード解析
Verilog HDL/Chisel のコードを
Verilator(+DPI) で繋いで、
Pythonからどのように使っているのか?
Created date:2020.03.15

@Vengineer



TVM TSIM
vta-hw/hardware/dpi/tsim_device.cc
module TestAccel(
input clock,
input reset,
input sim_clock,
output sim_wait
);
clock
reset
dpi/module.cc
SimDPI
MemDPI
HostDPI
VTADeviceRun
tsim/tsim_driver.cc
CommandQueue::
Synchronize
SystemVerilog
de10nano/de10nano_driver.cc
pynq/pynq_driver.cc
tsim/tsim_driver.cc
sim/sim_driver.cc
VTASimDPI
VTAMemDPI
VTAHostDPI
Verilator DPI
Accel
TVM TSIM
VTASimDPI
VTAMemDPI
VTAHostDPI
vta-hw/hardware/chisel/src/main/scala/test/Test.scala
VTAShell
dpi/module.cc
SimDPI
MemDPI
HostDPI
VTADeviceRun
tsim/tsim_driver.cc
CommandQueue::
Synchronize
Verilator DPI
Chisel
de10nano/de10nano_driver.cc
pynq/pynq_driver.cc
tsim/tsim_driver.cc
sim/sim_driver.cc
SimShell Test
TVM TSIM
VTADeviceRun
int VTADeviceRun(VTADeviceHandle handle,
vta_phy_addr_t insn_phy_addr,
uint32_t insn_count,
uint32_t wait_cycles) {
return static_cast<vta::tsim::Device*>(handle)->Run(
insn_phy_addr,
insn_count,
wait_cycles);
}
TVM TSIM
VTADevicevta::tsim::Device::Run
int Run(vta_phy_addr_t insn_phy_addr,
uint32_t insn_count,
uint32_t wait_cycles) {
this->Init();
this->Launch(insn_phy_addr,
insn_count,
wait_cycles);
this->WaitForCompletion(wait_cycles);
return 0;
}
TVM TSIM
VTADevicevta::tsim::Device::Init
void Init() {
dpi_ = loader_->Get();
dpi_->SimResume();
}
Device() {
loader_ = DPILoader::Global();
prof_ = Profiler::Global();
}
class DPILoader {
DPIModuleNode* Get() {
return
static_cast<DPIModuleNode*>( mod_.operato
r->());
}
void Init(Module module) {
mod_ = module;
dpi_ = this->Get();
dpi_->SimLaunch();
dpi_->SimWait();
}
TVM_REGISTER_GLOBAL(" vta.tsim.init")
.set_body([](TVMArgs args, TVMRetValue*
rv) {
Module m = args[0];
DPILoader::Global()->Init(m);
});
TVM TSIM
VTADevice::vta::tsim::Device::Launch
void Launch(vta_phy_addr_t insn_phy_addr,
uint32_t insn_count,
uint32_t wait_cycles) {
dpi_->WriteReg(0x08, insn_count);
dpi_->WriteReg(0x0c, insn_phy_addr);
dpi_->WriteReg(0x10, 0);
dpi_->WriteReg(0x14, 0);
dpi_->WriteReg(0x18, 0);
dpi_->WriteReg(0x1c, 0);
dpi_->WriteReg(0x20, 0);
// start
dpi_->WriteReg(0x00, 0x1);
}
TVM TSIM
VTADevicevta::tsim::Device::WaitForCompletion
void WaitForCompletion (uint32_t wait_cycles) {
uint32_t i, val;
for (i = 0; i < wait_cycles; i++) {
val = dpi_->ReadReg(0x00);
val &= 0x2;
if (val == 0x2) break; // finish
}
prof_->Update(0, dpi_->ReadReg(0x04));
dpi_->SimWait();
}
テストコード
vta-hw/apps/tsim_example/tests/python/verilog_accel.py
vta-hw/apps/tsim_example/tests/python/chisel_accel.py
TVM TSIM : apps/python
vta-hw/apps/tsim_example/tests/python/verilog_accel.py
if __name__ == "__main__":
tsim.init("verilog") => Verilog HDL モデルの初期化
for i in range(10):
test_accel()
vta-hw/apps/tsim_example/tests/python/chisel_accel.py
if __name__ == "__main__":
tsim.init("chisel") => Chisel モデルの初期化
for i in range(10):
test_accel()
TVM TSIM : apps/python
vta-hw/apps/tsim_example/python/tsim.py
def init(hw_backend):
"""Init hardware and software shared library for accelerator
Parameters
------------
hw_backend : str
Hardware backend can be verilog or chisel
"""
cur_path = osp.dirname(osp.abspath(osp.expanduser(__file__)))
hw_libname = "libhw" + get_ext()
if hw_backend in ("verilog", "chisel"):
hw_lib = osp.join(cur_path, "..", "hardware", hw_backend, "build",
hw_libname)
load_sw()
m = tvm.runtime.load_module(hw_lib, "vta-tsim")
f = tvm.get_global_func("tvm.vta.tsim.init")
f(m)
TVM TSIM : apps/python (verilog_accel)
vta-hw/apps/tsim_example/tests/python/verilog_accel.py
def test_accel():
rmax = 64
dtype = "uint64"
n = np.random.randint(1, rmax)
c = np.random.randint(0, rmax)
ctx = tvm.cpu(0)
a = tvm.nd.array(np.random.randint(rmax, size=n).astype(dtype), ctx)
b = tvm.nd.array(np.zeros(n).astype(dtype), ctx)
f = tsim.load_module() => 関数の獲得
cycles = f(a, b, c) => 関数の実行
msg = "cycles:{0:4} n:{1:2} c:{2:2}".format(cycles, n, c)
np.testing.assert_equal( b.asnumpy(), a.asnumpy() + c, err_msg = "[FAIL] " +
msg)
print("[PASS] " + msg)
TVM TSIM : apps/python (chisel_accel)
vta-hw/apps/tsim_example/tests/python/chisel_accel.py
def test_accel():
rmax = 64
dtype = "uint64"
n = np.random.randint(1, rmax)
c = np.random.randint(0, rmax)
ctx = tvm.cpu(0)
a = tvm.nd.array(np.random.randint(rmax, size=n).astype(dtype), ctx)
b = tvm.nd.array(np.zeros(n).astype(dtype), ctx)
f = tsim.load_module() => 関数の獲得
cycles = f(a, b, c) => 関数の実行
msg = "cycles:{0:4} n:{1:2} c:{2:2}".format(cycles, n, c)
np.testing.assert_equal( b.asnumpy(), a.asnumpy() + c, err_msg = "[FAIL] " +
msg)
print("[PASS] " + msg)
TVM TSIM : apps/python (tsim.load_module)
vta-hw/apps/tsim_example/python/tsim.py
def load_module():
"""Return driver function"""
load_sw()
return tvm.get_global_func("tvm.vta.driver")
TVM TSIM : apps/python (tvm.vta.driver)
vta-hw/apps/tsim_example/src/driver.cc
TVM_REGISTER_GLOBAL(" tvm.vta.driver")
.set_body([](TVMArgs args, TVMRetValue* rv) {
Device dev_;
DLTensor* A = args[0];
DLTensor* B = args[1];
uint32_t c = static_cast<int>(args[2]);
uint32_t cycles = dev_.Run(c, A, B);
*rv = static_cast<int>(cycles);
});
TVM TSIM : dev_.Run
vta-hw/apps/tsim_example/src/driver.cc
uint32_t Run(uint32_t c, DLTensor* a, DLTensor* b) {
uint32_t cycles;
uint32_t len = a->shape[0];
size_t size = (a->dtype.bits >> 3) * len;
a_ = this->MemAlloc(size);
b_ = this->MemAlloc(size);
this->MemCopyFromHost(a_, a->data, size);
this->Init();
this->Launch(c, len);
cycles = this->WaitForCompletion();
this->MemCopyToHost(b->data, b_, size);
this->MemFree(a_);
this->MemFree(b_);
return cycles;
}
TVM TSIM : Init / Launch
vta-hw/apps/tsim_example/src/driver.cc
void Init() {
dpi_ = loader_->Get();
dpi_->SimResume();
}
void Launch(uint32_t c, uint32_t len) {
dpi_->WriteReg(0x08, c);
dpi_->WriteReg(0x0c, len);
dpi_->WriteReg(0x10, this->MemGetPhyAddr(a_));
dpi_->WriteReg(0x14, 0);
dpi_->WriteReg(0x18, this->MemGetPhyAddr(b_));
dpi_->WriteReg(0x1c, 0);
dpi_->WriteReg(0x00, 0x1); // launch
}
TVM TSIM : WaitForCompletion
vta-hw/apps/tsim_example/src/driver.cc
uint32_t WaitForCompletion () {
uint32_t i, val;
for (i = 0; i < wait_cycles_; i++) {
val = dpi_->ReadReg(0x00);
if (val == 2) break; // finish
}
val = dpi_->ReadReg(0x04);
dpi_->SimWait();
return val;
}
シミュレーション制御
シミュレーション制御メソッド
vta-hw/src/dpi/module.cc
void SimLaunch() {
auto frun = [this]() {
(*ftsim_)();
};
tsim_thread_ = std::thread(frun);
}
void SimFinish() {
sim_device_. Exit();
tsim_thread_.join();
}
void SimWait() {
sim_device_. Wait();
}
void SimResume() {
sim_device_. Resume();
}
~DPILoader() {
dpi_->SimResume();
dpi_->SimFinish();
}}
class DPILoader {
void Init(Module module)
{
mod_ = module;
dpi_ = this->Get();
dpi_->SimLaunch();
dpi_->SimWait();
}
シミュレーション制御メソッド
vta-hw/src/tsim/tsim_driver.cc
TVM_REGISTER_GLOBAL(" vta.tsim.init")
.set_body([](TVMArgs args, TVMRetValue*
rv) {
Module m = args[0];
DPILoader::Global()-> Init(m);
});
class DPILoader {
void Init(Module module)
{
mod_ = module;
dpi_ = this->Get();
dpi_->SimLaunch();
dpi_->SimWait();
}
シミュレーション制御メソッド
vta-hw/src/dpi/module.cc
void SimDevice:: Wait() {
std::unique_lock<std::mutex>
lock(mutex_);
wait_ = true;
}
void SimDevice:: Resume() {
std::unique_lock<std::mutex>
lock(mutex_);
wait_ = false;
}
void SimDevice:: Exit() {
std::unique_lock<std::mutex>
lock(mutex_);
exit_ = true;
}
シミュレーション制御メソッド
vta-hw/src/dpi/module.cc
void SimDPI(dpi8_t* wait,
dpi8_t* exit) {
*wait = sim_device_. GetWaitStatus();
*exit = sim_device_. GetExitStatus();
}
bool SimDevice:: GetWaitStatus() {
std::unique_lock<std::mutex> lock(mutex_);
return wait_;
}
bool SimDevice:: GetExitStatus() {
std::unique_lock<std::mutex> lock(mutex_);
return exit_;
}
SimDPI
MemDPI
Verilator DPI
HostDPI
I am a computer engineer,
not a deep learning craftsman




ありがとうございました。
Thanks
@Vengineer
ソースコード解析職人
Source code analysis craftsman

More Related Content

What's hot

Rust で RTOS を考える
Rust で RTOS を考えるRust で RTOS を考える
Rust で RTOS を考える
ryuz88
 
VerilatorとSystemC
VerilatorとSystemCVerilatorとSystemC
VerilatorとSystemC
Mr. Vengineer
 
TVM の紹介
TVM の紹介TVM の紹介
TVM の紹介
Masahiro Masuda
 
UnrealEngine4で合成音声を使いたい
UnrealEngine4で合成音声を使いたいUnrealEngine4で合成音声を使いたい
UnrealEngine4で合成音声を使いたい
Itsuki Inoue
 
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
Chica Matsueda
 
Gocon2017:Goのロギング周りの考察
Gocon2017:Goのロギング周りの考察Gocon2017:Goのロギング周りの考察
Gocon2017:Goのロギング周りの考察
貴仁 大和屋
 
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
Fixstars Corporation
 
WebRTCで動かす“テレイグジスタンス”ロボット
WebRTCで動かす“テレイグジスタンス”ロボットWebRTCで動かす“テレイグジスタンス”ロボット
WebRTCで動かす“テレイグジスタンス”ロボット
NTT Communications Technology Development
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうか
Yuki Miyatake
 
WPF .NET Core でも XAML デザイナをあきらめない
WPF .NET Core でも XAML デザイナをあきらめないWPF .NET Core でも XAML デザイナをあきらめない
WPF .NET Core でも XAML デザイナをあきらめない
m ishizaki
 
いまさら聞けないarmを使ったNEONの基礎と活用事例
いまさら聞けないarmを使ったNEONの基礎と活用事例いまさら聞けないarmを使ったNEONの基礎と活用事例
いまさら聞けないarmを使ったNEONの基礎と活用事例
Fixstars Corporation
 
高速な倍精度指数関数expの実装
高速な倍精度指数関数expの実装高速な倍精度指数関数expの実装
高速な倍精度指数関数expの実装
MITSUNARI Shigeo
 
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
祐司 伊藤
 
ソフトウェア技術者はFPGAをどのように使うか
ソフトウェア技術者はFPGAをどのように使うかソフトウェア技術者はFPGAをどのように使うか
ソフトウェア技術者はFPGAをどのように使うかなおき きしだ
 
Node.js Native ESM への道 〜最終章: Babel / TypeScript Modules との闘い〜
Node.js Native ESM への道  〜最終章: Babel / TypeScript Modules との闘い〜Node.js Native ESM への道  〜最終章: Babel / TypeScript Modules との闘い〜
Node.js Native ESM への道 〜最終章: Babel / TypeScript Modules との闘い〜
Teppei Sato
 
Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409
稔 小林
 
ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料
直久 住川
 
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
Deep Learning JP
 
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
Unity Technologies Japan K.K.
 
TensorFlow計算グラフ最適化処理
TensorFlow計算グラフ最適化処理TensorFlow計算グラフ最適化処理
TensorFlow計算グラフ最適化処理
Atsushi Nukariya
 

What's hot (20)

Rust で RTOS を考える
Rust で RTOS を考えるRust で RTOS を考える
Rust で RTOS を考える
 
VerilatorとSystemC
VerilatorとSystemCVerilatorとSystemC
VerilatorとSystemC
 
TVM の紹介
TVM の紹介TVM の紹介
TVM の紹介
 
UnrealEngine4で合成音声を使いたい
UnrealEngine4で合成音声を使いたいUnrealEngine4で合成音声を使いたい
UnrealEngine4で合成音声を使いたい
 
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
MediaPipeを使ったARアプリ開発事例 ~カメラをかざして家䛾中で売れるも䛾を探そう~
 
Gocon2017:Goのロギング周りの考察
Gocon2017:Goのロギング周りの考察Gocon2017:Goのロギング周りの考察
Gocon2017:Goのロギング周りの考察
 
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
 
WebRTCで動かす“テレイグジスタンス”ロボット
WebRTCで動かす“テレイグジスタンス”ロボットWebRTCで動かす“テレイグジスタンス”ロボット
WebRTCで動かす“テレイグジスタンス”ロボット
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうか
 
WPF .NET Core でも XAML デザイナをあきらめない
WPF .NET Core でも XAML デザイナをあきらめないWPF .NET Core でも XAML デザイナをあきらめない
WPF .NET Core でも XAML デザイナをあきらめない
 
いまさら聞けないarmを使ったNEONの基礎と活用事例
いまさら聞けないarmを使ったNEONの基礎と活用事例いまさら聞けないarmを使ったNEONの基礎と活用事例
いまさら聞けないarmを使ったNEONの基礎と活用事例
 
高速な倍精度指数関数expの実装
高速な倍精度指数関数expの実装高速な倍精度指数関数expの実装
高速な倍精度指数関数expの実装
 
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
 
ソフトウェア技術者はFPGAをどのように使うか
ソフトウェア技術者はFPGAをどのように使うかソフトウェア技術者はFPGAをどのように使うか
ソフトウェア技術者はFPGAをどのように使うか
 
Node.js Native ESM への道 〜最終章: Babel / TypeScript Modules との闘い〜
Node.js Native ESM への道  〜最終章: Babel / TypeScript Modules との闘い〜Node.js Native ESM への道  〜最終章: Babel / TypeScript Modules との闘い〜
Node.js Native ESM への道 〜最終章: Babel / TypeScript Modules との闘い〜
 
Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409
 
ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料ACRiウェビナー:小野様ご講演資料
ACRiウェビナー:小野様ご講演資料
 
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
[DL輪読会]BANMo: Building Animatable 3D Neural Models from Many Casual Videos
 
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
【CEDEC2018】一歩先のUnityでのパフォーマンス/メモリ計測、デバッグ術
 
TensorFlow計算グラフ最適化処理
TensorFlow計算グラフ最適化処理TensorFlow計算グラフ最適化処理
TensorFlow計算グラフ最適化処理
 

Similar to TVM VTA (TSIM)

XilinxのxsimでSoftware Driven Verification.pdf
XilinxのxsimでSoftware  Driven Verification.pdfXilinxのxsimでSoftware  Driven Verification.pdf
XilinxのxsimでSoftware Driven Verification.pdf
Mr. Vengineer
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
yaman dua
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
PVS-Studio
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
Andrey Karpov
 
Debugging & profiling node.js
Debugging & profiling node.jsDebugging & profiling node.js
Debugging & profiling node.js
tomasperezv
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on Session
Razvan Musaloiu-E.
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
Mr. Vengineer
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloads
Bram Vogelaar
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
Andrey Karpov
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Max Kleiner
 
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
KAI CHU CHUNG
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
antiw
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32
HANCOM MDS
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화
NAVER D2
 
[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화
NAVER D2
 
JIT compilation for CPython
JIT compilation for CPythonJIT compilation for CPython
JIT compilation for CPython
delimitry
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
Kevin Keraudren
 
Monitoring InfluxEnterprise
Monitoring InfluxEnterpriseMonitoring InfluxEnterprise
Monitoring InfluxEnterprise
InfluxData
 

Similar to TVM VTA (TSIM) (20)

XilinxのxsimでSoftware Driven Verification.pdf
XilinxのxsimでSoftware  Driven Verification.pdfXilinxのxsimでSoftware  Driven Verification.pdf
XilinxのxsimでSoftware Driven Verification.pdf
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Debugging & profiling node.js
Debugging & profiling node.jsDebugging & profiling node.js
Debugging & profiling node.js
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on Session
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloads
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2
 
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화
 
[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화
 
JIT compilation for CPython
JIT compilation for CPythonJIT compilation for CPython
JIT compilation for CPython
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
 
Monitoring InfluxEnterprise
Monitoring InfluxEnterpriseMonitoring InfluxEnterprise
Monitoring InfluxEnterprise
 

More from Mr. Vengineer

VerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven VerificationVerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven Verification
Mr. Vengineer
 
Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析
Mr. Vengineer
 
Cloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceCloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & Inference
Mr. Vengineer
 
TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?
Mr. Vengineer
 
Pixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysisPixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysis
Mr. Vengineer
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Mr. Vengineer
 
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
Mr. Vengineer
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
Mr. Vengineer
 
Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会
Mr. Vengineer
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Mr. Vengineer
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Mr. Vengineer
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
Mr. Vengineer
 
TensorFlow local Python XLA client
TensorFlow local Python XLA clientTensorFlow local Python XLA client
TensorFlow local Python XLA client
Mr. Vengineer
 
LeFlowを調べてみました
LeFlowを調べてみましたLeFlowを調べてみました
LeFlowを調べてみました
Mr. Vengineer
 
Tensorflow dynamically loadable XLA plugin ソースコード解析
Tensorflow  dynamically loadable XLA plugin ソースコード解析Tensorflow  dynamically loadable XLA plugin ソースコード解析
Tensorflow dynamically loadable XLA plugin ソースコード解析
Mr. Vengineer
 
Tiramisu概要
Tiramisu概要Tiramisu概要
Tiramisu概要
Mr. Vengineer
 
Tensor comprehensions
Tensor comprehensionsTensor comprehensions
Tensor comprehensions
Mr. Vengineer
 
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network APITensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
Mr. Vengineer
 
「ディープラーニングでは、エコシステムが大切よ!」
 「ディープラーニングでは、エコシステムが大切よ!」 「ディープラーニングでは、エコシステムが大切よ!」
「ディープラーニングでは、エコシステムが大切よ!」
Mr. Vengineer
 
TensorFlow XLA とハードウェア
TensorFlow XLA とハードウェアTensorFlow XLA とハードウェア
TensorFlow XLA とハードウェア
Mr. Vengineer
 

More from Mr. Vengineer (20)

VerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven VerificationVerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven Verification
 
Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析
 
Cloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceCloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & Inference
 
TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?
 
Pixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysisPixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysis
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
 
Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
TensorFlow local Python XLA client
TensorFlow local Python XLA clientTensorFlow local Python XLA client
TensorFlow local Python XLA client
 
LeFlowを調べてみました
LeFlowを調べてみましたLeFlowを調べてみました
LeFlowを調べてみました
 
Tensorflow dynamically loadable XLA plugin ソースコード解析
Tensorflow  dynamically loadable XLA plugin ソースコード解析Tensorflow  dynamically loadable XLA plugin ソースコード解析
Tensorflow dynamically loadable XLA plugin ソースコード解析
 
Tiramisu概要
Tiramisu概要Tiramisu概要
Tiramisu概要
 
Tensor comprehensions
Tensor comprehensionsTensor comprehensions
Tensor comprehensions
 
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network APITensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
 
「ディープラーニングでは、エコシステムが大切よ!」
 「ディープラーニングでは、エコシステムが大切よ!」 「ディープラーニングでは、エコシステムが大切よ!」
「ディープラーニングでは、エコシステムが大切よ!」
 
TensorFlow XLA とハードウェア
TensorFlow XLA とハードウェアTensorFlow XLA とハードウェア
TensorFlow XLA とハードウェア
 

Recently uploaded

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
peuce
 
web-tech-lab-manual-final-abhas.pdf. Jer
web-tech-lab-manual-final-abhas.pdf. Jerweb-tech-lab-manual-final-abhas.pdf. Jer
web-tech-lab-manual-final-abhas.pdf. Jer
freshgammer09
 
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
aozcue
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
aozcue
 
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
Peter Gallagher
 
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
andreassenrolf537
 
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
PinkySharma900491
 

Recently uploaded (7)

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
 
web-tech-lab-manual-final-abhas.pdf. Jer
web-tech-lab-manual-final-abhas.pdf. Jerweb-tech-lab-manual-final-abhas.pdf. Jer
web-tech-lab-manual-final-abhas.pdf. Jer
 
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
一比一原版(UCSB毕业证)圣塔芭芭拉社区大学毕业证如何办理
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证如何办理
 
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR - Slides Onl...
 
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
欧洲杯冠军-欧洲杯冠军网站-欧洲杯冠军|【​网址​🎉ac123.net🎉​】领先全球的买球投注平台
 
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
MATHEMATICS BRIDGE COURSE (TEN DAYS PLANNER) (FOR CLASS XI STUDENTS GOING TO ...
 

TVM VTA (TSIM)

  • 1. TVM VTA (TSIM) ソースコード解析 Verilog HDL/Chisel のコードを Verilator(+DPI) で繋いで、 Pythonからどのように使っているのか? Created date:2020.03.15
 @Vengineer
 

  • 2. TVM TSIM vta-hw/hardware/dpi/tsim_device.cc module TestAccel( input clock, input reset, input sim_clock, output sim_wait ); clock reset dpi/module.cc SimDPI MemDPI HostDPI VTADeviceRun tsim/tsim_driver.cc CommandQueue:: Synchronize SystemVerilog de10nano/de10nano_driver.cc pynq/pynq_driver.cc tsim/tsim_driver.cc sim/sim_driver.cc VTASimDPI VTAMemDPI VTAHostDPI Verilator DPI Accel
  • 4. TVM TSIM VTADeviceRun int VTADeviceRun(VTADeviceHandle handle, vta_phy_addr_t insn_phy_addr, uint32_t insn_count, uint32_t wait_cycles) { return static_cast<vta::tsim::Device*>(handle)->Run( insn_phy_addr, insn_count, wait_cycles); }
  • 5. TVM TSIM VTADevicevta::tsim::Device::Run int Run(vta_phy_addr_t insn_phy_addr, uint32_t insn_count, uint32_t wait_cycles) { this->Init(); this->Launch(insn_phy_addr, insn_count, wait_cycles); this->WaitForCompletion(wait_cycles); return 0; }
  • 6. TVM TSIM VTADevicevta::tsim::Device::Init void Init() { dpi_ = loader_->Get(); dpi_->SimResume(); } Device() { loader_ = DPILoader::Global(); prof_ = Profiler::Global(); } class DPILoader { DPIModuleNode* Get() { return static_cast<DPIModuleNode*>( mod_.operato r->()); } void Init(Module module) { mod_ = module; dpi_ = this->Get(); dpi_->SimLaunch(); dpi_->SimWait(); } TVM_REGISTER_GLOBAL(" vta.tsim.init") .set_body([](TVMArgs args, TVMRetValue* rv) { Module m = args[0]; DPILoader::Global()->Init(m); });
  • 7. TVM TSIM VTADevice::vta::tsim::Device::Launch void Launch(vta_phy_addr_t insn_phy_addr, uint32_t insn_count, uint32_t wait_cycles) { dpi_->WriteReg(0x08, insn_count); dpi_->WriteReg(0x0c, insn_phy_addr); dpi_->WriteReg(0x10, 0); dpi_->WriteReg(0x14, 0); dpi_->WriteReg(0x18, 0); dpi_->WriteReg(0x1c, 0); dpi_->WriteReg(0x20, 0); // start dpi_->WriteReg(0x00, 0x1); }
  • 8. TVM TSIM VTADevicevta::tsim::Device::WaitForCompletion void WaitForCompletion (uint32_t wait_cycles) { uint32_t i, val; for (i = 0; i < wait_cycles; i++) { val = dpi_->ReadReg(0x00); val &= 0x2; if (val == 0x2) break; // finish } prof_->Update(0, dpi_->ReadReg(0x04)); dpi_->SimWait(); }
  • 10. TVM TSIM : apps/python vta-hw/apps/tsim_example/tests/python/verilog_accel.py if __name__ == "__main__": tsim.init("verilog") => Verilog HDL モデルの初期化 for i in range(10): test_accel() vta-hw/apps/tsim_example/tests/python/chisel_accel.py if __name__ == "__main__": tsim.init("chisel") => Chisel モデルの初期化 for i in range(10): test_accel()
  • 11. TVM TSIM : apps/python vta-hw/apps/tsim_example/python/tsim.py def init(hw_backend): """Init hardware and software shared library for accelerator Parameters ------------ hw_backend : str Hardware backend can be verilog or chisel """ cur_path = osp.dirname(osp.abspath(osp.expanduser(__file__))) hw_libname = "libhw" + get_ext() if hw_backend in ("verilog", "chisel"): hw_lib = osp.join(cur_path, "..", "hardware", hw_backend, "build", hw_libname) load_sw() m = tvm.runtime.load_module(hw_lib, "vta-tsim") f = tvm.get_global_func("tvm.vta.tsim.init") f(m)
  • 12. TVM TSIM : apps/python (verilog_accel) vta-hw/apps/tsim_example/tests/python/verilog_accel.py def test_accel(): rmax = 64 dtype = "uint64" n = np.random.randint(1, rmax) c = np.random.randint(0, rmax) ctx = tvm.cpu(0) a = tvm.nd.array(np.random.randint(rmax, size=n).astype(dtype), ctx) b = tvm.nd.array(np.zeros(n).astype(dtype), ctx) f = tsim.load_module() => 関数の獲得 cycles = f(a, b, c) => 関数の実行 msg = "cycles:{0:4} n:{1:2} c:{2:2}".format(cycles, n, c) np.testing.assert_equal( b.asnumpy(), a.asnumpy() + c, err_msg = "[FAIL] " + msg) print("[PASS] " + msg)
  • 13. TVM TSIM : apps/python (chisel_accel) vta-hw/apps/tsim_example/tests/python/chisel_accel.py def test_accel(): rmax = 64 dtype = "uint64" n = np.random.randint(1, rmax) c = np.random.randint(0, rmax) ctx = tvm.cpu(0) a = tvm.nd.array(np.random.randint(rmax, size=n).astype(dtype), ctx) b = tvm.nd.array(np.zeros(n).astype(dtype), ctx) f = tsim.load_module() => 関数の獲得 cycles = f(a, b, c) => 関数の実行 msg = "cycles:{0:4} n:{1:2} c:{2:2}".format(cycles, n, c) np.testing.assert_equal( b.asnumpy(), a.asnumpy() + c, err_msg = "[FAIL] " + msg) print("[PASS] " + msg)
  • 14. TVM TSIM : apps/python (tsim.load_module) vta-hw/apps/tsim_example/python/tsim.py def load_module(): """Return driver function""" load_sw() return tvm.get_global_func("tvm.vta.driver")
  • 15. TVM TSIM : apps/python (tvm.vta.driver) vta-hw/apps/tsim_example/src/driver.cc TVM_REGISTER_GLOBAL(" tvm.vta.driver") .set_body([](TVMArgs args, TVMRetValue* rv) { Device dev_; DLTensor* A = args[0]; DLTensor* B = args[1]; uint32_t c = static_cast<int>(args[2]); uint32_t cycles = dev_.Run(c, A, B); *rv = static_cast<int>(cycles); });
  • 16. TVM TSIM : dev_.Run vta-hw/apps/tsim_example/src/driver.cc uint32_t Run(uint32_t c, DLTensor* a, DLTensor* b) { uint32_t cycles; uint32_t len = a->shape[0]; size_t size = (a->dtype.bits >> 3) * len; a_ = this->MemAlloc(size); b_ = this->MemAlloc(size); this->MemCopyFromHost(a_, a->data, size); this->Init(); this->Launch(c, len); cycles = this->WaitForCompletion(); this->MemCopyToHost(b->data, b_, size); this->MemFree(a_); this->MemFree(b_); return cycles; }
  • 17. TVM TSIM : Init / Launch vta-hw/apps/tsim_example/src/driver.cc void Init() { dpi_ = loader_->Get(); dpi_->SimResume(); } void Launch(uint32_t c, uint32_t len) { dpi_->WriteReg(0x08, c); dpi_->WriteReg(0x0c, len); dpi_->WriteReg(0x10, this->MemGetPhyAddr(a_)); dpi_->WriteReg(0x14, 0); dpi_->WriteReg(0x18, this->MemGetPhyAddr(b_)); dpi_->WriteReg(0x1c, 0); dpi_->WriteReg(0x00, 0x1); // launch }
  • 18. TVM TSIM : WaitForCompletion vta-hw/apps/tsim_example/src/driver.cc uint32_t WaitForCompletion () { uint32_t i, val; for (i = 0; i < wait_cycles_; i++) { val = dpi_->ReadReg(0x00); if (val == 2) break; // finish } val = dpi_->ReadReg(0x04); dpi_->SimWait(); return val; }
  • 20. シミュレーション制御メソッド vta-hw/src/dpi/module.cc void SimLaunch() { auto frun = [this]() { (*ftsim_)(); }; tsim_thread_ = std::thread(frun); } void SimFinish() { sim_device_. Exit(); tsim_thread_.join(); } void SimWait() { sim_device_. Wait(); } void SimResume() { sim_device_. Resume(); } ~DPILoader() { dpi_->SimResume(); dpi_->SimFinish(); }} class DPILoader { void Init(Module module) { mod_ = module; dpi_ = this->Get(); dpi_->SimLaunch(); dpi_->SimWait(); }
  • 21. シミュレーション制御メソッド vta-hw/src/tsim/tsim_driver.cc TVM_REGISTER_GLOBAL(" vta.tsim.init") .set_body([](TVMArgs args, TVMRetValue* rv) { Module m = args[0]; DPILoader::Global()-> Init(m); }); class DPILoader { void Init(Module module) { mod_ = module; dpi_ = this->Get(); dpi_->SimLaunch(); dpi_->SimWait(); }
  • 22. シミュレーション制御メソッド vta-hw/src/dpi/module.cc void SimDevice:: Wait() { std::unique_lock<std::mutex> lock(mutex_); wait_ = true; } void SimDevice:: Resume() { std::unique_lock<std::mutex> lock(mutex_); wait_ = false; } void SimDevice:: Exit() { std::unique_lock<std::mutex> lock(mutex_); exit_ = true; }
  • 23. シミュレーション制御メソッド vta-hw/src/dpi/module.cc void SimDPI(dpi8_t* wait, dpi8_t* exit) { *wait = sim_device_. GetWaitStatus(); *exit = sim_device_. GetExitStatus(); } bool SimDevice:: GetWaitStatus() { std::unique_lock<std::mutex> lock(mutex_); return wait_; } bool SimDevice:: GetExitStatus() { std::unique_lock<std::mutex> lock(mutex_); return exit_; } SimDPI MemDPI Verilator DPI HostDPI
  • 24. I am a computer engineer, not a deep learning craftsman 
 
 ありがとうございました。 Thanks @Vengineer ソースコード解析職人 Source code analysis craftsman