是否可以从 CUDA 10.1 内核调用 cuBLAS 或 cuBLASLt 函数?
Is it possible to call cuBLAS or cuBLASLt functions from CUDA 10.1 kernels?
关于 CUDA 10.1
我正在对几何网格进行一些计算,并对网格的每个面进行大量独立计算。我 运行 一个 CUDA 内核,它对每张脸进行计算。
计算涉及一些矩阵乘法,所以我想使用 cuBLAS 或 cuBLASLt 来加快速度。因为我需要做很多矩阵乘法(每个面至少有几个)我想直接在内核中做。这可能吗?
似乎 cuBLAS 或 cuBLASLt 不允许您从内核 (__global__) 代码调用它们的函数。我从 Visual Studio 收到以下错误:
"calling a __host__ function from a __device__ function is not allowed"
有些旧答案 (Could a CUDA kernel call a cublas function?) 暗示这是可能的?
基本上,我想要这样的内核:
__global__
void calcPerFace(...)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < faceCount; i += stride)
{
// Calculate some matrices for each face in the mesh
...
// Multiply those matrices
cublasLtMatmul(...) // <- not allowed by cuBLASLt
// Continue calculation
...
}
}
是否可以在 CUDA 10.1 中像这样从内核调用 cublasLtMatmul 或 cublassgemm?
不可能
从 CUDA 10.0 开始,CUDA 不再支持从设备代码调用 CUBLAS 例程的能力。
一个deprecation notice was given prior to CUDA 10.0, and the formal announcement exists in the CUDA 10.0 release notes:
The cuBLAS library, to support the ability to call the same cuBLAS APIs from within the device routines (cublas_device), is dropped starting with CUDA 10.0.
同样,从 CUDA 10.0 开始,依赖于此功能的 CUDA 示例代码(例如 simpleDevLibCUBLAS
)不再是 CUDA 工具包分发的一部分。
这仅适用于 CUBLAS,并不意味着 CUDA 动态并行的一般能力已被移除。
我将无法回答 "why?" 或 "why?" 的变体问题 我将无法回答有关未来事件或主题的问题。没有任何技术原因表明此功能不可用或不受支持。改变的原因与发展和资源优先级有关。我不能再深入了。如果您希望看到 CUDA 的行为发生变化,无论是在功能、性能还是文档方面,我们鼓励您通过在 http://developer.nvidia.com. The specific bug filing instructions are linked here.
提交错误来表达您的愿望
对于执行一些准备工作的 CUDA 设备代码,然后调用 CUBLAS,然后执行一些其他工作,一般建议将其分解为执行准备工作的内核,然后从中启动所需的 CUBLAS 例程主机,然后在后续内核中执行剩余的工作。这并不意味着数据必须在设备和主机之间来回移动。当执行多个 CUBLAS 调用时(例如,每个设备线程),那么研究可用的各种 CUBLAS 批处理功能可能是有益的。不可能给出一个单一的方法来重构每一种代码。这些建议可能无法解决所有情况。
关于 CUDA 10.1
我正在对几何网格进行一些计算,并对网格的每个面进行大量独立计算。我 运行 一个 CUDA 内核,它对每张脸进行计算。
计算涉及一些矩阵乘法,所以我想使用 cuBLAS 或 cuBLASLt 来加快速度。因为我需要做很多矩阵乘法(每个面至少有几个)我想直接在内核中做。这可能吗?
似乎 cuBLAS 或 cuBLASLt 不允许您从内核 (__global__) 代码调用它们的函数。我从 Visual Studio 收到以下错误:
"calling a __host__ function from a __device__ function is not allowed"
有些旧答案 (Could a CUDA kernel call a cublas function?) 暗示这是可能的?
基本上,我想要这样的内核:
__global__
void calcPerFace(...)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < faceCount; i += stride)
{
// Calculate some matrices for each face in the mesh
...
// Multiply those matrices
cublasLtMatmul(...) // <- not allowed by cuBLASLt
// Continue calculation
...
}
}
是否可以在 CUDA 10.1 中像这样从内核调用 cublasLtMatmul 或 cublassgemm?
不可能
从 CUDA 10.0 开始,CUDA 不再支持从设备代码调用 CUBLAS 例程的能力。
一个deprecation notice was given prior to CUDA 10.0, and the formal announcement exists in the CUDA 10.0 release notes:
The cuBLAS library, to support the ability to call the same cuBLAS APIs from within the device routines (cublas_device), is dropped starting with CUDA 10.0.
同样,从 CUDA 10.0 开始,依赖于此功能的 CUDA 示例代码(例如 simpleDevLibCUBLAS
)不再是 CUDA 工具包分发的一部分。
这仅适用于 CUBLAS,并不意味着 CUDA 动态并行的一般能力已被移除。
我将无法回答 "why?" 或 "why?" 的变体问题 我将无法回答有关未来事件或主题的问题。没有任何技术原因表明此功能不可用或不受支持。改变的原因与发展和资源优先级有关。我不能再深入了。如果您希望看到 CUDA 的行为发生变化,无论是在功能、性能还是文档方面,我们鼓励您通过在 http://developer.nvidia.com. The specific bug filing instructions are linked here.
提交错误来表达您的愿望对于执行一些准备工作的 CUDA 设备代码,然后调用 CUBLAS,然后执行一些其他工作,一般建议将其分解为执行准备工作的内核,然后从中启动所需的 CUBLAS 例程主机,然后在后续内核中执行剩余的工作。这并不意味着数据必须在设备和主机之间来回移动。当执行多个 CUBLAS 调用时(例如,每个设备线程),那么研究可用的各种 CUBLAS 批处理功能可能是有益的。不可能给出一个单一的方法来重构每一种代码。这些建议可能无法解决所有情况。