| 890 | } |
| 891 | |
| 892 | void benchmark_spectrogram(TestUtils::TestRunner& runner, const BenchmarkConfig& config) { |
| 893 | using namespace cactus::engine; |
| 894 | |
| 895 | const size_t n_fft = 400; |
| 896 | const size_t hop_length = 160; |
| 897 | const size_t chunk_length = 30; |
| 898 | const size_t sampling_rate = 16000; |
| 899 | const size_t feature_size = 80; |
| 900 | const size_t num_frequency_bins = 1 + n_fft / 2; |
| 901 | |
| 902 | const size_t n_samples = chunk_length * sampling_rate; |
| 903 | |
| 904 | AudioProcessor audio_proc; |
| 905 | audio_proc.init_mel_filters(num_frequency_bins, feature_size, 0.0f, 8000.0f, sampling_rate); |
| 906 | |
| 907 | std::vector<float> waveform(n_samples); |
| 908 | for (size_t i = 0; i < n_samples; i++) { |
| 909 | waveform[i] = std::sin(2.0f * M_PI * 440.0f * i / sampling_rate); |
| 910 | } |
| 911 | |
| 912 | AudioProcessor::SpectrogramConfig spec_config; |
| 913 | spec_config.n_fft = n_fft; |
| 914 | spec_config.hop_length = hop_length; |
| 915 | spec_config.frame_length = n_fft; |
| 916 | spec_config.power = 2.0f; |
| 917 | spec_config.center = true; |
| 918 | spec_config.log_mel = "log10"; |
| 919 | |
| 920 | double time_ms = time_operation<float>([&]() { |
| 921 | audio_proc.compute_spectrogram(waveform, spec_config); |
| 922 | }, config.iterations); |
| 923 | |
| 924 | const size_t pad_length = n_fft / 2; |
| 925 | const size_t padded_length = n_samples + 2 * pad_length; |
| 926 | const size_t num_frames = 1 + (padded_length - n_fft) / hop_length; |
| 927 | |
| 928 | double real_time_factor = (chunk_length * 1000.0) / time_ms; |
| 929 | |
| 930 | size_t bytes_processed = (n_samples * sizeof(float)) + (feature_size * num_frames * sizeof(float)); |
| 931 | double gb_per_sec = bytes_processed / (time_ms * 1e6); |
| 932 | |
| 933 | std::ostringstream details; |
| 934 | details << std::fixed << std::setprecision(3) << time_ms << "ms, " |
| 935 | << std::setprecision(1) << real_time_factor << "x RT, " |
| 936 | << std::setprecision(2) << gb_per_sec << " GB/s"; |
| 937 | runner.log_performance( |
| 938 | "Spectrogram " + std::to_string(chunk_length) + "s (" + std::to_string(num_frames) + " frames)", |
| 939 | details.str()); |
| 940 | } |
| 941 | |
| 942 | void benchmark_gemm_f16_direct(TestUtils::TestRunner& runner, const BenchmarkConfig& config) { |
| 943 | std::vector<std::tuple<size_t, size_t, size_t>> shapes = { |
no test coverage detected