CUDA - 链接内核在一起 [英] CUDA - link kernels together

查看:258
本文介绍了CUDA - 链接内核在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CUDA内核在.cu文件和另一个CUDA内核到另一个.cu文件。我知道使用动态并行化我可以从父内核调用另一个CUDA内核,但我想知道是否有任何方式来做这个与一个子内核驻留到另一个.cu文件。

I have a CUDA kernel in a .cu file and another CUDA kernel into another .cu file. I know that with dynamic parallelism I can call another CUDA kernel from a parent kernel but I'd like to know if there's any way to do this with a child kernel residing into another .cu file.

感谢

推荐答案

可以。

关键是使用单独的编译与设备代码链接,这是可用nvcc 。由于使用动态并行性,这里真的没什么新鲜的。

The key is to use separate compilation with device code linking, which is available with nvcc. Since this is already required for usage of dynamic parallelism, there's really nothing new here.

这里有一个简单的例子:

Here's a simple example:

ch_kernel.cu :

ch_kernel.cu:

#include <stdio.h>

__global__ void ch_kernel(){

  printf("hello from child kernel\n");
}

main.cu:

#include <stdio.h>

extern __global__ void ch_kernel();

__global__ void kernel(){

  ch_kernel<<<1,1>>>();
}

int main(){

  kernel<<<1,1>>>();
  cudaDeviceSynchronize();
}

编译:

nvcc -arch=sm_35 -rdc=true -o test ch_kernel.cu main.cu -lcudadevrt

这篇关于CUDA - 链接内核在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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