From 6cb97f5142e5981f58d6286f11e8c759b61611a8 Mon Sep 17 00:00:00 2001 From: Felix Thaler Date: Wed, 24 Jul 2024 07:47:42 +0200 Subject: [PATCH] =?UTF-8?q?Use=20=E2=80=98const=E2=80=99=20in=20neighbor?= =?UTF-8?q?=20table=20value=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/gridtools/storage/data_store.hpp | 50 +++++++++++++++--------- tests/include/fn_mesh.hpp | 4 +- 2 files changed, 34 insertions(+), 20 deletions(-) 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 924c8144d..da97efffd 100644 --- a/tests/include/fn_mesh.hpp +++ b/tests/include/fn_mesh.hpp @@ -110,11 +110,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(); } };