| 1456 | |
| 1457 | template <typename LhsScalar, typename RhsScalar, typename Spec> |
| 1458 | void MakeSpecClampFields(const Matrix<LhsScalar>& lhs, |
| 1459 | const Matrix<RhsScalar>& rhs, |
| 1460 | typename Spec::DstScalar dst_zero_point, Spec* spec) { |
| 1461 | using AccumScalar = typename Spec::AccumScalar; |
| 1462 | using DstScalar = typename Spec::DstScalar; |
| 1463 | |
| 1464 | if (getenv("BENCHMARK_ONLY_MATMUL")) { |
| 1465 | spec->clamp_min = -std::numeric_limits<DstScalar>::infinity(); |
| 1466 | spec->clamp_max = std::numeric_limits<DstScalar>::infinity(); |
| 1467 | return; |
| 1468 | } |
| 1469 | |
| 1470 | if (getenv("QUICK_BENCHMARK")) { |
| 1471 | spec->clamp_min = std::numeric_limits<DstScalar>::lowest() + 1; |
| 1472 | spec->clamp_max = std::numeric_limits<DstScalar>::max() - 1; |
| 1473 | return; |
| 1474 | } |
| 1475 | Context context; |
| 1476 | context.SetRuntimeEnabledPaths(Path::kReference); |
| 1477 | Matrix<DstScalar> unclamped_dst; |
| 1478 | MakeSimpleLayout(lhs.layout.rows, rhs.layout.cols, Order::kColMajor, |
| 1479 | &unclamped_dst.layout); |
| 1480 | unclamped_dst.zero_point = dst_zero_point; |
| 1481 | const int size = FlatSize(unclamped_dst.layout); |
| 1482 | std::vector<DstScalar> unclamped_dst_data(size); |
| 1483 | unclamped_dst.data = unclamped_dst_data.data(); |
| 1484 | ruy::BasicSpec<AccumScalar, DstScalar> spec_unclamped; |
| 1485 | spec_unclamped.bias = spec->bias; |
| 1486 | spec_unclamped.multiplier_fixedpoint = spec->multiplier_fixedpoint; |
| 1487 | spec_unclamped.multiplier_exponent = spec->multiplier_exponent; |
| 1488 | spec_unclamped.multiplier_fixedpoint_perchannel = |
| 1489 | spec->multiplier_fixedpoint_perchannel; |
| 1490 | spec_unclamped.multiplier_exponent_perchannel = |
| 1491 | spec->multiplier_exponent_perchannel; |
| 1492 | Mul<Path::kReference>(lhs, rhs, spec_unclamped, &context, &unclamped_dst); |
| 1493 | // If dst is std::int32_t, no need to set the clamp min/max. |
| 1494 | if (!std::is_same<typename Spec::DstScalar, std::int32_t>::value) { |
| 1495 | std::sort(unclamped_dst_data.begin(), unclamped_dst_data.end()); |
| 1496 | const int clamp_count = static_cast<int>(std::floor(kClampRatio * size)); |
| 1497 | RUY_CHECK_LT(clamp_count, size); |
| 1498 | spec->clamp_min = unclamped_dst_data[clamp_count]; |
| 1499 | spec->clamp_max = unclamped_dst_data[size - 1 - clamp_count]; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | template <typename LhsScalar, typename RhsScalar, typename SpecType> |
| 1504 | void TestSet<LhsScalar, RhsScalar, SpecType>::MakeZeroPoints() { |