2

主持人:

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

为什么?错误在哪里?

4

1 回答 1

3

你声明__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);
于 2012-07-15T13:54:52.403 回答