# HG changeset patch # User Chris Cannam # Date 1399390084 -3600 # Node ID 62b7be1226d5f00b7544e2955a9683536da47114 # Parent 4937f276b4462305babf737df59064d26f5383a6 OpenMP support in main EM iteration diff -r 4937f276b446 -r 62b7be1226d5 Makefile.linux --- a/Makefile.linux Tue May 06 11:31:14 2014 +0100 +++ b/Makefile.linux Tue May 06 16:28:04 2014 +0100 @@ -1,11 +1,12 @@ -CFLAGS := -Wall -O3 -ffast-math -msse -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ +CFLAGS := -Wall -O3 -ffast-math -fopenmp -msse -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ + #CFLAGS := -g -fPIC -I../vamp-plugin-sdk CXXFLAGS := $(CFLAGS) VAMPSDK_DIR := ../vamp-plugin-sdk -PLUGIN_LDFLAGS := -shared -Wl,--version-script=vamp-plugin.map +PLUGIN_LDFLAGS := -lgomp -shared -Wl,--version-script=vamp-plugin.map PLUGIN_EXT := .so diff -r 4937f276b446 -r 62b7be1226d5 src/Silvet.cpp --- a/src/Silvet.cpp Tue May 06 11:31:14 2014 +0100 +++ b/src/Silvet.cpp Tue May 06 16:28:04 2014 +0100 @@ -375,6 +375,8 @@ FeatureSet fs; + if (filtered.empty()) return fs; + for (int i = 0; i < (int)filtered.size(); ++i) { Feature f; for (int j = 0; j < processingHeight; ++j) { @@ -387,37 +389,56 @@ int iterations = 12; - for (int i = 0; i < width; ++i) { + int stride = 8; - double sum = 0.0; - for (int j = 0; j < processingHeight; ++j) { - sum += filtered[i][j]; + for (int i = 0; i < width; i += stride) { + + int chunk = stride; + if (i + chunk > width) { + chunk = width - i; } - if (sum < 1e-5) continue; + vector > pitchSubMatrix + (chunk, vector(processingNotes)); - EM em; - for (int j = 0; j < iterations; ++j) { - em.iterate(filtered[i]); +#pragma omp parallel for + for (int k = 0; k < chunk; ++k) { + + double sum = 0.0; + for (int j = 0; j < processingHeight; ++j) { + sum += filtered[i + k][j]; + } + + if (sum < 1e-5) continue; + + EM em; + for (int j = 0; j < iterations; ++j) { + em.iterate(filtered[i + k]); + } + + vector pitches = em.getPitchDistribution(); + + for (int j = 0; j < processingNotes; ++j) { + pitchSubMatrix[k][j] = pitches[j] * sum; + } } + + for (int k = 0; k < chunk; ++k) { - vector pitches = em.getPitchDistribution(); - - for (int j = 0; j < processingNotes; ++j) { - pitches[j] *= sum; - } + const vector &pitches = pitchSubMatrix[k]; - Feature f; - for (int j = 0; j < processingNotes; ++j) { - f.values.push_back(float(pitches[j])); - } - fs[m_pitchOutputNo].push_back(f); + Feature f; + for (int j = 0; j < processingNotes; ++j) { + f.values.push_back(float(pitches[j])); + } + fs[m_pitchOutputNo].push_back(f); - FeatureList noteFeatures = postProcess(pitches); + FeatureList noteFeatures = postProcess(pitches); - for (FeatureList::const_iterator fi = noteFeatures.begin(); - fi != noteFeatures.end(); ++fi) { - fs[m_notesOutputNo].push_back(*fi); + for (FeatureList::const_iterator fi = noteFeatures.begin(); + fi != noteFeatures.end(); ++fi) { + fs[m_notesOutputNo].push_back(*fi); + } } }