虽然TVM支持透明代码生成,但有时将手动编写的代码合并到管道中也很有帮助。例如,我们想去为部分卷积和使用cuDNN和定义其他阶段。
TVM原生支持黑盒函数调用。TVM支持兼容DLPack的所有张量函数。这意味着我们可以使用POD类型(pointer,int,float)或指向DLTensor的指针作为参数调用任何函数。
from __future__ import absolute_import, print_function
import tvm
// attr [get_valid_counts_phase_one.v0] storage_scope = "global" | |
allocate get_valid_counts_phase_one.v0[int32 * 15360] | |
// attr [get_valid_counts_phase_one.v1] storage_scope = "global" | |
allocate get_valid_counts_phase_one.v1[int32 * 15360] | |
// attr [get_valid_counts_phase_two.v1] storage_scope = "global" | |
allocate get_valid_counts_phase_two.v1[int32 * 496] | |
// attr [get_valid_counts_phase_two.v0] storage_scope = "global" | |
allocate get_valid_counts_phase_two.v0[int32 * 15360] | |
// attr [get_valid_counts_phase_three] storage_scope = "global" | |
allocate get_valid_counts_phase_three[int32 * 496] |
""" | |
Quantization module for generating the calibration tables will be used by | |
quantized (INT8) models from FP32 models.with bucket split,[k, k, cin, cout] | |
cut into "cout" buckets. | |
This tool is based on Caffe Framework. | |
""" | |
from __future__ import division | |
from __future__ import print_function | |
import argparse | |
import numpy as np |
#include <random> | |
#include <iomanip> | |
#include <array> | |
#include <exception> | |
#define NDEBUG | |
#include <tvm/tvm.h> | |
#include <tvm/build_module.h> | |
#include <topi/broadcast.h> | |
#undef NDEBUG |
import tvm | |
from tvm import relay | |
def test_fuse_simple(): | |
"""Simple testcase.""" | |
def before(): | |
x = relay.var("x", shape=(10, 20)) | |
y = relay.add(x, relay.const(1, "float32")) | |
z = relay.exp(y) | |
return relay.Function([x], z) |
import tvm | |
import topi | |
import numpy as np | |
from tvm.testing import check_numerical_grads, estimate_performance, PerformanceEstimate | |
import time | |
import inspect | |
import sys | |
from exercise.runners import run_tvm | |
# Whether to dump the generated code |
#include <iostream> | |
#include <chrono> | |
#include <stdexcept> | |
#include <memory> | |
#include <fstream> | |
#include <iterator> | |
#include <algorithm> | |
#include <tvm/runtime/module.h> | |
#include <tvm/runtime/registry.h> |