Skip to content
Snippets Groups Projects
Commit 7d65e53a authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

added host /device properties vector

parent f9ee7c72
Branches
No related tags found
No related merge requests found
#pragma once
#include <Kokkos_Core.hpp>
#include "feature_creation/node/value_storage/nodes_value_containers.hpp"
class PropertiesVector
{
public:
using VECTOR_TYPE = Kokkos::View<double*, Kokkos::LayoutLeft>::const_type;
PropertiesVector(const std::vector<double>& properties)
: d_properties_vector(Kokkos::ViewAllocateWithoutInitializing("properties_vector"),
properties.size())
{
h_properties_vector = Kokkos::create_mirror_view(d_properties_vector);
for (int material_idx = 0; material_idx < properties.size(); ++material_idx)
{
h_properties_vector(material_idx) = properties[material_idx];
}
Kokkos::deep_copy(d_properties_vector, h_properties_vector);
}
VECTOR_TYPE getDevicePropertiesVector() const { return d_properties_vector; }
VECTOR_TYPE::HostMirror getHostPropertiesVector() const { return h_properties_vector; }
private:
VECTOR_TYPE::non_const_type d_properties_vector;
VECTOR_TYPE::HostMirror::non_const_type h_properties_vector;
};
\ No newline at end of file
// Copyright 2021 Thomas A. R. Purcell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include "feature_creation/node/Node.hpp"
#include "utils/PropertiesVector.hpp"
namespace
{
TEST(DescriptorMatrix, CheckCopy)
{
PropertiesVector properties({2,3,4,5});
EXPECT_FLOAT_EQ(properties.getHostPropertiesVector()(0), 2);
EXPECT_FLOAT_EQ(properties.getHostPropertiesVector()(1), 3);
EXPECT_FLOAT_EQ(properties.getHostPropertiesVector()(2), 4);
EXPECT_FLOAT_EQ(properties.getHostPropertiesVector()(3), 5);
auto prop = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), properties.getDevicePropertiesVector());
EXPECT_FLOAT_EQ(prop(0), 2);
EXPECT_FLOAT_EQ(prop(1), 3);
EXPECT_FLOAT_EQ(prop(2), 4);
EXPECT_FLOAT_EQ(prop(3), 5);
}
} // namespace
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment