diff --git a/include/gridtools/storage/data_store.hpp b/include/gridtools/storage/data_store.hpp index d7764bd2d..fd2ee8737 100644 --- a/include/gridtools/storage/data_store.hpp +++ b/include/gridtools/storage/data_store.hpp @@ -173,25 +173,35 @@ namespace gridtools { auto const_host_view() const { return const_target_view(); } }; - template - class data_store - : public base { - - template - struct is_host_refrenceable : std::bool_constant {}; - - template ::value, int> = 0> - void init(Initializer const &initializer) { - auto host_ptr = std::make_unique(this->info().length()); - initializer(host_ptr.get(), typename data_store::layout_t(), this->info()); - traits::update_target(this->raw_target_ptr(), host_ptr.get(), this->info().length()); - } + template + class data_store : public base { + std::unique_ptr m_host_ptr; - template ::value, int> = 0> - void init(Initializer const &initializer) { - initializer(this->raw_target_ptr(), typename data_store::layout_t(), this->info()); + public: + template + data_store(std::string, Info, Halos const &, uninitialized const &) = delete; + + template + data_store(std::string name, Info info, Halos const &halos, Initializer const &initializer) + : data_store::base(std::move(name), std::move(info), halos), + m_host_ptr(std::make_unique(this->info().length())) { + initializer(m_host_ptr.get(), typename data_store::layout_t(), this->info()); + traits::update_target(this->raw_target_ptr(), m_host_ptr.get(), this->info().length()); } + T const *get_target_ptr() const { return this->raw_target_ptr(); } + T const *get_const_target_ptr() const { return this->raw_target_ptr(); } + auto target_view() const { return traits::make_target_view(get_target_ptr(), this->info()); } + auto const_target_view() const { return target_view(); } + + T const *get_host_ptr() const { return m_host_ptr.get(); } + T const *get_const_host_ptr() const { return get_host_ptr(); } + auto host_view() const { return make_host_view(get_host_ptr(), this->info()); } + auto const_host_view() const { return host_view(); } + }; + + template + class data_store : public base { public: template data_store(std::string, Info, Halos const &, uninitialized const &) = delete; @@ -199,12 +209,16 @@ namespace gridtools { template data_store(std::string name, Info info, Halos const &halos, Initializer const &initializer) : base(std::move(name), std::move(info), halos) { - init(initializer); + initializer(this->raw_target_ptr(), typename data_store::layout_t(), this->info()); } T const *get_target_ptr() const { return this->raw_target_ptr(); } + T const *get_const_target_ptr() const { return get_target_ptr(); } auto target_view() const { return traits::make_target_view(get_target_ptr(), this->info()); } - auto get_const_target_ptr() const { return get_target_ptr(); } auto const_target_view() const { return target_view(); } + T const *get_host_ptr() { return get_target_ptr(); } + T const *get_const_host_ptr() { return get_target_ptr(); } + auto host_view() const { return target_view(); } + auto const_host_view() const { return target_view(); } }; template diff --git a/tests/include/fn_mesh.hpp b/tests/include/fn_mesh.hpp index ad2ebeae2..db7b8fd50 100644 --- a/tests/include/fn_mesh.hpp +++ b/tests/include/fn_mesh.hpp @@ -111,11 +111,11 @@ namespace gridtools { } auto v2e_table() const { - return storage::builder.dimensions(nvertices(), max_v2e_neighbors_t()).template type().initializer(v2e_initializer()).unknown_id().build(); + return storage::builder.dimensions(nvertices(), max_v2e_neighbors_t()).template type().initializer(v2e_initializer()).unknown_id().build(); } auto e2v_table() const { - return storage::builder.dimensions(nedges(), max_e2v_neighbors_t()).template type().initializer(e2v_initializer()).unknown_id().build(); + return storage::builder.dimensions(nedges(), max_e2v_neighbors_t()).template type().initializer(e2v_initializer()).unknown_id().build(); } };