【发布时间】:2011-10-01 05:18:13
【问题描述】:
过程描述如下:
#include <cuda.h>
#include <cutil_math>
#include <cuda_runtime.h>
#include <iostream>
struct testtype
{
float x;
int y;
char z;
};
__device__ testtype* gpu_config;
__global__
void test()
{
gpu_config->y = 3.0;
};
int main(void)
{
testtype cpu_config;
cpu_config.x = 1;
cpu_config.y = 2.0f;
cpu_config.z = 'A';
testtype val ;
if (cudaMalloc((void**) &gpu_config, sizeof(testtype)) != cudaSuccess)
{
return -1;
}
cudaMemcpy(gpu_config, &cpu_config, sizeof(testtype), cudaMemcpyHostToDevice);
test<<<1,1,0>>>();
cudaMemcpy(&val, gpu_config, sizeof(testtype), cudaMemcpyDeviceToHost);
std::cout << val.y << std::endl;
}
当我删除测试时>>(); val 与 gpu_config 相同。但是当有 test>>(); 时, val.y 不等于 3.0 。这意味着全局函数测试不会改变 val 的值。我想知道如何通过全局函数更改 _device_ 变量的值。
【问题讨论】:
标签: cuda