Skip to content

Commit aca4845

Browse files
committed
Fix a few CUDA issues
1 parent 279da47 commit aca4845

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

librapid/include/librapid/cuda/cudaStorage.hpp

+11-29
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace librapid {
7575
public:
7676
using PtrType = T *;
7777

78-
CudaRef(const PtrType &ptr, size_t offset) : m_ptr(ptr), m_offset(offset) {}
78+
CudaRef(PtrType ptr, size_t offset) : m_ptr(ptr), m_offset(offset) {}
7979

8080
LIBRAPID_ALWAYS_INLINE CudaRef &operator=(const T &val) {
8181
cudaSafeCall(cudaMemcpyAsync(
@@ -161,22 +161,18 @@ namespace librapid {
161161

162162
/// Create a CudaStorage object from an std::initializer_list
163163
/// \param list Initializer list of elements
164-
template<typename V>
165-
LIBRAPID_ALWAYS_INLINE CudaStorage(const std::initializer_list<V> &list);
164+
LIBRAPID_ALWAYS_INLINE CudaStorage(const std::initializer_list<Scalar> &list);
166165

167166
/// Create a CudaStorage object from an std::vector of values
168167
/// \param vec The vector to fill with
169-
template<typename V>
170-
LIBRAPID_ALWAYS_INLINE explicit CudaStorage(const std::vector<V> &vec);
168+
LIBRAPID_ALWAYS_INLINE explicit CudaStorage(const std::vector<Scalar> &vec);
171169

172170
template<typename ShapeType>
173171
static ShapeType defaultShape();
174172

175-
template<typename V>
176-
static CudaStorage fromData(const std::initializer_list<V> &vec);
173+
static CudaStorage fromData(const std::initializer_list<Scalar> &vec);
177174

178-
template<typename V>
179-
static CudaStorage fromData(const std::vector<V> &vec);
175+
static CudaStorage fromData(const std::vector<Scalar> &vec);
180176

181177
/// Assignment operator for a CudaStorage object
182178
/// \param other CudaStorage object to copy
@@ -237,16 +233,6 @@ namespace librapid {
237233
template<typename P>
238234
LIBRAPID_ALWAYS_INLINE void initData(P begin, P end);
239235

240-
/// Resize the Storage Object to \p newSize elements, retaining existing
241-
/// data.
242-
/// \param newSize New size of the Storage object
243-
LIBRAPID_ALWAYS_INLINE void resizeImpl(SizeType newSize, int);
244-
245-
/// Resize the Storage object to \p newSize elements. Note this does not
246-
/// initialize the new elements or maintain existing data.
247-
/// \param newSize New size of the Storage object
248-
LIBRAPID_ALWAYS_INLINE void resizeImpl(SizeType newSize);
249-
250236
Pointer m_begin = nullptr;
251237
size_t m_size;
252238
bool m_ownsData = true;
@@ -332,21 +318,19 @@ namespace librapid {
332318
}
333319

334320
template<typename T>
335-
template<typename V>
336-
CudaStorage<T>::CudaStorage(const std::initializer_list<V> &list) :
321+
CudaStorage<T>::CudaStorage(const std::initializer_list<T> &list) :
337322
m_size(list.size()), m_begin(detail::cudaSafeAllocate<T>(list.size())),
338323
m_ownsData(true) {
339324
cudaSafeCall(cudaMemcpyAsync(
340325
m_begin, list.begin(), sizeof(T) * m_size, cudaMemcpyHostToDevice, global::cudaStream));
341326
}
342327

343328
template<typename T>
344-
template<typename V>
345-
CudaStorage<T>::CudaStorage(const std::vector<V> &list) :
329+
CudaStorage<T>::CudaStorage(const std::vector<T> &list) :
346330
m_size(list.size()), m_begin(detail::cudaSafeAllocate<T>(list.size())),
347331
m_ownsData(true) {
348332
cudaSafeCall(cudaMemcpyAsync(
349-
m_begin, list.begin(), sizeof(T) * m_size, cudaMemcpyHostToDevice, global::cudaStream));
333+
m_begin, &list[0], sizeof(T) * m_size, cudaMemcpyHostToDevice, global::cudaStream));
350334
}
351335

352336
template<typename T>
@@ -356,17 +340,15 @@ namespace librapid {
356340
}
357341

358342
template<typename T>
359-
template<typename V>
360-
auto CudaStorage<T>::fromData(const std::initializer_list<V> &list) -> CudaStorage {
343+
auto CudaStorage<T>::fromData(const std::initializer_list<T> &list) -> CudaStorage {
361344
CudaStorage ret;
362345
// ret.initData(list.begin(), list.end());
363-
ret.initData(static_cast<const V *>(list.begin()), static_cast<const V *>(list.end()));
346+
ret.initData(static_cast<const T *>(list.begin()), static_cast<const T *>(list.end()));
364347
return ret;
365348
}
366349

367350
template<typename T>
368-
template<typename V>
369-
auto CudaStorage<T>::fromData(const std::vector<V> &vec) -> CudaStorage {
351+
auto CudaStorage<T>::fromData(const std::vector<T> &vec) -> CudaStorage {
370352
CudaStorage ret;
371353
// ret.initData(vec.begin(), vec.end());
372354
ret.initData(&vec[0], &vec[0] + vec.size());

librapid/include/librapid/opencl/openclStorage.hpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,9 @@ namespace librapid {
184184
template<typename ShapeType>
185185
static ShapeType defaultShape();
186186

187-
template<typename V>
188-
static OpenCLStorage fromData(const std::initializer_list<V> &list);
187+
static OpenCLStorage fromData(const std::initializer_list<Scalar> &list);
189188

190-
template<typename V>
191-
static OpenCLStorage fromData(const std::vector<V> &vec);
189+
static OpenCLStorage fromData(const std::vector<Scalar> &vec);
192190

193191
~OpenCLStorage();
194192

@@ -337,14 +335,13 @@ namespace librapid {
337335
}
338336

339337
template<typename Scalar>
340-
template<typename V>
341-
OpenCLStorage<Scalar> OpenCLStorage<Scalar>::fromData(const std::initializer_list<V> &list) {
338+
OpenCLStorage<Scalar>
339+
OpenCLStorage<Scalar>::fromData(const std::initializer_list<Scalar> &list) {
342340
return OpenCLStorage<Scalar>(list);
343341
}
344342

345343
template<typename Scalar>
346-
template<typename V>
347-
OpenCLStorage<Scalar> OpenCLStorage<Scalar>::fromData(const std::vector<V> &vec) {
344+
OpenCLStorage<Scalar> OpenCLStorage<Scalar>::fromData(const std::vector<Scalar> &vec) {
348345
return OpenCLStorage<Scalar>(vec);
349346
}
350347

0 commit comments

Comments
 (0)