如何在不使用nvcc的情况下在编译时获取CUDA工具包版本? [英] How to Get CUDA Toolkit Version at Compile Time Without nvcc?

查看:253
本文介绍了如何在不使用nvcc的情况下在编译时获取CUDA工具包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.cpp文件中有一些对cuSPARSE库的调用,这些调用在较旧的工具包中不可用。为了支持使用较旧工具箱的系统,我想使用编译器指令来编译代码的不同部分。特别是,我想使用旧工具箱的CSR格式矩阵和新工具箱的BSR格式矩阵来解决稀疏三角系统。

I have some calls in a .cpp file, to the cuSPARSE library, that are not available in older toolkits. In order to support systems with older toolkits, I want to compile different sections of code using compiler directives. In particular, I want to solve sparse triangular systems using matrices in CSR format for old toolkits and BSR format for new toolkits.

问题是,我没有编译任何矩阵使用nvcc的本节中实际的CUDA代码,只是进行库调用,因此无法获取用于版本信息的nvcc宏。

The problem is, I'm not compiling any actual CUDA code in this section with nvcc, just making library calls, so the nvcc macros to get version information are not available.

在cuda中有一个#define __CUDA_API_VERSION .h,但是无论是否包含cuda.h,在编译我的.cpp时均为0。

There is a #define of __CUDA_API_VERSION in cuda.h, but it is 0 when compiling my .cpp regardless of whether I include cuda.h.

如何在此获取有关工具包版本的信息案件?我正在CentOS 7中工作,并使用g ++编译.cpp。

How can I get information about the toolkit version at compile time in this case? I'm working in CentOS 7 and compiling my .cpp with g++.

推荐答案

一种可能的方法:


  1. 在您的.cpp文件中包含cuda_runtime_api.h(例如,如果您正在其中使用任何CUDA运行时API函数,则可能已经这样做了) cudaMalloc

使用 CUDART_VERSION 定义该文件包含在该头文件中:

Use the CUDART_VERSION define that is included from that header file:

#include <cuda_runtime_api.h>
...
#ifndef CUDART_VERSION
#error CUDART_VERSION Undefined!
#elif (CUDART_VERSION == 8000)
// your code for the CUDA 8.0 case
#elif (CUDART_VERSION == 7050)
// your code for the CUDA 7.5 case
#elif ...
//etc.
#else
#error Unknown CUDART_VERSION!
#endif

或类似。

这篇关于如何在不使用nvcc的情况下在编译时获取CUDA工具包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆