|
4 | 4 | #include <cmath> |
5 | 5 | #include <gtest/gtest.h> |
6 | 6 | #include <hipdnn_data_sdk/types.hpp> |
| 7 | +#include <hipdnn_data_sdk/utilities/ShapeUtilities.hpp> |
7 | 8 | #include <hipdnn_data_sdk/utilities/Tensor.hpp> |
8 | 9 | #include <hipdnn_test_sdk/utilities/CpuFpReferenceValidation.hpp> |
9 | 10 | #include <hipdnn_test_sdk/utilities/DynamicTolerances.hpp> |
@@ -1176,24 +1177,32 @@ struct MatmulToleranceTestCase |
1176 | 1177 | // rowValues[i] specifies the constant value for all elements in row i. |
1177 | 1178 | // This ensures different rows have different sums, exercising the max-row-sum logic |
1178 | 1179 | // in computeMatrixInfNorm. |
| 1180 | +// Supports batched (>2D) tensors via iterateAlongDimensions. |
1179 | 1181 | template <typename T> |
1180 | 1182 | hipdnn_data_sdk::utilities::Tensor<T> |
1181 | 1183 | createTensorFromRowValues(const std::vector<int64_t>& dims, |
1182 | 1184 | const std::vector<double>& rowValues) |
1183 | 1185 | { |
| 1186 | + using hipdnn_data_sdk::utilities::iterateAlongDimensions; |
| 1187 | + |
1184 | 1188 | hipdnn_data_sdk::utilities::Tensor<T> tensor(dims); |
1185 | | - auto* data = static_cast<T*>(tensor.memory().hostData()); |
1186 | 1189 |
|
1187 | | - auto rows = dims[dims.size() - 2]; |
1188 | | - auto cols = dims[dims.size() - 1]; |
| 1190 | + auto cols = dims.back(); |
| 1191 | + |
| 1192 | + // outerDims = [batch..., rows] — everything except the last dim (cols) |
| 1193 | + auto outerDims = std::vector<int64_t>(dims.begin(), dims.end() - 1); |
| 1194 | + |
| 1195 | + iterateAlongDimensions(outerDims, [&](const std::vector<int64_t>& outerIndices) { |
| 1196 | + auto row = outerIndices.back(); |
| 1197 | + auto fullIndices = outerIndices; |
| 1198 | + fullIndices.push_back(0); |
1189 | 1199 |
|
1190 | | - for(int64_t i = 0; i < rows; ++i) |
1191 | | - { |
1192 | 1200 | for(int64_t j = 0; j < cols; ++j) |
1193 | 1201 | { |
1194 | | - data[i * cols + j] = static_cast<T>(rowValues[static_cast<size_t>(i)]); |
| 1202 | + fullIndices.back() = j; |
| 1203 | + tensor.setHostValue(static_cast<T>(rowValues[static_cast<size_t>(row)]), fullIndices); |
1195 | 1204 | } |
1196 | | - } |
| 1205 | + }); |
1197 | 1206 |
|
1198 | 1207 | return tensor; |
1199 | 1208 | } |
@@ -1224,7 +1233,17 @@ std::vector<MatmulToleranceTestCase> getMatmulToleranceTestCases<TypeTriple<floa |
1224 | 1233 | {1.0, 2.0, 3.0, 4.0, 5.0, 1.0, 2.0, 3.0, 4.0, 5.0}, |
1225 | 1234 | computeGamma(10, u) * 20.0 * 10.0}, |
1226 | 1235 | // K=100: A=2x100, rows={1,2}. ||A||_inf=200, B=100x2, all 1.0. ||B||_inf=2 |
1227 | | - {{2, 100}, {100, 2}, {1.0, 2.0}, bRowValues100, computeGamma(100, u) * 200.0 * 2.0}}; |
| 1236 | + {{2, 100}, {100, 2}, {1.0, 2.0}, bRowValues100, computeGamma(100, u) * 200.0 * 2.0}, |
| 1237 | + // Batched K=3: A={2,2,3}, B={2,3,4}. Same row values as 2D K=3 case. |
| 1238 | + // Batch dim doesn't change max row sum: ||A||_inf=6, ||B||_inf=12 |
| 1239 | + {{2, 2, 3}, {2, 3, 4}, {1.0, 2.0}, {1.0, 3.0, 0.5}, computeGamma(3, u) * 6.0 * 12.0}, |
| 1240 | + // Batched K=10: A={3,2,10}, B={3,10,2}. 3 batches. |
| 1241 | + // ||A||_inf=20, ||B||_inf=10 (same as 2D K=10) |
| 1242 | + {{3, 2, 10}, |
| 1243 | + {3, 10, 2}, |
| 1244 | + {1.0, 2.0}, |
| 1245 | + {1.0, 2.0, 3.0, 4.0, 5.0, 1.0, 2.0, 3.0, 4.0, 5.0}, |
| 1246 | + computeGamma(10, u) * 20.0 * 10.0}}; |
1228 | 1247 | } |
1229 | 1248 |
|
1230 | 1249 | // Float / Double / Float (Input casting error) |
|
0 commit comments