579
社区成员
发帖
与我相关
我的任务
分享
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// includes CUDA
#include <cuda_runtime.h>
// includes, project
#include <helper_cuda.h>
#include <helper_functions.h> // helper functions for SDK examples
////////////////////////////////////////////////////////////////////////////////
// declaration, forward
__global__ void kernel(double *d_U)
{
*d_U = 11111;
}
void test(double *pR)
{
double *d_x;
double *y = (double*)malloc(sizeof(double));
double *m = (double*)malloc(sizeof(double));
cudaMalloc((void**)&d_x, sizeof(double));
cudaMemcpy(d_x, y, sizeof(double), cudaMemcpyHostToDevice);
kernel<<<1, 1>>>(d_x);
cudaMemcpy(m, d_x, sizeof(double), cudaMemcpyDeviceToHost);
*pR = *m;
}
int main()
{
double *a = (double*)malloc(sizeof(double));
test(a);
printf("%f\n", *a);
return 0;
}