gpt4 book ai didi

cuda - 我在使用 CUDA 在 GPU 上复制字符时遇到问题

转载 作者:行者123 更新时间:2023-12-04 05:39:13 31 4
gpt4 key购买 nike

主持人:

unsigned char exp[128];
unsigned char __e;

i = cudaMalloc( (void**)&__e, 128 * sizeof(unsigned char) );
if(i != cudaSuccess)
printf("cudaMalloc __e FAIL! Code: %d\n", i);

BN_bn2bin128B(e, exp); // copy data from e to exp, no problems since here

i = cudaMemcpy( &__e, &exp, 128 * sizeof(unsigned char), cudaMemcpyHostToDevice);
if(i != cudaSuccess)
printf("cudaMemcpy __e FAIL! Code: %d\n", i);

输出:
cudaMemcpy __e FAIL! Code: 11

错误 11 对应于:
cudaErrorInvalidValue = 11, ///< Invalid value

为什么?错误在哪里?

最佳答案

您已申报 __e不正确。它必须是一个指针。试试这个:

unsigned char exp[128];
unsigned char * __e;

i = cudaMalloc( (void**)&__e, 128 * sizeof(unsigned char) );
if(i != cudaSuccess)
printf("cudaMalloc __e FAIL! Code: %d\n", i);

// whatever goes here to set exp

i = cudaMemcpy( __e, &exp[0], 128 * sizeof(unsigned char), cudaMemcpyHostToDevice);
if(i != cudaSuccess)
printf("cudaMemcpy __e FAIL! Code: %d\n", i);

关于cuda - 我在使用 CUDA 在 GPU 上复制字符时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11492203/

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