gpt4 book ai didi

c++ - CUDA 程序的输出为空

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:01:12 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Output of cuda program is not what was expected

我正在运行这个简单的 CUDA 程序:

#include <cuda_runtime.h>
#include <cuda.h>
#include <stdio.h>

__global__ void
display(char *t[])
{

int v = blockIdx.x;
int p = blockIdx.y;
int offset = v+ p*gridDim.x;
t[offset] = "(";
//
}

void
main()
{
int c = 5;
cudaGetDeviceCount(&c);
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop,0);
printf("The device name is : %s\n", prop.name);
//bool value = prop.integrated;
char *x[6];
int i;
for (i = 0; i<6; i++)
cudaMalloc((void**)&x[i], 20*sizeof(char));

// Checking the meaning of grid(3,2)
dim3 grid(3,2);
display<<<grid,1>>>(x);
char y[30];
cudaMemcpy(y, x[0], 20*sizeof(char), cudaMemcpyDeviceToHost);
printf("The values is :%s\n", y);
cudaFree(x[0]);

getchar();
}

我不明白为什么执行结束时数组y还是空的。不应该是“(”吗?

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