aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/SConscript2
-rw-r--r--tests/validation/CL/UNIT/Extensions.cpp49
-rw-r--r--tests/validation/UNIT/Version.cpp47
-rw-r--r--tests/validation/cpu/unit/Context.cpp197
-rw-r--r--tests/validation/gpu/unit/Context.cpp168
5 files changed, 463 insertions, 0 deletions
diff --git a/tests/SConscript b/tests/SConscript
index 8eebe5f2d8..fea68e0fe9 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -127,6 +127,7 @@ if env['opencl']:
files_validation += Glob('validation/CL/' + filter_pattern)
if env['external_tests_dir']:
files_validation += Glob(env['external_tests_dir'] + '/tests/validation/CL/' + filter_pattern)
+ files_validation += Glob('validation/gpu/unit/*.cpp')
if env['neon']:
filter_pattern = test_env['test_filter']
@@ -144,6 +145,7 @@ if env['neon']:
files_validation += Glob('validation/NEON/*/' + filter_pattern)
if env['external_tests_dir']:
files_validation += Glob(env['external_tests_dir'] + '/tests/validation/NEON/' + filter_pattern)
+ files_validation += Glob('validation/cpu/unit/*.cpp')
extra_link_flags = []
if env['os'] == 'android':
diff --git a/tests/validation/CL/UNIT/Extensions.cpp b/tests/validation/CL/UNIT/Extensions.cpp
new file mode 100644
index 0000000000..8119290d4b
--- /dev/null
+++ b/tests/validation/CL/UNIT/Extensions.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclVersion.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/validation/Validation.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+TEST_SUITE(CL)
+TEST_SUITE(UNIT)
+TEST_CASE(GetClContext, framework::DatasetMode::ALL)
+{
+ const auto ver = AclVersionInfo();
+ ARM_COMPUTE_EXPECT(ver->major == ARM_COMPUTE_LIBRARY_VERSION_MAJOR, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(ver->minor == ARM_COMPUTE_LIBRARY_VERSION_MINOR, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(ver->patch == ARM_COMPUTE_LIBRARY_VERSION_PATCH, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(!std::string(ver->build_info).empty(), framework::LogLevel::ERRORS);
+}
+TEST_SUITE_END() // UNIT
+TEST_SUITE_END() // CL
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/UNIT/Version.cpp b/tests/validation/UNIT/Version.cpp
new file mode 100644
index 0000000000..72e2d48113
--- /dev/null
+++ b/tests/validation/UNIT/Version.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclVersion.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/validation/Validation.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+TEST_SUITE(UNIT)
+TEST_CASE(Version, framework::DatasetMode::ALL)
+{
+ const auto ver = AclVersionInfo();
+ ARM_COMPUTE_EXPECT(ver->major == ARM_COMPUTE_LIBRARY_VERSION_MAJOR, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(ver->minor == ARM_COMPUTE_LIBRARY_VERSION_MINOR, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(ver->patch == ARM_COMPUTE_LIBRARY_VERSION_PATCH, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(!std::string(ver->build_info).empty(), framework::LogLevel::ERRORS);
+}
+TEST_SUITE_END() // UNIT
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/cpu/unit/Context.cpp b/tests/validation/cpu/unit/Context.cpp
new file mode 100644
index 0000000000..bf2a02df5d
--- /dev/null
+++ b/tests/validation/cpu/unit/Context.cpp
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/validation/Validation.h"
+
+#include "arm_compute/Acl.hpp"
+
+#include "src/cpu/CpuContext.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+TEST_SUITE(CPU)
+TEST_SUITE(UNIT)
+TEST_SUITE(Context)
+
+/** Test-case for AclCreateContext
+ *
+ * Validate that AclCreateContext behaves as expected on invalid target
+ *
+ * Test Steps:
+ * - Call AclCreateContext with invalid target
+ * - Confirm that AclUnsupportedTarget is reported
+ * - Confirm that context is still nullptr
+ */
+TEST_CASE(CreateContextWithInvalidTarget, framework::DatasetMode::ALL)
+{
+ AclTarget invalid_target = static_cast<AclTarget>(-1);
+ AclContext ctx = nullptr;
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, invalid_target, nullptr) == AclStatus::AclUnsupportedTarget);
+ ARM_COMPUTE_ASSERT(ctx == nullptr);
+}
+
+/** Test-case for AclCreateContext
+ *
+ * Validate that AclCreateContext behaves as expected on invalid context options
+ *
+ * Test Steps:
+ * - Call AclCreateContext with valid target but invalid context options
+ * - Confirm that AclInvalidArgument is reported
+ * - Confirm that context is still nullptr
+ */
+TEST_CASE(CreateContextWithInvalidOptions, framework::DatasetMode::ALL)
+{
+ AclContextOptions invalid_ctx_opts;
+ invalid_ctx_opts.mode = static_cast<AclExecutionMode>(-1);
+ invalid_ctx_opts.capabilities = AclCpuCapabilitiesAuto;
+ invalid_ctx_opts.max_compute_units = 0;
+ invalid_ctx_opts.enable_fast_math = false;
+ invalid_ctx_opts.kernel_config_file = "";
+ AclContext ctx = nullptr;
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclCpu, &invalid_ctx_opts) == AclStatus::AclInvalidArgument);
+ ARM_COMPUTE_ASSERT(ctx == nullptr);
+}
+
+/** Test-case for AclDestroyContext
+ *
+ * Validate that AclDestroyContext behaves as expected when invalid inputs as context are given
+ *
+ * Test Steps:
+ * - Call AclDestroyContext with null context
+ * - Confirm that AclInvalidArgument is reported
+ * - Call AclDestroyContext on empty array
+ * - Confirm that AclInvalidArgument is reported
+ * - Call AclDestroyContext on an ACL object other than AclContext
+ * - Confirm that AclInvalidArgument is reported
+ * - Confirm that context is still nullptr
+ */
+TEST_CASE(DestroyInvalidContext, framework::DatasetMode::ALL)
+{
+ AclContext ctx = nullptr;
+ std::array<char, 256> empty_array{};
+ AclContext valid_ctx = nullptr;
+ ARM_COMPUTE_ASSERT(AclCreateContext(&valid_ctx, AclCpu, nullptr) == AclStatus::AclSuccess);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclInvalidArgument);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(reinterpret_cast<AclContext>(empty_array.data())) == AclStatus::AclInvalidArgument);
+ ARM_COMPUTE_ASSERT(ctx == nullptr);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(valid_ctx) == AclStatus::AclSuccess);
+}
+
+/** Test-case for AclCreateContext and AclDestroy Context
+ *
+ * Validate that AclCreateContext can create and destroy a context
+ *
+ * Test Steps:
+ * - Call AclCreateContext with valid target
+ * - Confirm that context is not nullptr and error code is AclSuccess
+ * - Destroy context
+ * - Confirm that AclSuccess is reported
+ */
+TEST_CASE(SimpleContextCApi, framework::DatasetMode::ALL)
+{
+ AclContext ctx = nullptr;
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclCpu, nullptr) == AclStatus::AclSuccess);
+ ARM_COMPUTE_ASSERT(ctx != nullptr);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclSuccess);
+}
+
+/** Test-case for Context from the C++ interface
+ *
+ * Test Steps:
+ * - Create a Context obejct
+ * - Confirm that StatusCode::Success is reported
+ * - Confirm that equality operator works
+ * - Confirm that inequality operator works
+ */
+TEST_CASE(SimpleContextCppApi, framework::DatasetMode::ALL)
+{
+ acl::StatusCode status = acl::StatusCode::Success;
+ acl::Context ctx(acl::Target::Cpu, &status);
+ ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
+
+ auto ctx_eq = ctx;
+ ARM_COMPUTE_ASSERT(ctx_eq == ctx);
+
+ acl::Context ctx_ienq(acl::Target::Cpu, &status);
+ ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
+ ARM_COMPUTE_ASSERT(ctx_ienq != ctx);
+}
+
+/** Test-case for CpuCapabilities
+ *
+ * Validate that AclCreateContext can create/destroy multiple contexts with different options
+ *
+ * Test Steps:
+ * - Call AclCreateContext with different targets
+ * - Confirm that AclSuccess is reported
+ * - Destroy all contexts
+ * - Confirm that AclSuccess is reported
+ */
+TEST_CASE(MultipleContexts, framework::DatasetMode::ALL)
+{
+ const unsigned int num_tests = 5;
+ std::array<AclContext, num_tests> ctxs{};
+ for(unsigned int i = 0; i < num_tests; ++i)
+ {
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctxs[i], AclTarget::AclCpu, nullptr) == AclStatus::AclSuccess);
+ ARM_COMPUTE_ASSERT(ctxs[i] != nullptr);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(ctxs[i]) == AclStatus::AclSuccess);
+ }
+}
+
+/** Test-case for CpuCapabilities
+ *
+ * Validate that CpuCapabilities are set correctly
+ *
+ * Test Steps:
+ * - Create a context with a given list of capabilities
+ * - Confirm that AclSuccess is reported
+ * - Validate that all capabilities are set correctly
+ */
+TEST_CASE(CpuCapabilities, framework::DatasetMode::ALL)
+{
+ AclContextOptions opts = acl_default_ctx_options;
+ opts.capabilities = AclCpuCapabilitiesDot | AclCpuCapabilitiesMmlaInt8 | AclCpuCapabilitiesSve2;
+ arm_compute::cpu::CpuContext ctx(&opts);
+
+ ARM_COMPUTE_ASSERT(ctx.capabilities().dot == true);
+ ARM_COMPUTE_ASSERT(ctx.capabilities().mmla_int8 == true);
+ ARM_COMPUTE_ASSERT(ctx.capabilities().sve2 == true);
+ ARM_COMPUTE_ASSERT(ctx.capabilities().fp16 == false);
+
+ arm_compute::cpu::CpuContext ctx_legacy(nullptr);
+ ARM_COMPUTE_ASSERT(ctx_legacy.capabilities().neon == true);
+}
+
+TEST_SUITE_END() // Context
+TEST_SUITE_END() // UNIT
+TEST_SUITE_END() // CPU
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/gpu/unit/Context.cpp b/tests/validation/gpu/unit/Context.cpp
new file mode 100644
index 0000000000..06b4a83925
--- /dev/null
+++ b/tests/validation/gpu/unit/Context.cpp
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/validation/Validation.h"
+
+#include "arm_compute/Acl.hpp"
+
+#include "src/gpu/cl/ClContext.h"
+
+using namespace arm_compute::mlgo;
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+TEST_SUITE(CL)
+TEST_SUITE(UNIT)
+TEST_SUITE(Context)
+
+/** Test-case for AclCreateContext and AclDestroy Context
+ *
+ * Validate that AclCreateContext can create and destroy a context
+ *
+ * Test Steps:
+ * - Call AclCreateContext with valid target
+ * - Confirm that context is not nullptr and error code is AclSuccess
+ * - Destroy context
+ * - Confirm that AclSuccess is reported
+ */
+TEST_CASE(SimpleContextCApi, framework::DatasetMode::ALL)
+{
+ AclContext ctx = nullptr;
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclGpuOcl, nullptr) == AclStatus::AclSuccess);
+ ARM_COMPUTE_ASSERT(ctx != nullptr);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclSuccess);
+}
+
+/** Test-case for Context from the C++ interface
+ *
+ * Test Steps:
+ * - Create a Context obejct
+ * - Confirm that StatusCode::Success is reported
+ * - Confirm that equality operator works
+ * - Confirm that inequality operator works
+ */
+TEST_CASE(SimpleContextCppApi, framework::DatasetMode::ALL)
+{
+ acl::StatusCode status = acl::StatusCode::Success;
+ acl::Context ctx(acl::Target::GpuOcl, &status);
+ ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
+
+ auto ctx_eq = ctx;
+ ARM_COMPUTE_ASSERT(ctx_eq == ctx);
+
+ acl::Context ctx_ienq(acl::Target::GpuOcl, &status);
+ ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
+ ARM_COMPUTE_ASSERT(ctx_ienq != ctx);
+}
+
+/** Test-case for CpuCapabilities
+ *
+ * Validate that AclCreateContext can create/destroy multiple contexts with different options
+ *
+ * Test Steps:
+ * - Call AclCreateContext with different targets
+ * - Confirm that AclSuccess is reported
+ * - Destroy all contexts
+ * - Confirm that AclSuccess is reported
+ */
+TEST_CASE(MultipleContexts, framework::DatasetMode::ALL)
+{
+ const unsigned int num_tests = 5;
+ std::array<AclContext, num_tests> ctxs{};
+ for(unsigned int i = 0; i < num_tests; ++i)
+ {
+ ARM_COMPUTE_ASSERT(AclCreateContext(&ctxs[i], AclTarget::AclGpuOcl, nullptr) == AclStatus::AclSuccess);
+ ARM_COMPUTE_ASSERT(ctxs[i] != nullptr);
+ ARM_COMPUTE_ASSERT(AclDestroyContext(ctxs[i]) == AclStatus::AclSuccess);
+ }
+}
+
+/** Test-case for MLGO kernel configuration file
+ *
+ * Validate that CpuCapabilities are set correctly
+ *
+ * Test Steps:
+ * - Create a file with the MLGO configuration
+ * - Pass the kernel file to the Context during creation
+ * - Validate that the MLGO file has been parsed successfully
+ */
+TEST_CASE(CheckMLGO, framework::DatasetMode::ALL)
+{
+ // Create test mlgo file
+ std::string mlgo_str = R"_(
+
+ <header>
+
+ gemm-version, [1,2,1]
+ ip-type,gpu
+ </header>
+ <heuristics-table>
+ 0, g76 , 8, f32, best-performance, static, gemm-type, [m,n,k,n]
+ 1, g76 , 8, f16, best-performance, static, gemm-config-reshaped, [m,n,k,n]
+ </heuristics-table>
+ <heuristic, 0>
+ b , 0, var, m, ==, num, 10., 1, 2
+ l , 1, gemm-type, reshaped
+ b , 2, var, r_mn, >=, num, 2., 3, 6
+
+ b , 3, var, n, >=, num, 200., 4, 5
+ l, 4, gemm-type, reshaped-only-rhs
+ l , 5, gemm-type, reshaped
+ l , 6, gemm-type, reshaped-only-rhs
+ </heuristic>
+
+ <heuristic, 1>
+ l ,0,gemm-config-reshaped,[4,2,4,2,8,1,0,1,0]
+ </heuristic>
+
+ )_";
+ const std::string mlgo_filename = "test.mlgo";
+ std::ofstream ofs(mlgo_filename, std::ofstream::trunc);
+ ARM_COMPUTE_EXPECT(ofs, framework::LogLevel::ERRORS);
+ ofs << mlgo_str;
+ ofs.close();
+
+ AclContextOptions opts = acl_default_ctx_options;
+ opts.kernel_config_file = mlgo_filename.c_str();
+ arm_compute::gpu::opencl::ClContext ctx(&opts);
+
+ const MLGOHeuristics &heuristics = ctx.mlgo();
+
+ ARM_COMPUTE_EXPECT(heuristics.query_gemm_type(Query{ "g76", DataType::F32, 10, 1024, 20, 1 }).second == GEMMType::RESHAPED,
+ framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT((heuristics.query_gemm_config_reshaped(Query{ "g76", DataType::F16, 100, 100, 20, 32 }).second == GEMMConfigReshaped{ 4, 2, 4, 2, 8, true, false, true, false }),
+ framework::LogLevel::ERRORS);
+}
+
+TEST_SUITE_END() // Context
+TEST_SUITE_END() // UNIT
+TEST_SUITE_END() // CL
+} // namespace validation
+} // namespace test
+} // namespace arm_compute