cupy.RawModule using name_expressions and nvcc and/or path

社会主义新天地 提交于 2021-02-08 11:23:21

问题


I am using CuPy for testing cuda kernels from a library. More specifically I use the cupy.RawModule to exploit the kernels in python. However, the kernels are templated and enclosed in a namespace. Before the name_expressions parameter to RawModule in CuPy 8.0.0, I had to copy the c++-mangled names into the get_function() method manually of the RawModule. Using name_expressions I thought that this should be possible, nevertheless, this requires the code to be compiled from source using the code parameter in combination with backend='nvrtc'.

Should it be possible to enable (any of the below)?:

  1. name_expressions in conjunction with path
  2. name_expressions in conjunction with backend='nvcc'

回答1:


Should it be possible to enable (any of the below)?:

  1. 'name_expressions' in conjunction with 'path'
  2. 'name_expressions' in conjunction with 'backend'='nvcc'

The answer is no for both questions.

The name_expressions feature requires the source code for just-in-time (JIT) compilation of your C++ template kernels using NVRTC, whereas the path argument is for loading external cubin, fatbin, or ptx code. If you want to compile an external source code, you can do so by loading it in Python first, and then pass it as the code argument:

with open('my_cuda_cpp_code.cu') as f:
    code = f.read()

mod = cp.RawModule(code=code, name_expressions=(...), ...)

Unfortunately unlike NVRTC, NVCC does not provide an API to return mangled names, so using NVCC is not possible. If you pass backend='nvcc' to RawModule, it'd raise an error.



来源:https://stackoverflow.com/questions/64442514/cupy-rawmodule-using-name-expressions-and-nvcc-and-or-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!