#include #include #include #include #include void *__gxx_personality_v0; //c++ shenanigans extern void init(int n, int *res); extern void end(); extern void launch(float *a, uint64_t l, float r); int main(int argc, char *argv[]) { int out = 0; if (argc <= 2) { fprintf(stderr, "testDRP \n"); return -1; } int num = atoi(argv[1]); if (num <= 0) { fprintf(stderr, "testDRP \n"); return -1; } float rate = strtof(argv[2], NULL); if (rate <= 0.0f) { fprintf(stderr, "testDRP \n"); return -1; } int res; init(num, &res); if (!res) { fprintf(stderr, "Failed to initialize curand states.\n"); return -1; } float *a = 0; float *b = 0; b = malloc(num*sizeof(float)); if (!b) { fprintf(stderr, "Host memory error\n"); out = -1; goto exit; } for (int i = 0; i < num; i++) { b[i] = (float)rand() / (float)RAND_MAX; } if (cudaSuccess != cudaMalloc((void**)&a, num*sizeof(float))) { fprintf(stderr, "Device memory error\n"); out = -1; goto exit; } cudaMemcpy(a, b, num * sizeof(float), cudaMemcpyHostToDevice); memset(b, 0, num*sizeof(float)); launch(a, num, rate); cudaMemcpy(b, a, num * sizeof(float), cudaMemcpyDeviceToHost); for (int i = 0; i < num; i++) { if (!b[i]) fprintf(stdout, "0\n"); } exit: cudaFree(a); free(b); end(); //Free globalstate array return out; }