| 89 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 90 | TEST_SUITE(BF16) |
| 91 | TEST_CASE(LUTValueTest, framework::DatasetMode::ALL) |
| 92 | { |
| 93 | // Define values for test |
| 94 | constexpr float beta = -1.0f; |
| 95 | constexpr float rel_tolerance = 0.01f; |
| 96 | constexpr int num_elements = 65536; |
| 97 | unsigned int num_mismatches = 0; |
| 98 | |
| 99 | // Create lutinfo, use to get lut |
| 100 | LUTInfo info = {LUTType::Exponential, beta, DataType::BFLOAT16, UniformQuantizationInfo()}; |
| 101 | LUTManager lman = LUTManager::get_instance(); |
| 102 | |
| 103 | if (cpu_supports_dtypes({DataType::BFLOAT16})) |
| 104 | { |
| 105 | // Retrieve lut, Assert lut exists and is retrieved successfully. |
| 106 | std::shared_ptr<LookupTable65536> lut = lman.get_lut_table<LookupTable65536>(info); |
| 107 | ARM_COMPUTE_EXPECT(lut != nullptr, framework::LogLevel::ALL); |
| 108 | |
| 109 | // Check each value in lut |
| 110 | for (int i = 0; i < num_elements; i++) |
| 111 | { |
| 112 | // Calculate reference in fp32. Convert lut value to fp32. |
| 113 | const float fref = std::exp(bf16_to_float(i) * beta); |
| 114 | const uint16_t target_bf16 = read_as_bf16((*lut)[i]); |
| 115 | const float target = bf16_to_float(target_bf16); |
| 116 | |
| 117 | // Compare and increment mismatch count if needed. |
| 118 | if (!equal_values_relative(target, fref, rel_tolerance)) |
| 119 | { |
| 120 | ARM_COMPUTE_TEST_INFO("id = " << i); |
| 121 | ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target)); |
| 122 | ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(fref)); |
| 123 | ARM_COMPUTE_TEST_INFO("relative tolerance = " << std::setprecision(5) |
| 124 | << framework::make_printable(rel_tolerance)); |
| 125 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 126 | ++num_mismatches; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (num_mismatches != 0) |
| 131 | { |
| 132 | const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f; |
| 133 | ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) |
| 134 | << percent_mismatches << "%) mismatched "); |
| 135 | } |
| 136 | |
| 137 | // Check if passed tests |
| 138 | ARM_COMPUTE_EXPECT(num_mismatches == 0, framework::LogLevel::ERRORS); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | TEST_CASE(CheckLutReuse, framework::DatasetMode::ALL) |
| 143 | { |
nothing calls this directly
no test coverage detected