@@ -410,43 +410,41 @@ struct CudaAllocator : private Arena {
410
410
411
411
T *allocate (size_t size) {
412
412
void *ptr = nullptr ;
413
- if (size >= std::numeric_limits<size_t >::max () / sizeof (T))
414
- [[unlikely]] {
413
+ if (sizeof (T) <= 1 || size > std::numeric_limits<size_t >::max () /
414
+ sizeof (T)) [[unlikely]] {
415
415
throw std::bad_array_new_length ();
416
416
}
417
417
cudaError_t res = Arena::doMalloc (&ptr, size * sizeof (T));
418
- if (res != cudaSuccess ) [[unlikely]] {
418
+ if (res == cudaErrorMemoryAllocation ) [[unlikely]] {
419
419
throw std::bad_alloc ();
420
420
}
421
+ CHECK_CUDA ((" Arena::doMalloc" , res));
421
422
return static_cast <T *>(ptr);
422
423
}
423
424
424
- void deallocate (T *ptr, size_t size = 0 ) noexcept {
425
- Arena::doFree (ptr);
425
+ void deallocate (T *ptr, size_t size = 0 ) {
426
+ CHECK_CUDA ( Arena::doFree (ptr) );
426
427
}
427
428
428
429
template <class ... Args>
429
430
static constexpr std::enable_if_t <sizeof ...(Args)>
430
- construct (T *p, Args &&...args) noexcept (
431
- noexcept ( ::new (p ) T(std::forward<Args>(args)...))) {
432
- ::new (( void *)p ) T (std::forward<Args>(args)...);
431
+ construct (T *p, Args &&...args) noexcept (noexcept (
432
+ ::new (static_cast < void *>(p) ) T(std::forward<Args>(args)...))) {
433
+ ::new (static_cast < void *>(p) ) T (std::forward<Args>(args)...);
433
434
}
434
435
435
- static constexpr void construct (T *p) noexcept (noexcept (::new (p) T)) {
436
- ::new ((void *)p) T;
436
+ static constexpr void
437
+ construct (T *p) noexcept (noexcept (::new (static_cast <void *>(p)) T)) {
438
+ ::new (static_cast <void *>(p)) T;
437
439
}
438
440
439
441
static constexpr void destroy (T *p) noexcept (noexcept (p->~T ())) {
440
442
p->~T ();
441
443
}
442
444
443
- template <class U > // cihou shabi wendous
445
+ template <class U >
444
446
constexpr CudaAllocator (CudaAllocator<U> const &other) noexcept {}
445
447
446
- constexpr bool operator ==(CudaAllocator<T> const &other) const noexcept {
447
- return true ;
448
- }
449
-
450
448
template <class U >
451
449
constexpr bool operator ==(CudaAllocator<U> const &other) const noexcept {
452
450
return true ;
0 commit comments