Skip to content

Commit 2955479

Browse files
committed
fix edge case
1 parent 338c5e1 commit 2955479

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spiner/databox.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
namespace Spiner {
4343

4444
enum class IndexType { Interpolated = 0, Named = 1, Indexed = 2 };
45-
enum class DataStatus { Empty, Unmanaged, AllocatedHost, AllocatedDevice };
45+
enum class DataStatus { Empty = 0, Unmanaged = 1, AllocatedHost = 2, AllocatedDevice = 3 };
4646
enum class AllocationTarget { Host, Device };
4747

4848
template <typename T = Real, typename Grid_t = RegularGrid1D<T>,
@@ -302,6 +302,10 @@ class DataBox {
302302

303303
DataBox<T, Grid_t, Concept>
304304
getOnDevice() const { // getOnDevice is always a deep copy
305+
if (size == 0 || status_ == DataStatus::Empty) { // edge case for unallocated
306+
DataBox<T, Grid_t, Concept> a;
307+
return a;
308+
}
305309
// create device memory (host memory if no device)
306310
T *device_data = (T *)PORTABLE_MALLOC(sizeBytes());
307311
// copy to device

0 commit comments

Comments
 (0)