1 #ifndef THC_GENERIC_FILE 2 #define THC_GENERIC_FILE "THC/generic/THCStorage.cpp" 5 #include <c10/util/intrusive_ptr.h> 6 #include <c10/util/typeid.h> 8 scalar_t* THCStorage_(data)(THCState *state,
const THCStorage *
self)
10 return self->data<scalar_t>();
13 ptrdiff_t THCStorage_(size)(THCState *state,
const THCStorage *
self)
15 return THStorage_size(
self);
18 int THCStorage_(elementSize)(THCState *state)
20 return sizeof(scalar_t);
23 void THCStorage_(
set)(THCState *state, THCStorage *
self, ptrdiff_t index, scalar_t value)
25 THArgCheck((index >= 0) && (index < self->numel()), 2,
"index out of bounds");
26 cudaStream_t stream = THCState_getCurrentStream(state);
27 THCudaCheck(cudaMemcpyAsync(THCStorage_(data)(state,
self) + index, &value,
sizeof(scalar_t),
28 cudaMemcpyHostToDevice,
30 THCudaCheck(cudaStreamSynchronize(stream));
33 scalar_t THCStorage_(
get)(THCState *state,
const THCStorage *
self, ptrdiff_t index)
35 THArgCheck((index >= 0) && (index < self->numel()), 2,
"index out of bounds");
37 cudaStream_t stream = THCState_getCurrentStream(state);
38 THCudaCheck(cudaMemcpyAsync(&value, THCStorage_(data)(state,
self) + index,
sizeof(scalar_t),
39 cudaMemcpyDeviceToHost, stream));
40 THCudaCheck(cudaStreamSynchronize(stream));
44 THCStorage* THCStorage_(
new)(THCState *state)
46 THStorage* storage = c10::make_intrusive<at::StorageImpl>(
47 caffe2::TypeMeta::Make<scalar_t>(),
49 state->cudaDeviceAllocator,
54 THCStorage* THCStorage_(newWithSize)(THCState *state, ptrdiff_t size)
56 THStorage* storage = c10::make_intrusive<at::StorageImpl>(
57 caffe2::TypeMeta::Make<scalar_t>(),
59 state->cudaDeviceAllocator,
64 THCStorage* THCStorage_(newWithAllocator)(THCState *state, ptrdiff_t size,
67 THStorage* storage = c10::make_intrusive<at::StorageImpl>(
68 caffe2::TypeMeta::Make<scalar_t>(),
75 THCStorage* THCStorage_(newWithSize1)(THCState *state, scalar_t data0)
77 THCStorage *
self = THCStorage_(newWithSize)(state, 1);
78 THCStorage_(
set)(state,
self, 0, data0);
82 THCStorage* THCStorage_(newWithSize2)(THCState *state, scalar_t data0, scalar_t data1)
84 THCStorage *
self = THCStorage_(newWithSize)(state, 2);
85 THCStorage_(
set)(state,
self, 0, data0);
86 THCStorage_(
set)(state,
self, 1, data1);
90 THCStorage* THCStorage_(newWithSize3)(THCState *state, scalar_t data0, scalar_t data1, scalar_t data2)
92 THCStorage *
self = THCStorage_(newWithSize)(state, 3);
93 THCStorage_(
set)(state,
self, 0, data0);
94 THCStorage_(
set)(state,
self, 1, data1);
95 THCStorage_(
set)(state,
self, 2, data2);
99 THCStorage* THCStorage_(newWithSize4)(THCState *state, scalar_t data0, scalar_t data1, scalar_t data2, scalar_t data3)
101 THCStorage *
self = THCStorage_(newWithSize)(state, 4);
102 THCStorage_(
set)(state,
self, 0, data0);
103 THCStorage_(
set)(state,
self, 1, data1);
104 THCStorage_(
set)(state,
self, 2, data2);
105 THCStorage_(
set)(state,
self, 3, data3);
109 THCStorage* THCStorage_(newWithMapping)(THCState *state,
const char *fileName, ptrdiff_t size,
int isShared)
111 THError(
"not available yet for THCStorage");
115 THCStorage* THCStorage_(newWithDataAndAllocator)(
120 THStorage* storage = c10::make_intrusive<at::StorageImpl>(
121 caffe2::TypeMeta::Make<scalar_t>(),
125 allocator !=
nullptr).release();
129 void THCStorage_(retain)(THCState *state, THCStorage *
self)
131 THStorage_retain(
self);
134 void THCStorage_(free)(THCState *state, THCStorage *
self)
136 THStorage_free(
self);