summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-09-17 11:41:12 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-09-17 11:41:12 +0200
commita3ae458a06f43e9c3e0e346d178c91f46094f990 (patch)
tree8d36b6eb3d6cca94734264d825f19f583a0ffe74 /modules
parent1d578450dc82843bd4b24f3a6aad2c1a82bbda5e (diff)
wip
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/data_raw.hpp19
-rw-r--r--modules/core/c++/error.hpp22
-rw-r--r--modules/remote-hip/c++/device.tmpl.hpp11
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<schema::Array<T,Dim>, encode::NativeRaw> {
static_assert(sizeof...(Dims)==Dim, "Argument size must be equal to the Dimension");
}
+ template<std::integral... Dims>
+ constexpr error_or<void> adopt(typename raw_native_array_type_helper<T>::Type* adoptee, Dims... adoptee_size){
+ if(value_ != nullptr){
+ return make_error<err::invalid_state>("Can't adopt into existing state");
+ }
+ dims_ = {adoptee_size...};
+ value_size_ = get_full_size();
+ value_ = adoptee;
+
+ return make_void();
+ }
+
+ constexpr error_or<typename raw_native_array_type_helper<T>::Type*> extract(){
+ auto old_val = value_;
+ value_ = nullptr;
+ value_size_ = 0u;
+ return old_val;
+ }
+
constexpr data<schema::Ref<T>, encode::NativeRaw> at(const std::array<uint64_t, Dim>& 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<err::invalid_state>("Default assignement for error_or constructor.")}{}
- error_or(const fix_void<T> &value) : value_or_error_{value} {}
+ constexpr error_or():value_or_error_{make_error<err::invalid_state>("Default assignement for error_or constructor.")}{}
+ constexpr error_or(const fix_void<T> &value) : value_or_error_{value} {}
- error_or(fix_void<T> &&value) : value_or_error_{std::move(value)} {}
+ constexpr error_or(fix_void<T> &&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<fix_void<T>>(value_or_error_);
}
- bool is_error() const {
+ constexpr bool is_error() const {
return std::holds_alternative<class error>(value_or_error_);
}
- class error &get_error() {
+ constexpr class error &get_error() {
return std::get<class error>(value_or_error_);
}
- const class error &get_error() const {
+ constexpr const class error &get_error() const {
return std::get<class error>(value_or_error_);
}
- fix_void<T> &get_value() { return std::get<fix_void<T>>(value_or_error_); }
+ constexpr fix_void<T> &get_value() { return std::get<fix_void<T>>(value_or_error_); }
- const fix_void<T> &get_value() const {
+ constexpr const fix_void<T> &get_value() const {
return std::get<fix_void<T>>(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<schema::Array<T,Dim>, Encoding> {
}
// auto from_dat = &from.at(0);
+ data<Schema,Encoding> 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<Schema,Encoding>));
- hipError_t copy_err = hipMemcpy(*to, &from, sizeof(data<Schema,Encoding>), hipMemcpyHostToDevice);
+ hipError_t copy_err = hipMemcpy(*to, &tmp_fake_dat, sizeof(data<Schema,Encoding>), hipMemcpyHostToDevice);
+
+ tmp_fake_dat.extract();
return make_void();
}