Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a CUDA kernel in a .cu file and another CUDA kernel in 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 in another .cu file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, you can.

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:

#include <stdio.h>

__global__ void ch_kernel(){

  printf("hello from child kernel
");
}

main.cu:

#include <stdio.h>

extern __global__ void ch_kernel();

__global__ void kernel(){

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

int main(){

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

compile with:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...