版主及各位网友好。
我这里有一个有关 CUDA runtime API 初始化的问题。程序启动时,第一次调用 runtime API 好像都需要花费比较长的时间。我这边大约是 1 秒。这个启动时间有没有方法消除?比如说,专门的异步启动函数,在启动完成之前先将函数返回值返回。
我在网上搜集相关信息时,也看到有人提到设置 nvidia-smi -pm 1 。我尝试过该方法,好像没有效果。似乎这个是针对驱动时API 启动的优化。
另外,有人提到过 nvcc 的编译设置。Enabling the device code translation cache
By default, the result of any runtime compiled ptx code will be used for the lifetime
of the process that compiles it, and then discarded. Runtime compilation is intended
to be an escape situation, but in case it occurs, it might be desirable to keep the
result for later invocations of the executable.
This can be achieved by defining the environment variable
CUDA_DEVCODE_CACHE to the name of a selected code repository. When
defined, the CUDA runtime system will add the result of runtime compiled code to
this repository, after creating it as a directory when it did not exist before.
Additionally, CUDA_DEVCODE_CACHE will be placed on the repository search
list.
上面这段是 nvcc 文档里面的。具体地说是 cuda toolkit 4.0 里面文档标题为 nvcc 那个 pdf 里面的。可是,我没看懂这是什么意思。有没有关于该设置的相关例子?
有任何相关的信息,请直接回复。先行谢过~
LZ您好:
1:CUDA Runtime会在第一次使用到Runtime API函数或者调用kernel的时候自动初始化,第一次初始化确实需要较长的时间。一般建议您尽可能早地启动一个“空kernel”或者其他runtime API函数,仅作为初始化环境的“热身”之用,如此在后面真正使用的时候,就无需再次初始化环境了。
2:您给出的 nvcc编译设置和定义环境变量的内容,指的是是否缓冲runtime 编译PTX代码的编译结果的,和您考虑的runtime 初始化耗时是不同的问题。
大致如上,祝您编码愉快~
ICE说的正确,一般ptx的jit过程很快的。
而driver的每次加载和runtime的初始化则较慢。
但前者你已经处理了。所以只剩下runtime初始化导致的时间了。这个目前没有办法消除。