如何在Visual Studio中为CUDA项目启用单独的编译
How to enable separate compilation for CUDA project in Visual Studio
我是 CUDA 的新手。 我正在尝试编写一个应用程序,其中我从另一个内核函数调用一个内核函数。但是我在构建应用程序时收到错误">从设备或全局函数启动内核需要单独的编译模式"。 这是我的完整代码。任何帮助将不胜感激。
#include<iostream>
#include<curand.h>
#include<cuda.h>
#include <curand_kernel.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
__device__ int *vectorData;
__device__ void initializeArray(int elementCount)
{
for (int i = 0; i < elementCount; i++)
{
vectorData[i] = 1;
}
}
__global__ void AddOneToEachElement(int elementCount)
{
for (int i = 0; i < elementCount; i++)
{
vectorData[i] = vectorData[i]+1;
}
}
__global__ void addKernel(int *numberOfElements)
{
vectorData = (int*)malloc(sizeof(int));
initializeArray(*numberOfElements);
int gridSize = ceil((*numberOfElements) / 1024) + 1;
AddOneToEachElement << <gridSize, 1024 >> > (*numberOfElements);
cudaDeviceSynchronize();
free(vectorData);
}
int main()
{
int numberOfElements = 1;
int *device_numberOfElements;
cudaMalloc((int**)&device_numberOfElements, sizeof(int));
cout << "Enter the Number of elements" << endl;
cin >> numberOfElements;
cudaMemcpy(device_numberOfElements, &(numberOfElements), sizeof(int), cudaMemcpyHostToDevice);
addKernel << <1, 1 >> > (device_numberOfElements);
cudaFree(device_numberOfElements);
return 0;
}
使用以下链接中提供的信息解决了该问题 在Visual Studio中使用CUDA动态并行性
这是我从上述链接中获得的完整信息:
从 CUDA 5.0 开始,CUDA 支持对计算能力为 3.5 或更高的 GPU 使用动态并行性。动态并行性允许直接从其他内核启动内核,并在这些应用程序中实现进一步的加速,这些应用程序可以从运行时直接在 GPU 上更好地处理计算工作负载中受益;在许多情况下,动态并行性避免了 CPU/GPU 交互,从而有利于递归等机制。 若要在 Visual Studio 2010 或 Visual Studio 2013 中使用动态并行性,请执行以下操作:
- 查看 ->属性页
- 配置属性 -> CUDA C/C++ -> 通用 -> 生成可重定位的设备代码 -> 是 (-rdc=true(
- 配置属性 -> CUDA C/C++ ->设备 ->代码生成 -> compute_35,sm_35
- 配置属性 -> 链接器 -> 输入 -> 其他依赖项 -> cudadevrt.lib
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法在 CLion 中构建 C++ 项目
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 编译时未启用intel oneApi CUDA支持
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 欧拉项目#8答案是大以获得有效答案
- 从链接列表c++中删除一个项目
- 如何在Visual Studio中为CUDA项目启用单独的编译
- Android Studio-在现有的旧项目中启用本机C++调试(card.io Android Source)
- 检测 Visual Studio 项目的属性中是否启用了英特尔 MKL
- 在我的 CLR 项目中添加包含会导致无法在启用 /clr 的情况下编译 WLR
- 在 C++/CLI/C# 项目中启用"Native Code Debugging"导致应用程序崩溃
- 我有一个启用了代理存根支持的 ATL 项目,在哪里可以找到 xdlldata.h 文件中所有方法的实现
- 在VS2010中启用跨项目调试
- 如何在非 js 项目中启用 JS 着色
- 在 Visual Studio 2012 中编译启用 CLR C++项目时出现 C2248 错误
- Eclipse CDT:如何启用项目调试
- 如何在 intellij IDEA 中为 Android 项目中的 C/C++ 启用自动完成和语法突出显示?
- 为项目启用clang