MCPcopy Create free account
hub / github.com/cactus-compute/cactus / benchmark_spectrogram

Function benchmark_spectrogram

tests/test_performance.cpp:892–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

890}
891
892void 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
942void benchmark_gemm_f16_direct(TestUtils::TestRunner& runner, const BenchmarkConfig& config) {
943 std::vector<std::tuple<size_t, size_t, size_t>> shapes = {

Callers 1

test_signals_performanceFunction · 0.85

Calls 3

init_mel_filtersMethod · 0.80
compute_spectrogramMethod · 0.80
log_performanceMethod · 0.80

Tested by

no test coverage detected