与cuda 3.5兼容的旧源代码与较新的cuda版本不兼容,例如7.5。例如,
cuda_runtime_api.cc: In function ‘cudaError_t cudaMemcpyToSymbol(const char*, const void*, size_t, size_t, cudaMemcpyKind)’:
cuda_runtime_api.cc:556:141: error: declaration of C function ‘cudaError_t cudaMemcpyToSymbol(const char*, const void*, size_t, size_t, cudaMemcpyKind)’ conflicts with
__host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const char *symbol, const void *src, size_t count, size_t offset, enum cudaMemcpyKind kind)
^
In file included from cuda_runtime_api.cc:155:0:
/usr/local/cuda/include/cuda_runtime_api.h:4335:39: error: previous declaration ‘cudaError_t cudaMemcpyToSymbol(const void*, const void*, size_t, size_t, cudaMemcpyKind)’ here
extern __host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const void *symbol, const void *src, size_t count, size_t offset __dv(0), enum cudaMemcpyKind kind __dv(cudaMemcpyHostToDevice));
所以,这表示代码中的cudaMemcpyToSymbol()与7.5实现不兼容。源代码是
__host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const char *symbol, const void *src, size_t count, size_t offset, enum cudaMemcpyKind kind)
{....}
和/usr/local/cuda/include/cuda_runtime_api.h上的7.5版
extern __host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const void *symbol, const void *src, size_t count, size_t offset __dv(0), enum cudaMemcpyKind kind __dv(cudaMemcpyHostToDevice));
我该如何解决?
更新:错误文件中的cuda_runtime_api.cc
指向用户定义的可用here。
mahmood@u1604:~/gem5-gpu/benchmarks/libcuda$ g++ -std=c++0x -O3 -g -Wall -fPIC -DCUDART_VERSION=7050 -I./ -I/usr/local/cuda/include -I../../gem5/util/m5 -c cuda_runtime_api.cc -o cuda_runtime_api.o
cuda_runtime_api.cc: In function ‘cudaError_t cudaMemcpyToSymbol(const char*, const void*, size_t, size_t, cudaMemcpyKind)’:
cuda_runtime_api.cc:556:143: error: declaration of C function ‘cudaError_t cudaMemcpyToSymbol(const char*, const void*, size_t, size_t, cudaMemcpyKind)’ conflicts with
__host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const char *symbol, const void *src, size_t count, size_t offset , enum cudaMemcpyKind kind )
^
In file included from cuda_runtime_api.cc:155:0:
/usr/local/cuda/include/cuda_runtime_api.h:4335:39: error: previous declaration ‘cudaError_t cudaMemcpyToSymbol(const void*, const void*, size_t, size_t, cudaMemcpyKind)’ here
extern __host__ cudaError_t CUDARTAPI cudaMemcpyToSymbol(const void *symbol, const void *src, size_t count, size_t offset __dv(0), enum cudaMemcpyKind kind __dv(cudaMemcpyHostToDevice));
^
答案 0 :(得分:1)
在评论之后,必须传递符号本身,而不是字符串中的名称。以下是有关如何使用此新API签名的示例示例:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__constant__ int a[1];
__global__ void kernel()
{
printf("a = %d\n", a[0]);
}
int main()
{
int value = 42;
cudaMemcpyToSymbol(a, &value, sizeof(int));
kernel << <1, 1 >> > ();
return cudaDeviceSynchronize();
}
应打印
a = 42