LA_library/cuda_la.cc

65 lines
1.4 KiB
C++
Raw Permalink Normal View History

2010-09-08 18:27:58 +02:00
/* vim: set ts=8 sw=8 sts=8 noexpandtab cindent: */
/*******************************************************************************
*******************************************************************************/
2010-06-25 17:28:19 +02:00
#include "la_traits.h"
2010-06-18 14:42:24 +02:00
#include "cuda_la.h"
2010-06-25 17:28:19 +02:00
#ifdef CUDALA
namespace LA {
GPUID DEFAULT_LOC = cpu;
2010-09-08 18:27:58 +02:00
void set_default_loc(const GPUID loc){
DEFAULT_LOC = loc;
2010-06-25 17:28:19 +02:00
}
2010-09-08 18:27:58 +02:00
void *gpualloc(size_t size){
void *ptr = NULL;
cublasAlloc(size, 1, &ptr);
TEST_CUBLAS("cublasAlloc");
return ptr;
2010-06-25 17:28:19 +02:00
}
2010-09-08 18:27:58 +02:00
void gpufree(void *ptr){
cublasFree(ptr);
TEST_CUBLAS("cublasFree");
2010-06-25 17:28:19 +02:00
}
2010-09-08 18:27:58 +02:00
void gpuget(size_t n, size_t elsize, const void *from, void *to){
cublasGetVector(n, elsize, from, 1, to, 1);
TEST_CUBLAS("cublasGetVector");
2010-06-25 17:28:19 +02:00
}
2010-09-08 18:27:58 +02:00
void gpuput(size_t n, size_t elsize, const void *from, void *to){
cublasSetVector(n, elsize, from, 1, to, 1);
TEST_CUBLAS("cublasSetVector");
2010-06-25 17:28:19 +02:00
}
2010-09-08 18:27:58 +02:00
double *gpuputdouble(const double &x){
void *ptr = NULL;
cublasAlloc(1, sizeof(double), &ptr);
TEST_CUBLAS("cublasAlloc");
cublasSetVector(1, sizeof(double), &x, 1, ptr, 1);
TEST_CUBLAS("cublasSetVector");
2010-06-25 17:28:19 +02:00
2010-09-08 18:27:58 +02:00
return (double *)ptr;
2010-06-25 17:28:19 +02:00
}
std::complex<double> *gpuputcomplex(const std::complex<double> &x){
2010-09-08 18:27:58 +02:00
void *ptr = NULL;
cublasAlloc(1, sizeof(std::complex<double>), &ptr);
2010-09-08 18:27:58 +02:00
TEST_CUBLAS("cublasAlloc");
cublasSetVector(1, sizeof(std::complex<double>), &x, 1, ptr, 1);
2010-09-08 18:27:58 +02:00
TEST_CUBLAS("cublasSetVector");
return (std::complex<double> *)ptr;
2010-09-08 18:27:58 +02:00
}
2010-06-25 17:28:19 +02:00
}
#endif