File indexing completed on 2024-04-09 02:22:22
0001 #include <cstdint>
0002 #include <random>
0003 #include <vector>
0004
0005 #define CATCH_CONFIG_MAIN
0006 #include <catch.hpp>
0007
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
0010 #include "HeterogeneousTest/AlpakaOpaque/interface/alpaka/DeviceAdditionOpaque.h"
0011
0012 using namespace ALPAKA_ACCELERATOR_NAMESPACE;
0013
0014 TEST_CASE("HeterogeneousTest/AlpakaOpaque test", "[alpakaTestOpaqueAdditionOpaque]") {
0015 auto const& devices = cms::alpakatools::devices<Platform>();
0016 if (devices.empty()) {
0017 FAIL("No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, "
0018 "the test will be skipped.");
0019 }
0020
0021
0022 std::random_device rd{};
0023 std::default_random_engine rand{rd()};
0024 std::normal_distribution<float> dist{0., 1.};
0025
0026
0027 constexpr float epsilon = 0.000001;
0028
0029
0030 constexpr uint32_t size = 1024 * 1024;
0031
0032
0033 std::vector<float> in1(size);
0034 std::vector<float> in2(size);
0035 std::vector<float> out(size);
0036
0037
0038 for (uint32_t i = 0; i < size; ++i) {
0039 in1[i] = dist(rand);
0040 in2[i] = dist(rand);
0041 out[i] = 0.;
0042 }
0043
0044 SECTION("Test add_vectors_f on " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend") {
0045
0046 REQUIRE_NOTHROW(test::opaque_add_vectors_f(in1.data(), in2.data(), out.data(), size));
0047
0048
0049 for (uint32_t i = 0; i < size; ++i) {
0050 float sum = in1[i] + in2[i];
0051 CHECK_THAT(out[i], Catch::Matchers::WithinAbs(sum, epsilon));
0052 }
0053 }
0054 }