12 # ifndef SLCUDABUFFER_H
13 # define SLCUDABUFFER_H
18 # include <driver_types.h>
19 # include <cuda_runtime_api.h>
24 class SLOptixCudaBuffer
40 void alloc_and_upload(vector<T>&);
41 void alloc_and_upload(T*,
unsigned int);
43 void upload(vector<T>&);
48 CUdeviceptr devicePointer() {
return _devicePointer; }
49 CUdeviceptr* devicePointerPointer() {
return &_devicePointer; }
50 size_t size() {
return _size; }
53 CUdeviceptr _devicePointer;
58 SLOptixCudaBuffer<T>::SLOptixCudaBuffer()
65 SLOptixCudaBuffer<T>::~SLOptixCudaBuffer()
71 bool SLOptixCudaBuffer<T>::isAllocated()
73 return _devicePointer != 0;
77 void SLOptixCudaBuffer<T>::resize(
size_t size)
84 void SLOptixCudaBuffer<T>::alloc(
size_t size)
87 CUDA_CHECK(cuMemAlloc(&_devicePointer, _size));
91 void SLOptixCudaBuffer<T>::free()
95 CUDA_CHECK(cuMemFree(_devicePointer));
102 void SLOptixCudaBuffer<T>::alloc_and_upload(vector<T>& vt)
104 alloc(
sizeof(T) * vt.size());
109 void SLOptixCudaBuffer<T>::alloc_and_upload(T* t,
unsigned int count)
111 alloc(
sizeof(T) * count);
116 void SLOptixCudaBuffer<T>::upload(vector<T>& vt)
118 assert(_size ==
sizeof(T) * vt.size());
119 CUDA_CHECK(cuMemcpyHtoD(_devicePointer,
125 void SLOptixCudaBuffer<T>::upload(T* t)
127 CUDA_CHECK(cuMemcpyHtoD(_devicePointer,
133 void SLOptixCudaBuffer<T>::download(T* t)
135 assert(_devicePointer != 0);
136 CUDA_CHECK(cuMemcpyDtoH((
void*)t,