first commit
This commit is contained in:
commit
604f1cb18a
9 changed files with 1683 additions and 0 deletions
54
cuda_pointer.h
Normal file
54
cuda_pointer.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <assert.h>
|
||||
// #include <cutil.h>
|
||||
#include <helper_cuda.h>
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct cudaPointer{
|
||||
T *dev_pointer;
|
||||
T *host_pointer;
|
||||
int size;
|
||||
cudaPointer(){
|
||||
dev_pointer = NULL;
|
||||
host_pointer = NULL;
|
||||
size = 0;
|
||||
}
|
||||
~cudaPointer(){
|
||||
// free();
|
||||
}
|
||||
void allocate(int _size){
|
||||
size = _size;
|
||||
void *p;
|
||||
checkCudaErrors(cudaMalloc(&p, size * sizeof(T)));
|
||||
assert(p);
|
||||
dev_pointer = (T*)p;
|
||||
checkCudaErrors(cudaMallocHost(&p, size * sizeof(T)));
|
||||
assert(p);
|
||||
host_pointer = (T*)p;
|
||||
}
|
||||
void free(){
|
||||
checkCudaErrors(cudaFree(dev_pointer));
|
||||
checkCudaErrors(cudaFreeHost(host_pointer));
|
||||
dev_pointer = NULL;
|
||||
host_pointer = NULL;
|
||||
size = 0;
|
||||
}
|
||||
void htod(int count){
|
||||
checkCudaErrors(cudaMemcpy(dev_pointer, host_pointer, count * sizeof(T), cudaMemcpyHostToDevice));
|
||||
}
|
||||
void htod(){
|
||||
this->htod(size);
|
||||
}
|
||||
void dtoh(int count){
|
||||
checkCudaErrors(cudaMemcpy(host_pointer, dev_pointer, count * sizeof(T), cudaMemcpyDeviceToHost));
|
||||
}
|
||||
void dtoh(){
|
||||
this->dtoh(size);
|
||||
}
|
||||
T &operator [] (int i){
|
||||
return host_pointer[i];
|
||||
}
|
||||
operator T* (){
|
||||
return dev_pointer;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue