From 02bb33c64514ef36d48388e2265b034c49bb31c4 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Mon, 14 Mar 2016 06:47:23 +0000
Subject: [PATCH] stuff

---
 src/cuda.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/cuda.c b/src/cuda.c
index c914290..d773d0b 100644
--- a/src/cuda.c
+++ b/src/cuda.c
@@ -7,10 +7,12 @@
 #include "blas.h"
 #include "assert.h"
 #include <stdlib.h>
+#include <time.h>
 
 
 void check_error(cudaError_t status)
 {
+    cudaError_t status2 = cudaGetLastError();
     if (status != cudaSuccess)
     {   
         const char *s = cudaGetErrorString(status);
@@ -20,6 +22,15 @@
         snprintf(buffer, 256, "CUDA Error: %s", s);
         error(buffer);
     } 
+    if (status2 != cudaSuccess)
+    {   
+        const char *s = cudaGetErrorString(status);
+        char buffer[256];
+        printf("CUDA Error Prev: %s\n", s);
+        assert(0);
+        snprintf(buffer, 256, "CUDA Error Prev: %s", s);
+        error(buffer);
+    } 
 }
 
 dim3 cuda_gridsize(size_t n){
@@ -56,9 +67,23 @@
         status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
         check_error(status);
     }
+    if(!x_gpu) error("Cuda malloc failed\n");
     return x_gpu;
 }
 
+void cuda_random(float *x_gpu, int n)
+{
+    static curandGenerator_t gen;
+    static int init = 0;
+    if(!init){
+        curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
+        curandSetPseudoRandomGeneratorSeed(gen, time(0));
+        init = 1;
+    }
+    curandGenerateUniform(gen, x_gpu, n);
+    check_error(cudaPeekAtLastError());
+}
+
 float cuda_compare(float *x_gpu, float *x, int n, char *s)
 {
     float *tmp = calloc(n, sizeof(float));

--
Gitblit v1.10.0