Cleaned up, debugged. Ready for 1st release
[RBC.git] / utilsGPU.cu
1 /* This file is part of the Random Ball Cover (RBC) library.
2 * (C) Copyright 2010, Lawrence Cayton [lcayton@tuebingen.mpg.de]
3 */
4
5 #ifndef UTILSGPU_CU
6 #define UTILSGPU_CU
7
8 #include<cuda.h>
9 #include<stdio.h>
10 #include "defs.h"
11 #include "utilsGPU.h"
12
13 void copyAndMove(matrix *dx, const matrix *x){
14 dx->r = x->r;
15 dx->c = x->c;
16 dx->pr = x->pr;
17 dx->pc = x->pc;
18 dx->ld = x->ld;
19
20 checkErr( cudaMalloc( (void**)&(dx->mat), dx->pr*dx->pc*sizeof(*(dx->mat)) ) );
21 cudaMemcpy( dx->mat, x->mat, dx->pr*dx->pc*sizeof(*(dx->mat)), cudaMemcpyHostToDevice );
22
23 }
24
25
26 void copyAndMoveI(intMatrix *dx, const intMatrix *x){
27 dx->r = x->r;
28 dx->c = x->c;
29 dx->pr = x->pr;
30 dx->pc = x->pc;
31 dx->ld = x->ld;
32
33 checkErr( cudaMalloc( (void**)&(dx->mat), dx->pr*dx->pc*sizeof(*(dx->mat)) ) );
34 cudaMemcpy( dx->mat, x->mat, dx->pr*dx->pc*sizeof(*(dx->mat)), cudaMemcpyHostToDevice );
35
36 }
37
38
39 void copyAndMoveC(charMatrix *dx, const charMatrix *x){
40 dx->r = x->r;
41 dx->c = x->c;
42 dx->pr = x->pr;
43 dx->pc = x->pc;
44 dx->ld = x->ld;
45
46 checkErr( cudaMalloc( (void**)&(dx->mat), dx->pr*dx->pc*sizeof(*(dx->mat)) ) );
47 cudaMemcpy( dx->mat, x->mat, dx->pr*dx->pc*sizeof(*(dx->mat)), cudaMemcpyHostToDevice );
48
49 }
50
51
52 void checkErr(cudaError_t cError){
53 if(cError != cudaSuccess){
54 fprintf(stderr,"GPU-related error:\n\t%s \n", cudaGetErrorString(cError) );
55 fprintf(stderr,"exiting ..\n");
56 exit(1);
57 }
58
59 }
60
61 void checkErr(char* loc, cudaError_t cError){
62 printf("in %s:\n",loc);
63 checkErr(cError);
64 }
65
66 #endif