     PyArrayObject *vres = (PyArrayObject *) PyArray_FromDims(1, dims, NPY_DOUBLE);
     
     #ifdef __CUDACC__
-        // Apply CUDA version of c_add
-        c_add_cuda(v1, v2, size, (double*)vres->data);
+        if (is_cuda_available())
+        {
+            // Apply CUDA version of c_add
+            c_add_cuda(v1, v2, size, (double*)vres->data);
+        }
+        else
+        {
+            // Apply GPU version of c_add
+            c_add_cpu(v1, v2, size, (double*)vres->data);
+        }
     #else
         // Apply GPU version of c_add
         c_add_cpu(v1, v2, size, (double*)vres->data);

    d_vres[i] = d_v1[i] + d_v2[i];    
}

#else

void c_add_cpu(const double* v1, const double* v2, const unsigned int &size, double* vres)
{
    printf("void c_add_cpu(const double*, const double*, const unsigned int&, double*)\n");
    
    for (unsigned int i(0) ; i != size ; i++)
        vres[i] = v1[i] + v2[i];
}

#endif



void init_numpy();
PyArrayObject *c_add(const double* v1, const double* v2, const unsigned int &size);
void c_add_cpu(const double* v1, const double* v2, const unsigned int &size, double* vres);
#ifdef __CUDACC__
    int __DEVICE_COUNT__(-1); // -1 means to be done
    bool is_cuda_available();
    void c_add_cuda(const double* h_v1, const double* h_v2, const unsigned int &size, double* h_vres);
    __global__ void c_add_cuda_kernel(const double* d_v1, const double* d_v2, const unsigned int size, double* d_vres);
#endif

/**
    import_array has to be call
    before the first call to NumPy API
*/
bool is_init(false);
void init_numpy()
{
    if (! is_init)
    {
        import_array();
        is_init = true;
    }
}

