6.33. 驱动程序入口点访问
本节介绍底层CUDA驱动应用程序编程接口的驱动程序入口点访问函数。
Functions
- CUresult cuGetProcAddress ( const char* symbol, void** pfn, int cudaVersion, cuuint64_t flags, CUdriverProcAddressQueryResult* symbolStatus )
- Returns the requested driver API function pointer.
Functions
- CUresult cuGetProcAddress ( const char* symbol, void** pfn, int cudaVersion, cuuint64_t flags, CUdriverProcAddressQueryResult* symbolStatus )
-
返回请求的驱动程序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 and cudaVersion would be the ABI compatible CUDA version for the _v2 variant.
- pfn
- - 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.
- symbolStatus
- - Optional location to store the status of the search for symbol based on cudaVersion. See CUdriverProcAddressQueryResult for possible values.
描述
在**pfn中返回指定CUDA版本和标志对应的CUDA驱动程序函数地址。
CUDA版本号的计算公式为(1000 * 主版本号 + 10 * 次版本号),因此CUDA 11.2应表示为11020。对于请求的驱动程序符号,如果指定的CUDA版本号大于或等于该驱动程序符号被引入时的CUDA版本号,此API将返回对应版本函数的指针。
API返回的指针应转换为与请求的驱动程序函数在API头文件中的定义相匹配的函数指针。函数指针的类型定义可以从相应的类型定义头文件中获取。例如,cudaTypedefs.h包含了cuda.h中定义的驱动程序API的函数指针类型定义。
如果请求的驱动程序函数在当前平台不受支持、没有针对指定cudaVersion的ABI兼容驱动程序函数存在,或者驱动程序符号无效,该API将返回CUDA_SUCCESS并将返回的pfn设置为NULL。
它还会将可选的symbolStatus设置为CUdriverProcAddressQueryResult中的以下值之一,其含义如下:
-
CU_GET_PROC_ADDRESS_SUCCESS - 根据输入参数成功找到请求的符号,且pfn有效
-
CU_GET_PROC_ADDRESS_SYMBOL_NOT_FOUND - 未找到请求的符号
-
CU_GET_PROC_ADDRESS_VERSION_NOT_SUFFICIENT - 找到了请求的符号,但指定的cudaVersion不支持该符号
请求的标志可以是:
-
CU_GET_PROC_ADDRESS_DEFAULT: 这是默认模式。如果代码使用--default-stream per-thread编译标志或定义了CUDA_API_PER_THREAD_DEFAULT_STREAM宏,则等同于CU_GET_PROC_ADDRESS_PER_THREAD_DEFAULT_STREAM;否则等同于CU_GET_PROC_ADDRESS_LEGACY_STREAM。
-
CU_GET_PROC_ADDRESS_LEGACY_STREAM: 这将启用对所有匹配请求的驱动程序符号名称的搜索,但不包括对应的每线程版本。
-
CU_GET_PROC_ADDRESS_PER_THREAD_DEFAULT_STREAM: 这将启用对所有匹配请求驱动符号名称的驱动符号的搜索,包括每线程版本。如果未找到每线程版本,该API将返回驱动函数的旧版实现。
Note:强烈不建议混合使用CUDA定义的类型和驱动API版本,这样做可能导致未定义的行为。更多信息。
另请参阅: