Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame^] | 24 | #include "tests/validation/fixtures/UNIT/ContextFixture.h" |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 25 | |
| 26 | #include "src/gpu/cl/ClContext.h" |
| 27 | |
| 28 | using namespace arm_compute::mlgo; |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace test |
| 33 | { |
| 34 | namespace validation |
| 35 | { |
| 36 | TEST_SUITE(CL) |
| 37 | TEST_SUITE(UNIT) |
| 38 | TEST_SUITE(Context) |
| 39 | |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame^] | 40 | EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCApi, SimpleContextCApiFixture<AclTarget::AclGpuOcl>, framework::DatasetMode::ALL) |
| 41 | EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCppApi, SimpleContextCppApiFixture<acl::Target::GpuOcl>, framework::DatasetMode::ALL) |
| 42 | EMPTY_BODY_FIXTURE_TEST_CASE(MultipleContexts, MultipleContextsFixture<AclTarget::AclGpuOcl>, framework::DatasetMode::ALL) |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 43 | |
| 44 | /** Test-case for MLGO kernel configuration file |
| 45 | * |
| 46 | * Validate that CpuCapabilities are set correctly |
| 47 | * |
| 48 | * Test Steps: |
| 49 | * - Create a file with the MLGO configuration |
| 50 | * - Pass the kernel file to the Context during creation |
| 51 | * - Validate that the MLGO file has been parsed successfully |
| 52 | */ |
| 53 | TEST_CASE(CheckMLGO, framework::DatasetMode::ALL) |
| 54 | { |
| 55 | // Create test mlgo file |
| 56 | std::string mlgo_str = R"_( |
| 57 | |
| 58 | <header> |
| 59 | |
| 60 | gemm-version, [1,2,1] |
| 61 | ip-type,gpu |
| 62 | </header> |
| 63 | <heuristics-table> |
| 64 | 0, g76 , 8, f32, best-performance, static, gemm-type, [m,n,k,n] |
| 65 | 1, g76 , 8, f16, best-performance, static, gemm-config-reshaped, [m,n,k,n] |
| 66 | </heuristics-table> |
| 67 | <heuristic, 0> |
| 68 | b , 0, var, m, ==, num, 10., 1, 2 |
| 69 | l , 1, gemm-type, reshaped |
| 70 | b , 2, var, r_mn, >=, num, 2., 3, 6 |
| 71 | |
| 72 | b , 3, var, n, >=, num, 200., 4, 5 |
| 73 | l, 4, gemm-type, reshaped-only-rhs |
| 74 | l , 5, gemm-type, reshaped |
| 75 | l , 6, gemm-type, reshaped-only-rhs |
| 76 | </heuristic> |
| 77 | |
| 78 | <heuristic, 1> |
| 79 | l ,0,gemm-config-reshaped,[4,2,4,2,8,1,0,1,0] |
| 80 | </heuristic> |
| 81 | |
| 82 | )_"; |
| 83 | const std::string mlgo_filename = "test.mlgo"; |
| 84 | std::ofstream ofs(mlgo_filename, std::ofstream::trunc); |
| 85 | ARM_COMPUTE_EXPECT(ofs, framework::LogLevel::ERRORS); |
| 86 | ofs << mlgo_str; |
| 87 | ofs.close(); |
| 88 | |
Georgios Pinitas | 3f26ef4 | 2021-02-23 10:01:33 +0000 | [diff] [blame] | 89 | acl::Context::Options opts; |
| 90 | opts.copts.kernel_config_file = mlgo_filename.c_str(); |
| 91 | arm_compute::gpu::opencl::ClContext ctx(&opts.copts); |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 92 | |
| 93 | const MLGOHeuristics &heuristics = ctx.mlgo(); |
| 94 | |
| 95 | ARM_COMPUTE_EXPECT(heuristics.query_gemm_type(Query{ "g76", DataType::F32, 10, 1024, 20, 1 }).second == GEMMType::RESHAPED, |
| 96 | framework::LogLevel::ERRORS); |
| 97 | 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 }), |
| 98 | framework::LogLevel::ERRORS); |
| 99 | } |
| 100 | |
| 101 | TEST_SUITE_END() // Context |
| 102 | TEST_SUITE_END() // UNIT |
| 103 | TEST_SUITE_END() // CL |
| 104 | } // namespace validation |
| 105 | } // namespace test |
| 106 | } // namespace arm_compute |