Advertisement

在Mac上通过clang++与nvcc进行CUDA程序编译

阅读量:

主函数位于main.cpp文件中,采用clang++进行编译,而与CUDA相关的函数则被置于KernelWrapper.cu文件中,并通过nvcc进行编译。此外,在main.cpp文件中还需引入KernelWrapper.h这一头文件。

KernelWrapper.h

复制代码
 #ifndef _KernelWrapper_h

    
 #define _KernelWrapper_h
    
  
    
 void RunTest();
    
 #endif
    
    
    
    

KernelWrapper.cu

复制代码
 #include <stdio.h>

    
 #include "KernelWrapper.h"
    
  
    
 __global__ void TestDevice(int *deviceArray)
    
 {
    
 int idx = blockIdx.x*blockDim.x + threadIdx.x;
    
 deviceArray[idx] = deviceArray[idx]*deviceArray[idx];
    
 }
    
  
    
 void RunTest()
    
 {
    
 int* hostArray;
    
 int*

全部评论 (0)

还没有任何评论哟~