Skip to content

Commit

Permalink
Add a scalar to TestSoA
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Jul 28, 2022
1 parent b1c83d1 commit 22a63e1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion DataFormats/PortableTestObjects/interface/TestSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace portabletest {
SOA_COLUMN(double, x),
SOA_COLUMN(double, y),
SOA_COLUMN(double, z),
SOA_COLUMN(int32_t, id))
SOA_COLUMN(int32_t, id),
// scalars: one value for the whole structure
SOA_SCALAR(double, r))

using TestSoA = TestSoALayout<>;

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/PortableTestObjects/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="y_" comment="[nElements_]"/>
<field name="z_" comment="[nElements_]"/>
<field name="id_" comment="[nElements_]"/>
<field name="metadata()" comment="!"/>
<field name="r_" comment="[scalar_]"/>
</class>
<class name="portabletest::TestSoA::View"/>
</lcgdict>
1 change: 1 addition & 0 deletions DataFormats/SoATemplate/interface/SoALayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
/* data members */ \
std::byte* mem_; \
size_type nElements_; \
size_type const scalar_ = 1; \
byte_size_type byteSize_; \
_ITERATE_ON_ALL(_DECLARE_SOA_DATA_MEMBER, ~, __VA_ARGS__) \
/* Making the code conditional is problematic in macros as the commas will interfere with parameter lisings */ \
Expand Down
23 changes: 18 additions & 5 deletions HeterogeneousCore/AlpakaTest/plugins/TestAlpakaAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@ class TestAlpakaAnalyzer : public edm::stream::EDAnalyzer<> {

edm::LogInfo msg("TestAlpakaAnalyzer");
msg << source_.encode() << ".size() = " << view.metadata().size() << '\n';
msg << "data = " << product.buffer().data() << " x = " << view.x() << " y = " << view.y() << " z = " << view.z()
<< " id = " << view.id() << '\n';
msg << std::hex << "[y - x] = 0x" << reinterpret_cast<intptr_t>(view.y()) - reinterpret_cast<intptr_t>(view.x())
<< " [z - y] = 0x" << reinterpret_cast<intptr_t>(view.z()) - reinterpret_cast<intptr_t>(view.y())
<< " [id - z] = 0x" << reinterpret_cast<intptr_t>(view.id()) - reinterpret_cast<intptr_t>(view.z());
msg << " data = " << product.buffer().data() << ",\n"
<< " x = " << view.metadata().addressOf_x() << ",\n"
<< " y = " << view.metadata().addressOf_y() << ",\n"
<< " z = " << view.metadata().addressOf_z() << ",\n"
<< " id = " << view.metadata().addressOf_id() << ",\n"
<< " r = " << view.metadata().addressOf_r() << '\n';
msg << std::hex << " [y - x] = 0x"
<< reinterpret_cast<intptr_t>(view.metadata().addressOf_y()) -
reinterpret_cast<intptr_t>(view.metadata().addressOf_x())
<< " [z - y] = 0x"
<< reinterpret_cast<intptr_t>(view.metadata().addressOf_z()) -
reinterpret_cast<intptr_t>(view.metadata().addressOf_y())
<< " [id - z] = 0x"
<< reinterpret_cast<intptr_t>(view.metadata().addressOf_id()) -
reinterpret_cast<intptr_t>(view.metadata().addressOf_z())
<< " [r - id] = 0x"
<< reinterpret_cast<intptr_t>(view.metadata().addressOf_r()) -
reinterpret_cast<intptr_t>(view.metadata().addressOf_id());
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down
3 changes: 3 additions & 0 deletions HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlgo.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// this example accepts an arbitrary number of blocks and threads, and always uses 1 element per thread
const int32_t thread = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u];
const int32_t stride = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc)[0u];
if (thread == 0) {
view.r() = 1.;
}
for (auto i = thread; i < size; i += stride) {
view[i] = {0., 0., 0., i};
}
Expand Down

0 comments on commit 22a63e1

Please sign in to comment.