Skip to content

Commit

Permalink
Merge pull request #44703 from fwyzard/implement_HeterogeneousTest_Al…
Browse files Browse the repository at this point in the history
…paka_alt_140x

Use explicit acelerator types in alpaka tests [14.0.x]
  • Loading branch information
cmsbuild authored Apr 12, 2024
2 parents 4109f34 + 9a0bcd7 commit 289d578
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 44 deletions.
10 changes: 4 additions & 6 deletions HeterogeneousTest/AlpakaDevice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ Alpaka-based libraries, and using them from multiple plugins.
The package `HeterogeneousTest/AlpakaDevice` implements a library that defines and exports Alpaka
device-side functions:
```c++
namespace cms::alpakatest {
namespace ALPAKA_ACCELERATOR_NAMESPACE::test {

template <typename TAcc>
ALPAKA_FN_ACC void add_vectors_f(TAcc const& acc, ...);
inline ALPAKA_FN_ACC void add_vectors_f(Acc1D const& acc, ...) { ... }

template <typename TAcc>
ALPAKA_FN_ACC void add_vectors_d(TAcc const& acc, ...);
inline ALPAKA_FN_ACC void add_vectors_d(Acc1D const& acc, ...) { ... }

} // namespace cms::alpakatest
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::test
```
The `plugins` directory implements the `AlpakaTestDeviceAdditionModule` `EDAnalyzer` that launches
Expand Down
27 changes: 13 additions & 14 deletions HeterogeneousTest/AlpakaDevice/interface/alpaka/DeviceAddition.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@

#include <alpaka/alpaka.hpp>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"

namespace cms::alpakatest {
namespace ALPAKA_ACCELERATOR_NAMESPACE::test {

template <typename TAcc>
ALPAKA_FN_ACC void add_vectors_f(TAcc const& acc,
float const* __restrict__ in1,
float const* __restrict__ in2,
float* __restrict__ out,
uint32_t size) {
inline ALPAKA_FN_ACC void add_vectors_f(Acc1D const& acc,
float const* __restrict__ in1,
float const* __restrict__ in2,
float* __restrict__ out,
uint32_t size) {
for (auto i : cms::alpakatools::uniform_elements(acc, size)) {
out[i] = in1[i] + in2[i];
}
}

template <typename TAcc>
ALPAKA_FN_ACC void add_vectors_d(TAcc const& acc,
double const* __restrict__ in1,
double const* __restrict__ in2,
double* __restrict__ out,
uint32_t size) {
inline ALPAKA_FN_ACC void add_vectors_d(Acc1D const& acc,
double const* __restrict__ in1,
double const* __restrict__ in2,
double* __restrict__ out,
uint32_t size) {
for (auto i : cms::alpakatools::uniform_elements(acc, size)) {
out[i] = in1[i] + in2[i];
}
}

} // namespace cms::alpakatest
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::test

#endif // HeterogeneousTest_AlpakaDevice_interface_alpaka_DeviceAddition_h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
namespace ALPAKA_ACCELERATOR_NAMESPACE::HeterogeneousTestAlpakaDevicePlugins {

struct KernelAddVectorsF {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
const float* __restrict__ in1,
const float* __restrict__ in2,
float* __restrict__ out,
uint32_t size) const {
cms::alpakatest::add_vectors_f(acc, in1, in2, out, size);
test::add_vectors_f(acc, in1, in2, out, size);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
using namespace ALPAKA_ACCELERATOR_NAMESPACE;

struct KernelAddVectorsF {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
const float* __restrict__ in1,
const float* __restrict__ in2,
float* __restrict__ out,
uint32_t size) const {
cms::alpakatest::add_vectors_f(acc, in1, in2, out, size);
test::add_vectors_f(acc, in1, in2, out, size);
}
};

Expand Down
10 changes: 4 additions & 6 deletions HeterogeneousTest/AlpakaKernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ Alpaka-based libraries, and using them from multiple plugins.
The package `HeterogeneousTest/AlpakaKernel` implements a library that defines and exports Alpaka
kernels that call the device functions defined in the `HeterogeneousTest/AlpakaDevice` library:
```c++
namespace cms::alpakatest {
namespace ALPAKA_ACCELERATOR_NAMESPACE::test {

struct KernelAddVectorsF {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc, ...) const;
ALPAKA_FN_ACC void operator()(Acc1D const& acc, ...) const { ... }
};

struct KernelAddVectorsD {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc, ...) const;
ALPAKA_FN_ACC void operator()(Acc1D const& acc, ...) const { ... }
};

} // namespace cms::alpakatest
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::test
```
The `plugins` directory implements the `AlpakaTestKernelAdditionModule` `EDAnalyzer` that launches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

#include <alpaka/alpaka.hpp>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousTest/AlpakaDevice/interface/alpaka/DeviceAddition.h"

namespace cms::alpakatest {
namespace ALPAKA_ACCELERATOR_NAMESPACE::test {

struct KernelAddVectorsF {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
const float* __restrict__ in1,
const float* __restrict__ in2,
float* __restrict__ out,
Expand All @@ -21,8 +21,7 @@ namespace cms::alpakatest {
};

struct KernelAddVectorsD {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
const double* __restrict__ in1,
const double* __restrict__ in2,
double* __restrict__ out,
Expand All @@ -31,6 +30,6 @@ namespace cms::alpakatest {
}
};

} // namespace cms::alpakatest
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::test

#endif // HeterogeneousTest_AlpakaKernel_interface_alpaka_DeviceAdditionKernel_h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::HeterogeneousTestAlpakaKernelPlugins {
float* __restrict__ out,
uint32_t size) {
alpaka::exec<Acc1D>(
queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), cms::alpakatest::KernelAddVectorsF{}, in1, in2, out, size);
queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), test::KernelAddVectorsF{}, in1, in2, out, size);
}

} // namespace ALPAKA_ACCELERATOR_NAMESPACE::HeterogeneousTestAlpakaKernelPlugins
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ TEST_CASE("HeterogeneousTest/AlpakaKernel test", "[alpakaTestDeviceAdditionKerne
// launch the 1-dimensional kernel for vector addition
alpaka::exec<Acc1D>(queue,
cms::alpakatools::make_workdiv<Acc1D>(32, 32),
cms::alpakatest::KernelAddVectorsF{},
test::KernelAddVectorsF{},
in1_d.data(),
in2_d.data(),
out_d.data(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::test {
const float* __restrict__ in2,
float* __restrict__ out,
uint32_t size) {
alpaka::exec<Acc1D>(
queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), cms::alpakatest::KernelAddVectorsF{}, in1, in2, out, size);
alpaka::exec<Acc1D>(queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), KernelAddVectorsF{}, in1, in2, out, size);
}

void wrapper_add_vectors_d(Queue& queue,
const double* __restrict__ in1,
const double* __restrict__ in2,
double* __restrict__ out,
uint32_t size) {
alpaka::exec<Acc1D>(
queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), cms::alpakatest::KernelAddVectorsD{}, in1, in2, out, size);
alpaka::exec<Acc1D>(queue, cms::alpakatools::make_workdiv<Acc1D>(32, 32), KernelAddVectorsD{}, in1, in2, out, size);
}

} // namespace ALPAKA_ACCELERATOR_NAMESPACE::test

0 comments on commit 289d578

Please sign in to comment.