Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

example for contrib op #1018

Closed

Conversation

thisjiang
Copy link
Collaborator

@thisjiang thisjiang commented Oct 31, 2022

CINN基础算子代码开发示例。

仅供参考!!!算子本身无任何实际意义!!!

提示

  1. 算子代码实现需在cinn/hlir/op/contrib目录下新建一同名文件,并在CMakeLists.txt中添加文件名,最后需要在cinn/hlir/op/use_ops.h 文件中添加链接所需的CINN_REGISTER_HELPER名称。
  2. cinn/ir/ir.hcinn/ir/ir_base.hcinn/lang/builtin.h均有提供Compte实现所需的ir工具。
  3. nvgpu自定义函数实现在cinn/runtime/cuda/cinn_cuda_runtime_source.cuh 中,并需要在cinn/runtime/cuda/cuda_intrinsics.cc中注册。
  4. host自定义函数实现在cinn/runtime/cpu/host_intrinsics.cc中并同时需要注册。
  5. python单测文件必须从shape、type等维度覆盖当前能考虑到的所有情况,每种情况只需一个测试用例即可。 单测必须通过CI测试。可通过bash build.sh gpu_on ci命令来本地运行所有单测,或通过如下命令运行单个单测:
export $PYTHONPATH=$PWD/build/python/
export runtime_include_dir=$PWD/cinn/runtime/cuda

cd python 
python tests/ops/test_example_op.py

部分文件作用说明

必备文件
cinn/hlir/op/contrib/example.cc:算子代码实现
cinn/hlir/op/use_ops.h & cinn/hlir/op/contrib/CMakeLists.txt:编译&链接所需
cinn/frontend/net_builder.h:对外API接口
cinn/pybind/frontend.cc:python接口
python/tests/ops/test_example_op.py:python测试文件

可选文件
cinn/runtime/cpu/host_intrinsics.cc:自定义函数host端实现及注册
cinn/runtime/cuda/cinn_cuda_runtime_source.cuh & cinn/runtime/cuda/cuda_intrinsics.cc:自定义函数nvgpu端实现及注册

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant