diff --git a/include/aidge/backend/cpu/data/TensorImpl.hpp b/include/aidge/backend/cpu/data/TensorImpl.hpp index 922acacb070c745b2924d1fb787602326ec9d05a..7cd8c67262221fbf9c1b2415ebf98db56274cce5 100644 --- a/include/aidge/backend/cpu/data/TensorImpl.hpp +++ b/include/aidge/backend/cpu/data/TensorImpl.hpp @@ -23,6 +23,8 @@ namespace Aidge { template <class T> class TensorImpl_cpu : public TensorImpl { + static_assert(std::is_trivially_copyable<T>::value, "TensorImpl type should be trivially copyable"); + private: /// Pointer to the data and its capacity future_std::span<T> mData; diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index b8623450a9c793e4efaff00d87455ab88aa60207..e686737a44928886f97ce636df8be6c883404e56 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -529,6 +529,7 @@ public: template <typename expectedType> const expectedType& get(std::size_t idx) const { AIDGE_ASSERT(NativeType<expectedType>::type == mDataType, "wrong data type"); + AIDGE_ASSERT(mImpl->hostPtr() != nullptr, "get() can only be used for backends providing a valid host pointer"); AIDGE_ASSERT(idx < mSize, "idx out of range"); return *reinterpret_cast<expectedType *>(mImpl->hostPtr(mImplOffset + idx)); } @@ -541,6 +542,7 @@ public: template <typename expectedType> void set(std::size_t idx, expectedType value){ AIDGE_ASSERT(NativeType<expectedType>::type == mDataType, "wrong data type"); + AIDGE_ASSERT(mImpl->hostPtr() != nullptr, "get() can only be used for backends providing a valid host pointer"); AIDGE_ASSERT(idx < mSize, "idx out of range"); expectedType* dataPtr = static_cast<expectedType*>(mImpl->hostPtr(mImplOffset + idx)); *dataPtr = value;