From a3ae458a06f43e9c3e0e346d178c91f46094f990 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Tue, 17 Sep 2024 11:41:12 +0200 Subject: wip --- modules/codec/c++/data_raw.hpp | 19 +++++++++++++++++++ modules/core/c++/error.hpp | 22 +++++++++++----------- modules/remote-hip/c++/device.tmpl.hpp | 11 ++++++++++- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/modules/codec/c++/data_raw.hpp b/modules/codec/c++/data_raw.hpp index 2da49b4..3447f42 100644 --- a/modules/codec/c++/data_raw.hpp +++ b/modules/codec/c++/data_raw.hpp @@ -483,6 +483,25 @@ class data, encode::NativeRaw> { static_assert(sizeof...(Dims)==Dim, "Argument size must be equal to the Dimension"); } + template + constexpr error_or adopt(typename raw_native_array_type_helper::Type* adoptee, Dims... adoptee_size){ + if(value_ != nullptr){ + return make_error("Can't adopt into existing state"); + } + dims_ = {adoptee_size...}; + value_size_ = get_full_size(); + value_ = adoptee; + + return make_void(); + } + + constexpr error_or::Type*> extract(){ + auto old_val = value_; + value_ = nullptr; + value_size_ = 0u; + return old_val; + } + constexpr data, encode::NativeRaw> at(const std::array& ind){ return {value_[this->get_flat_index(ind)]}; } diff --git a/modules/core/c++/error.hpp b/modules/core/c++/error.hpp index ac45fbc..32b67a0 100644 --- a/modules/core/c++/error.hpp +++ b/modules/core/c++/error.hpp @@ -270,33 +270,33 @@ private: "Don't use internal private types"); public: - error_or():value_or_error_{make_error("Default assignement for error_or constructor.")}{} - error_or(const fix_void &value) : value_or_error_{value} {} + constexpr error_or():value_or_error_{make_error("Default assignement for error_or constructor.")}{} + constexpr error_or(const fix_void &value) : value_or_error_{value} {} - error_or(fix_void &&value) : value_or_error_{std::move(value)} {} + constexpr error_or(fix_void &&value) : value_or_error_{std::move(value)} {} - error_or(const error &error) : value_or_error_{error} {} - error_or(error &&error) : value_or_error_{std::move(error)} {} + constexpr error_or(const error &error) : value_or_error_{error} {} + constexpr error_or(error &&error) : value_or_error_{std::move(error)} {} - bool is_value() const { + constexpr bool is_value() const { return std::holds_alternative>(value_or_error_); } - bool is_error() const { + constexpr bool is_error() const { return std::holds_alternative(value_or_error_); } - class error &get_error() { + constexpr class error &get_error() { return std::get(value_or_error_); } - const class error &get_error() const { + constexpr const class error &get_error() const { return std::get(value_or_error_); } - fix_void &get_value() { return std::get>(value_or_error_); } + constexpr fix_void &get_value() { return std::get>(value_or_error_); } - const fix_void &get_value() const { + constexpr const fix_void &get_value() const { return std::get>(value_or_error_); } }; diff --git a/modules/remote-hip/c++/device.tmpl.hpp b/modules/remote-hip/c++/device.tmpl.hpp index 0517f67..cf31336 100644 --- a/modules/remote-hip/c++/device.tmpl.hpp +++ b/modules/remote-hip/c++/device.tmpl.hpp @@ -41,9 +41,18 @@ struct hip_copy_to_device, Encoding> { } // auto from_dat = &from.at(0); + data tmp_fake_dat; + { + auto eov = tmp_fake_dat.adopt(dat, from.size()); + if(eov.is_error()){ + return eov; + } + } hipError_t malloc_err = hipMalloc(to, sizeof(data)); - hipError_t copy_err = hipMemcpy(*to, &from, sizeof(data), hipMemcpyHostToDevice); + hipError_t copy_err = hipMemcpy(*to, &tmp_fake_dat, sizeof(data), hipMemcpyHostToDevice); + + tmp_fake_dat.extract(); return make_void(); } -- cgit v1.2.3