[英]How to separate kernels from C file
Hi I would like to separate some of my CUDA kernel functions in a separate file so that I can reuse them. 嗨,我想将我的一些CUDA内核函数放在一个单独的文件中,以便我可以重复使用它们。
Let say I have two files: 假设我有两个文件:
A.cu
contains the reusable CUDA kernels. A.cu
包含可重用的CUDA内核。 B.cu
contains some kernels as well as the host function, where I would like to call some of the kernels from my A.cu file. B.cu
包含一些内核以及宿主函数,在这里我想从A.cu文件中调用一些内核。 How can I do it? 我该怎么做?
For the case you have described, you can do this in a fashion nearly identical to how you would do it in C/C++. 对于您描述的情况,您可以采用与在C / C ++中几乎相同的方式进行此操作。 Here's a fully worked example: 这是一个完整的示例:
$ cat B.cu
#include "myheader.h"
__global__ void kernel1(){
printf("Hello 1\n");
}
int main(){
kernel1<<<1,1>>>();
cudaDeviceSynchronize();
kernel2<<<1,1>>>();
cudaDeviceSynchronize();
return 0;
}
$ cat A.cu
#include "myheader.h"
__global__ void kernel2(){
printf("Hello 2\n");
}
$ cat myheader.h
#include <stdio.h>
__global__ void kernel2();
$ nvcc -arch=sm_20 -o test A.cu B.cu
$ cuda-memcheck ./test
========= CUDA-MEMCHECK
Hello 1
Hello 2
========= ERROR SUMMARY: 0 errors
$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.