日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cuda加速的头文件_如何从C ++头文件调用CUDA文件?

發布時間:2024/9/27 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cuda加速的头文件_如何从C ++头文件调用CUDA文件? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I know the method of calling the .cu files from .c files. But now I want to call the .cu files from a C header file. Is it possible to do it ? If so how should I make the settings of my project ? please help.....

解決方案

Here's a worked example:

file1.h:

int hello();

file2.h:

#include

#include "file1.h"

int myfunc(){

hello();

return 0;

}

file1.cu:

#include

#include "file1.h"

__global__ void mykernel(){

printf("Hello from mykernel\n");

}

int hello(){

mykernel<<<1,1>>>();

cudaDeviceSynchronize();

return 0;

}

file2.cpp:

#include "file2.h"

int main(){

myfunc();

return 0;

}

build and test:

$ nvcc -arch=sm_20 -c file1.cu

$ g++ -c file2.cpp

$ g++ -o test file1.o file2.o -L/usr/local/cuda/lib64 -lcudart

$ ./test

Hello from mykernel

$

Assuming you are intending to include your file2.h into a cpp file, you cannot call a cuda kernel directly from that header and use it in a cpp file. You must put a wrapper around the cuda kernel, and call the wrapper, as I have indicated. This is because your cpp file will get compiled by the host compiler, which doesn't know anything about cuda syntax (e.g. mykernel<<<1,1>>>();)

Also, as indicated in the comments, it may make more sense to reserve the header file file2.h just for needed prototypes, and put the actual function definition of myfunc into a cpp file somewhere.

總結

以上是生活随笔為你收集整理的cuda加速的头文件_如何从C ++头文件调用CUDA文件?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。