1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*
* Copyright (c) 2018-2020 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/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
#include "arm_compute/core/Types.h"
#include "arm_compute/core/utils/misc/ShapeCalculator.h"
#include "arm_compute/runtime/CL/CLTensor.h"
#include "arm_compute/runtime/CL/CLTensorAllocator.h"
#include "tests/CL/CLAccessor.h"
#include "tests/CL/Helper.h"
#include "tests/PaddingCalculator.h"
#include "tests/datasets/ShapeDatasets.h"
#include "tests/framework/Asserts.h"
#include "tests/framework/Macros.h"
#include "tests/framework/datasets/Datasets.h"
#include "tests/validation/Validation.h"
#include "tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h"
namespace arm_compute
{
namespace test
{
namespace validation
{
namespace
{
// *INDENT-OFF*
// clang-format off
/** Data types */
const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
/** Batch size values to test */
const auto b_values = framework::dataset::make("batchsize", 1, 3);
/** N0 values to test */
const auto n0_values_nt_s32 = framework::dataset::make("N0", { 1, 2, 3 });
const auto n0_values_nt_s16 = framework::dataset::make("N0", { 4, 8 });
const auto n0_values_nt_s8 = framework::dataset::make("N0", { 16 });
const auto n0_values_t_s32 = framework::dataset::make("N0", { 4, 8 });
const auto n0_values_t_s16 = framework::dataset::make("N0", { 16 });
const auto n0_values_t_s8 = framework::dataset::make("N0", { 2, 3 });
/** K0 values to test */
const auto k0_values_nt_s32 = framework::dataset::make("K0", { 1, 2 });
const auto k0_values_nt_s16 = framework::dataset::make("K0", { 16 });
const auto k0_values_nt_s8 = framework::dataset::make("K0", { 3,4 });
const auto k0_values_t_s32 = framework::dataset::make("K0", { 2, 3 });
const auto k0_values_t_s16 = framework::dataset::make("K0", { 4, 8 });
const auto k0_values_t_s8 = framework::dataset::make("K0", { 16 });
/** H0 values to test */
const auto h0_values = framework::dataset::make("H0", 1, 4);
/** Interleave values to test */
const auto i_values = framework::dataset::make("interleave", { true, false });
} // namespace
using namespace arm_compute::misc::shape_calculator;
// Initialize the output tensor with zero and fill the border with zero
using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>;
template <typename T>
using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>;
TEST_SUITE(CL)
TEST_SUITE(GEMMReshapeRHSMatrix)
// *INDENT-OFF*
// clang-format off
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Mismatching data types
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong n0 value
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong k0 value
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong h0 value
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // n0 > 16
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 > 16
TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 == 1 && transpose
}),
framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(64U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F16),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
})),
framework::dataset::make("N0",{ 4, 0, 4, 4, 4, 17, 4, 4 })),
framework::dataset::make("K0",{ 4, 4, 0, 4, 4, 4, 17, 1 })),
framework::dataset::make("H0",{ 4, 4, 4, 0, 4, 4, 4, 4 })),
framework::dataset::make("Expected", { false, false, false, false, false, false, false})),
input_info, output_info, n0, k0, h0, expected)
{
GEMMRHSMatrixInfo rhs_info;
rhs_info.n0 = n0;
rhs_info.k0 = k0;
rhs_info.h0 = h0;
rhs_info.transpose = true;
rhs_info.interleave = true;
bool has_error = bool(CLGEMMReshapeRHSMatrixKernel::validate(&input_info.clone()->set_is_resizable(false), (output_info.total_size() == 0) ? nullptr : &output_info.clone()->set_is_resizable(false), rhs_info));
ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
}
DATA_TEST_CASE(ValidatePadding, framework::DatasetMode::ALL, combine(combine(combine(
framework::dataset::make("InputShape", { TensorShape(32U, 16U, 1U),
TensorShape(32U, 16U, 2U)
}),
framework::dataset::make("N0",{ 4 })),
framework::dataset::make("K0",{ 4, 8, 16 })),
framework::dataset::make("H0",{ 1, 2, 4 })),
input_shape, n0, k0, h0)
{
CLTensor input;
CLTensor output;
input.info()->init(input_shape, 1, DataType::F32);
unsigned int padding = 0;
GEMMRHSMatrixInfo rhs_info;
rhs_info.n0 = n0;
rhs_info.k0 = k0;
rhs_info.h0 = h0;
rhs_info.transpose = true;
rhs_info.interleave = true;
rhs_info.export_to_cl_image = image2d_from_buffer_supported(CLKernelLibrary::get().get_device()) && (get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) != 0);
if(rhs_info.export_to_cl_image)
{
TensorShape output_shape = compute_rhs_reshaped_shape(*input.info(), rhs_info);
constexpr unsigned int num_floats_per_pixel = 4;
const unsigned int pixel_aligment = get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device());
const unsigned int row_pitch_alignment = pixel_aligment * num_floats_per_pixel;
const unsigned int round_up_width = ((output_shape[0] + row_pitch_alignment - 1) / row_pitch_alignment) * row_pitch_alignment;
padding = round_up_width - output_shape[0];
}
CLGEMMReshapeRHSMatrixKernel kernel;
kernel.configure(&input, &output, rhs_info);
ARM_COMPUTE_EXPECT((output.info()->padding().right == padding), framework::LogLevel::ERRORS);
}
// clang-format on
// *INDENT-ON*
// Run S32 tests only for transpose = false
FIXTURE_DATA_TEST_CASE(S32_NT, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S32)),
n0_values_nt_s32),
k0_values_nt_s32),
h0_values),
i_values),
framework::dataset::make("transpose", false)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
// Run S32 tests only for transpose = true
FIXTURE_DATA_TEST_CASE(S32_T, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S32)),
n0_values_t_s32),
k0_values_t_s32),
h0_values),
i_values),
framework::dataset::make("transpose", true)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
// Run S16 tests only for transpose = false
FIXTURE_DATA_TEST_CASE(S16_NT, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S16)),
n0_values_nt_s16),
k0_values_nt_s16),
h0_values),
i_values),
framework::dataset::make("transpose", false)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
// Run S16 tests only for transpose = true
FIXTURE_DATA_TEST_CASE(S16_T, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S16)),
n0_values_t_s16),
k0_values_t_s16),
h0_values),
i_values),
framework::dataset::make("transpose", true)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
// Run S8 tests only for transpose = false
FIXTURE_DATA_TEST_CASE(S8_NT, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S8)),
n0_values_nt_s8),
k0_values_nt_s8),
h0_values),
i_values),
framework::dataset::make("transpose", false)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
// Run S8 tests only for transpose = true
FIXTURE_DATA_TEST_CASE(S8_T, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
b_values),
framework::dataset::make("DataType", DataType::S8)),
n0_values_t_s8),
k0_values_t_s8),
h0_values),
i_values),
framework::dataset::make("transpose", true)))
{
// Validate output
validate(CLAccessor(_target), _reference);
}
TEST_SUITE_END() // GEMMReshapeRHSMatrix
TEST_SUITE_END() // CL
} // namespace validation
} // namespace test
} // namespace arm_compute
|