gpt4 book ai didi

cuda - 错误 : argument of type "int" is incompatible with parameter of type "const void *"

转载 作者:行者123 更新时间:2023-12-04 23:24:18 26 4
gpt4 key购买 nike

在我编译程序时的这部分代码中。此错误显示:“类型为“int”的参数与类型为“const void *”的参数不兼容。我声明变量如下:

int *dev_matrix, *dev_array, *dev_array_length;
int array_length=1;
cudaMalloc((void**)&dev_array_length, 1*sizeof(int));
cudaMemcpy(dev_array_length, array_length, 1*sizeof(int), cudaMemcpyHostToDevice);

最佳答案

cudaMemcpy() 的第二个参数是错的。它应该是一个指针( const void* ),而您提供的是一个 int .

你的意思是写:

cudaMemcpy(dev_array_length, &array_length, 1*sizeof(int), cudaMemcpyHostToDevice);
^

关于cuda - 错误 : argument of type "int" is incompatible with parameter of type "const void *",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15918686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com