| 1342 | } |
| 1343 | |
| 1344 | bool test_stft() { |
| 1345 | const size_t N = 2, C_in = 1, L = 8, K = 4, stride = 2, num_fft_bins = 2; |
| 1346 | const size_t C_out = 2 * num_fft_bins; |
| 1347 | const size_t out_len = (L - K) / stride + 1; |
| 1348 | |
| 1349 | std::vector<__fp16> weight_data = { |
| 1350 | (__fp16) 1, (__fp16) 1, (__fp16) 1, (__fp16) 1, |
| 1351 | (__fp16) 1, (__fp16) 0, (__fp16)-1, (__fp16) 0, |
| 1352 | (__fp16) 0, (__fp16) 0, (__fp16) 0, (__fp16) 0, |
| 1353 | (__fp16) 0, (__fp16)-1, (__fp16) 0, (__fp16) 1, |
| 1354 | }; |
| 1355 | std::vector<__fp16> input_data = { |
| 1356 | (__fp16)1, (__fp16)2, (__fp16)3, (__fp16)4, (__fp16)5, (__fp16)6, (__fp16)7, (__fp16)8, |
| 1357 | (__fp16)0, (__fp16)1, (__fp16)0, (__fp16)-1, (__fp16)0, (__fp16)1, (__fp16)0, (__fp16)-1, |
| 1358 | }; |
| 1359 | |
| 1360 | TestUtils::FP16TestFixture fx; |
| 1361 | size_t inp = fx.create_input({N, C_in, L}); |
| 1362 | size_t wt = fx.create_input({C_out, C_in, K}); |
| 1363 | size_t out = fx.graph().stft(inp, wt, stride, num_fft_bins); |
| 1364 | |
| 1365 | if (fx.graph().get_output_buffer(out).shape != std::vector<size_t>{N, C_out, out_len}) return false; |
| 1366 | |
| 1367 | fx.set_input_data(inp, input_data); |
| 1368 | fx.set_input_data(wt, weight_data); |
| 1369 | fx.execute(); |
| 1370 | |
| 1371 | const __fp16* cplx = fx.get_output(out); |
| 1372 | const size_t out_bs = C_out * out_len; |
| 1373 | const float tol = 0.1f; |
| 1374 | |
| 1375 | for (size_t t = 0; t < out_len; ++t) { |
| 1376 | if (std::abs((float)cplx[1 * out_len + t] - (-2.0f)) > tol) return false; |
| 1377 | if (std::abs((float)cplx[(1 + num_fft_bins) * out_len + t] - 2.0f) > tol) return false; |
| 1378 | } |
| 1379 | |
| 1380 | const float batch1_bin1_imag[3] = {-2.0f, 2.0f, -2.0f}; |
| 1381 | for (size_t t = 0; t < out_len; ++t) { |
| 1382 | if (std::abs((float)cplx[out_bs + 1 * out_len + t] - 0.0f) > tol) return false; |
| 1383 | if (std::abs((float)cplx[out_bs + (1 + num_fft_bins) * out_len + t] - batch1_bin1_imag[t]) > tol) return false; |
| 1384 | } |
| 1385 | |
| 1386 | return true; |
| 1387 | } |
| 1388 | |
| 1389 | template<typename T> |
| 1390 | static bool run_layernorm_case( |
no test coverage detected