6.31. 驱动程序入口点访问
本节介绍CUDA运行时应用程序编程接口的驱动程序入口点访问函数。
Functions
- __host__ cudaError_t cudaGetDriverEntryPoint ( const char* symbol, void** funcPtr, unsigned long long flags, cudaDriverEntryPointQueryResult ** driverStatus = NULL )
- Returns the requested driver API function pointer.
- __host__ cudaError_t cudaGetDriverEntryPointByVersion ( const char* symbol, void** funcPtr, unsigned int cudaVersion, unsigned long long flags, cudaDriverEntryPointQueryResult ** driverStatus = NULL )
- Returns the requested driver API function pointer by CUDA version.
Functions
- __host__ cudaError_t cudaGetDriverEntryPoint ( const char* symbol, void** funcPtr, unsigned long long flags, cudaDriverEntryPointQueryResult ** driverStatus = NULL )
-
返回请求的驱动程序API函数指针。
参数
- symbol
- - The base name of the driver API function to look for. As an example, for the driver API cuMemAlloc_v2, symbol would be cuMemAlloc. Note that the API will use the CUDA runtime version to return the address to the most recent ABI compatible driver symbol, cuMemAlloc or cuMemAlloc_v2.
- funcPtr
- - Location to return the function pointer to the requested driver function
- flags
- - Flags to specify search options.
- driverStatus
- - Optional location to store the status of finding the symbol from the driver. See cudaDriverEntryPointQueryResult for possible values.
描述
在**funcPtr中返回对应请求标志的CUDA驱动函数地址。
对于请求的驱动程序符号,如果引入该驱动程序符号的CUDA版本小于或等于CUDA运行时版本,API将返回指向相应版本驱动程序函数的函数指针。
API返回的指针应转换为与请求的驱动程序函数在API头文件中的定义相匹配的函数指针。函数指针的类型定义可以从相应的类型定义头文件中获取。例如,cudaTypedefs.h包含了cuda.h中定义的驱动程序API的函数指针类型定义。
如果请求的驱动程序函数有效且在该平台上受支持,API将返回cudaSuccess并设置返回的funcPtr。
如果请求的驱动程序函数在当前平台不受支持、没有与CUDA运行时版本ABI兼容的驱动程序函数存在,或者驱动程序符号无效,API将返回cudaSuccess并将返回的funcPtr设置为NULL。
它还会将可选的driverStatus设置为cudaDriverEntryPointQueryResult中的某个值,其含义如下:
-
cudaDriverEntryPointSuccess - 根据输入参数成功找到请求的符号,且pfn有效
-
cudaDriverEntryPointSymbolNotFound - 未找到请求的符号
-
cudaDriverEntryPointVersionNotSufficent - 找到了请求的符号,但当前运行时版本(CUDART_VERSION)不支持该符号
请求的标志可以是:
-
cudaEnableDefault: 这是默认模式。如果代码编译时使用了--default-stream per-thread编译标志或定义了CUDA_API_PER_THREAD_DEFAULT_STREAM宏,则等同于cudaEnablePerThreadDefaultStream;否则等同于cudaEnableLegacyStream。
-
cudaEnableLegacyStream: 这将启用搜索所有与请求的驱动程序符号名称匹配的驱动程序符号,但不包括对应的每线程版本。
-
cudaEnablePerThreadDefaultStream: 这将启用对所有匹配请求驱动符号名称的驱动符号的搜索,包括每线程版本。如果未找到每线程版本,API将返回传统版本的驱动函数。
Note:-
强烈不建议混合使用CUDA定义的类型与驱动API版本,这样做可能导致未定义的行为。更多信息。
-
请注意,如果此调用尝试初始化CUDA RT内部状态,该函数也可能返回cudaErrorInitializationError、cudaErrorInsufficientDriver或cudaErrorNoDevice。
-
请注意,根据cudaStreamAddCallback的规定,回调函数中不得调用任何CUDA函数。在这种情况下,可能会(但不保证)返回cudaErrorNotPermitted作为诊断信息。
另请参阅:
- __host__ cudaError_t cudaGetDriverEntryPointByVersion ( const char* symbol, void** funcPtr, unsigned int cudaVersion, unsigned long long flags, cudaDriverEntryPointQueryResult ** driverStatus = NULL )
-
根据CUDA版本返回请求的驱动程序API函数指针。
参数
- symbol
- - The base name of the driver API function to look for. As an example, for the driver API cuMemAlloc_v2, symbol would be cuMemAlloc.
- funcPtr
- - Location to return the function pointer to the requested driver function
- cudaVersion
- - The CUDA version to look for the requested driver symbol
- flags
- - Flags to specify search options.
- driverStatus
- - Optional location to store the status of finding the symbol from the driver. See cudaDriverEntryPointQueryResult for possible values.
描述
在**funcPtr中返回对应请求标志和CUDA驱动版本的CUDA驱动函数地址。
CUDA版本号的计算公式为(1000 * 主版本号 + 10 * 次版本号),因此CUDA 11.2应表示为11020。对于请求的驱动程序符号,如果指定的CUDA版本号大于或等于该驱动程序符号被引入时的CUDA版本号,此API将返回对应版本函数的指针。
API返回的指针应转换为与请求的驱动程序函数在API头文件中的定义相匹配的函数指针。函数指针的类型定义可以从相应的类型定义头文件中获取。例如,cudaTypedefs.h包含了cuda.h中定义的驱动程序API的函数指针类型定义。
当请求的CUDA版本高于已安装的CUDA工具包时,对应的头文件中可能没有合适的函数指针类型定义,此时可能需要自定义类型定义以匹配驱动程序返回的函数签名。可以通过从更新的工具包获取类型定义,或创建适当匹配的自定义函数类型定义来实现。
如果请求的驱动程序函数有效且在该平台上受支持,API将返回cudaSuccess并设置返回的funcPtr。
如果请求的驱动程序函数在当前平台不受支持、没有与请求版本ABI兼容的驱动程序函数存在,或者驱动程序符号无效,API将返回cudaSuccess并将返回的funcPtr设置为NULL。
它还会将可选的driverStatus设置为cudaDriverEntryPointQueryResult中的某个值,其含义如下:
-
cudaDriverEntryPointSuccess - 根据输入参数成功找到请求的符号,且pfn有效
-
cudaDriverEntryPointSymbolNotFound - 未找到请求的符号
-
cudaDriverEntryPointVersionNotSufficent - 找到了请求的符号,但指定的版本cudaVersion不支持该符号
请求的标志可以是:
-
cudaEnableDefault: 这是默认模式。如果代码编译时使用了--default-stream per-thread编译标志或定义了宏CUDA_API_PER_THREAD_DEFAULT_STREAM,则等同于cudaEnablePerThreadDefaultStream;否则等同于cudaEnableLegacyStream。
-
cudaEnableLegacyStream: 这将启用对除对应每线程版本外所有匹配请求驱动符号名称的驱动符号的搜索。
-
cudaEnablePerThreadDefaultStream: 这将启用对所有匹配请求驱动符号名称的驱动符号的搜索,包括每线程版本。如果未找到每线程版本,API将返回旧版驱动函数。
Note:-
强烈不建议混合使用CUDA定义的类型与驱动API版本,这样做可能导致未定义的行为。更多信息。
-
请注意,如果此调用尝试初始化CUDA RT内部状态,该函数也可能返回cudaErrorInitializationError、cudaErrorInsufficientDriver或cudaErrorNoDevice。
-
请注意,根据cudaStreamAddCallback的规定,回调函数中不得调用任何CUDA函数。在这种情况下,可能会(但不保证)返回cudaErrorNotPermitted作为诊断信息。
另请参阅: