【问题标题】:cuda file error "Invalid device function"cuda 文件错误“无效的设备功能”
【发布时间】:2015-01-21 16:12:25
【问题描述】:

我有一张 GPU 卡 GeForce GTX 295 和 Visual Studio 2012 以及 6.5 版的 cuda。我运行一个简单的代码,如

#include "stdafx.h" 
#include <stdio.h> 
#include <cuda.h> 
// Kernel that executes on the CUDA device
 __global__ void square_array(float *a, int N)
 { 
  int idx = blockIdx.x * blockDim.x + threadIdx.x; 
  if (idx<N) a[idx] = a[idx] * a[idx]; } 
 // main routine that executes on the host
 int main(void)
 {   float *a_h, *a_d;  // Pointer to host & device arrays   
const int N = 10;  // Number of elements in arrays   
size_t size = N * sizeof(float);  
 a_h = (float *)malloc(size);        // Allocate array on host   
cudaMalloc((void **) &a_d, size);   // Allocate array on device   // Initialize host array and copy it to CUDA device  
 for (int i=0; i<N; i++) a_h[i] = (float)i;   
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);   // Do calculation on device:   
int block_size = 4;  
 int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);   
square_array <<< n_blocks, block_size >>> (a_d, N);  

// Retrieve result from device and store it in host array   
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost); 
  // Print results  
 for (int i=0; i<N; i++) 
printf("%d %f\n", i, a_h[i]);  
 // Cleanup  
 free(a_h); 
cudaFree(a_d); } 

在这段代码中,当我在调用内核后使用命令 cudaGetLastError (void) 时,在控制台窗口显示错误“Invalid device function”。我该如何摆脱它? cuda kit 6.5的示例代码正在Visual Studio 2012上成功运行。enter code here

【问题讨论】:

    标签: cuda nvidia


    【解决方案1】:

    我相信 GTX 295 具有 1.3 的计算能力。可能值得检查您的解决方案编译器设置,以查看您是否没有使用compute_20,sm_20 之类的东西编译解决方案。如果是这样,请尝试将这些值更改为例如compute_10,sm_10,重建看看是否有帮助。有关设置这些值的详细信息,请参阅here

    编辑:

    根据 njuffa 和 CUDA documentation 对 cc1.0 设备的支持已在 CUDA 6.5 中删除,因此您必须使用 compute_13,sm_13

    【讨论】:

    • CUDA 6.5 中删除了对 sm_10 的支持,CUDA 6.5 中的 nvcc 编译器默认是为 sm_20 编译的。 GTX 295是sm_13,所以需要编译-arch=sm_13.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多