1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/********************************************************************
* sample.cu
* This is a example of the CUDA program.
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <cutil.h>
/************************************************************************/
/* Init CUDA */
/************************************************************************/
#if __DEVICE_EMULATION__
bool InitCUDA(void){return true;}
#else
bool InitCUDA(void)
{
int count = 0;
int i = 0;
cudaGetDeviceCount(&count);
if(count == 0) {
fprintf(stderr, "There is no device.\n");
return false;
}
for(i = 0; i < count; i++) {
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess) {
if(prop.major >= 1) {
break;
}
}
}
if(i == count) {
fprintf(stderr, "There is no device supporting CUDA.\n");
return false;
}
cudaSetDevice(i);
printf("CUDA initialized.\n");
return true;
}
#endif
__global__ void Raytracing_kernel(double *d_Suvx);
/************************************************************************/
/* HelloCUDA */
/************************************************************************/
int main(int argc, char* argv[])
{
double *h_Suvx;
double *d_Suvx;
// taille grille et blocks
int numBlocks = 1;
int numThreadsPerBlock = 1;
//Déclaration des tailles mémoires
size_t memSizeSuv = sizeof(double);
cudaMalloc( (void**)&d_Suvx,memSizeSuv );
h_Suvx = (double*) malloc(memSizeSuv);
// configuration et lancement kernel
dim3 dimGrid( numBlocks,1,1 );
dim3 dimBlock(numThreadsPerBlock,1,1);
Raytracing_kernel<<< dimGrid ,dimBlock >>>(d_Suvx);
cudaThreadSynchronize();
//printf("%s\n", cudaGetErrorString( cudaGetLastError() ) );
system("pause");
cudaMemcpy(h_Suvx, d_Suvx, memSizeSuv, cudaMemcpyDeviceToHost );
printf("\n valeur =%f \n", h_Suvx[0]);
system("pause");
free(h_Suvx);
cudaFree(d_Suvx);
}
__global__ void Raytracing_kernel(double *d_Suvx)
{
double Mx;
Mx= 3769468;
d_Suvx[0]= Mx;
} |
Partager