Append a custom target for TVM Context

We have a custom accelerator that uses the OpenCL frontend. We want to include this as a custom type like the aocl within the TVM pipeline. How do we go about introducing a new target for the same? (we aim to give our custom accelerator as the target parameter for tvm.context)

1 Like

You can first register a target using TVM_REGISTER_TARGET_KIND macro in https://github.com/apache/incubator-tvm/blob/master/src/target/target_kind.cc. Then register OpenCL codegen as your backend.

This doc can help you get familiar with the compilation flow, and you can add corresponding compoents for your accelerator:

https://tvm.apache.org/docs/dev/codebase_walkthrough.html

Hey @comaniac Thanks that was helpful. So if i register a new target “newName” for example like

TVM_REGISTER_TARGET_KIND(“newName”)

.add_attr_option<Array<String>>("keys")
.add_attr_option<Array<String>>("libs")
.add_attr_option<String>("device")
.add_attr_option<String>("model")
.add_attr_option<Bool>("system-lib")
.add_attr_option<Integer>("max_num_threads", Integer(256))
.add_attr_option<Integer>("thread_warp_size")
.set_default_keys({"opencl", "accelerator"})
.set_device_type(kDLOpenCL);

when I call tvm.context(“newName”) now will it directly use opencl backend or am I supposed to add more files for newName in the src/runtime folder ?

Also Once I added the files for for my new target called rsim I got the folowing error

File “sample_gpu.py”, line 1, in import tvm File “/home/akhil/Downloads/TVM/tvm/python/tvm/init.py”, line 25, in from ._ffi.base import TVMError, version File “/home/akhil/Downloads/TVM/tvm/python/tvm/_ffi/init.py”, line 28, in from .base import register_error File “/home/akhil/Downloads/TVM/tvm/python/tvm/_ffi/base.py”, line 62, in _LIB, _LIB_NAME = _load_lib() File “/home/akhil/Downloads/TVM/tvm/python/tvm/_ffi/base.py”, line 50, in _load_lib lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) File “/usr/lib/python3.6/ctypes/init.py”, line 348, in init self._handle = _dlopen(self._name, mode) OSError: /home/akhil/Downloads/TVM/tvm/build/libtvm.so: undefined symbol: ZN3tvm7runtime16RSIMModuleCreateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_St13unordered_mapIS6_NS0_12FunctionInfoESt4hashIS6_ESt8equal_toIS6_ESaISt4pairIKS6_S8_EEES6

@junrushao do you have an idea for this error before diving into it?

I saw FunctionInfo in the unmangled symbol name, so it looks like there are some missing pieces in the build. Seems like some linking issues or some symbols are missing.

Is it working if you build on HEAD?

Hey @comaniac and @junrushao seems like I just messed up the names inside the cmake/modules/opencl.cmake file

1 Like