Compare commits

...

6 Commits

Author SHA1 Message Date
Claude Heiland-Allen cc308486c6 Merge branch 'parallel-synapse-generation' into 'main'
parallelize synapse generation using OpenMP

See merge request then-try-this/samplebrain!6
2022-09-30 12:07:08 +00:00
Dave Griffiths a2b77951ca new version links 2022-09-30 12:48:36 +01:00
Dave Griffiths 524cd58945 version bump 2022-09-30 12:02:56 +01:00
dave griffiths 43890c905e Merge branch 'packaging/flatpak' into 'main'
Add Flathub download badge to README

See merge request then-try-this/samplebrain!10
2022-09-30 10:45:19 +00:00
Owen D'Aprile 99e59a6f11
readme: add Flathub download badge 2022-09-29 17:54:25 -04:00
Claude Heiland-Allen 8aa0dee3d1 parallelize synapse generation using OpenMP
- only tested on Debian Linux with a 16-thread amd64 CPU
- Windows may need DLLs to be shipped with the EXE
- using `-fopenmp` should be made optional via qmake somehow
  (without the flag, parallelization pragmas are ignored
  and it reverts to serial operation)
- assumes `status::update()` among other code is thread-safe,
  it seems to work on my machine without issues...
2022-09-27 13:19:04 +01:00
5 changed files with 75 additions and 21 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.*~
*.o

View File

@ -46,19 +46,23 @@ As this is experimental non-commercial software (only originally
written to run on a couple of computers!) you will have to bear with
us as we gradually stabilise things based on your feedback. There
might currently be problems running it on 64bit Windows.
* **Windows**: [samplebrain_0.18.3_win.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.3_win.zip)
* **Mac (intel/m1)**: [samplebrain_0.18.3_macintel.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.3_macintel.app.zip)
(New 0.18.3 release fixes loading samples from paths longer than 255 characters)
* **Windows**: [samplebrain_0.18.2_win.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.2_win.zip)
* **Mac (intel/m1)**: [samplebrain_0.18.1_macintel.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.1_macintel.app.zip)
Thank you to [Nik Gaffney](http://fo.am) for help with the Apple builds
Mac note: As this software is not on the apple store, to run the
binary you need to tell your mac it's ok: Go to System Preferences >
Security & Privacy > General. At the bottom of the window, select
"Allow apps to be downloaded from Anywhere".
**Linux install (Ubuntu)**
Thank you to [Nik Gaffney](http://fo.am) for help with the Apple builds
### Linux
<a href='https://flathub.org/apps/details/org.thentrythis.Samplebrain'><img width='200' alt='Download on Flathub' src='https://flathub.org/assets/badges/flathub-badge-en.png'/></a>
#### Ubuntu
$ sudo add-apt-repository ppa:thentrythis/samplebrain
$ sudo apt update
$ sudo apt install samplebrain
@ -68,9 +72,12 @@ If you'd like the right font, optionally:
$ sudo apt install ttf-mscorefonts-installer
# Old/broken/spurious binaries
* **Windows**: [samplebrain_0.18.2_win.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.2_win.zip)
* **Windows**: [samplebrain_0.18.1_win.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.1_win.zip)
* **Windows**: [samplebrain_0.18_win.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18_win.zip)
* **Mac (intel/m1)**: [samplebrain_0.18.1_macintel.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18.1_macintel.app.zip)
* **Mac (intel)**: [samplebrain_0.18_macintel.zip](https://static.thentrythis.org/samplebrain/samplebrain_0.18_macintel.zip)
* **Mac (m1)**: [samplebrain_0.18_m1_v2.dmg](https://static.thentrythis.org/samplebrain/samplebrain_0.18_m1_v2.dmg)

View File

@ -16,6 +16,7 @@
#include <iostream>
#include <algorithm>
#include <atomic>
#include <sndfile.h>
#include <float.h>
#include <spiralcore/audio.h>
@ -242,10 +243,12 @@ void brain::build_synapses_thresh(search_params &params, double thresh) {
m_average_error = calc_average_diff(params)*thresh;
double err = m_average_error*thresh;
u32 brain_size = m_blocks.size();
u32 outer_index = 0;
for (auto &i : m_blocks) {
std::atomic<u32> progress{0};
#pragma omp parallel for
for (u32 outer_index = 0; outer_index < brain_size; ++outer_index) {
auto &i = m_blocks[outer_index];
u32 index = 0;
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
status::update("building synapses %d%%",(int)(progress/(float)brain_size*100));
for (auto &j : m_blocks) {
if (index!=outer_index) {
// collect connections that are under threshold in closeness
@ -256,30 +259,32 @@ void brain::build_synapses_thresh(search_params &params, double thresh) {
}
++index;
}
++outer_index;
++progress;
}
}
void brain::build_synapses_fixed(search_params &params) {
//m_average_error = calc_average_diff(params)*thresh;
u32 brain_size = m_blocks.size();
u32 outer_index = 0;
u32 num_synapses = NUM_FIXED_SYNAPSES;
if (num_synapses>=m_blocks.size()) num_synapses=m_blocks.size()-1;
// need to stop the progress updates flooding osc
u32 update_period = 100;
u32 update_tick = 0;
for (auto &i:m_blocks) {
std::atomic<u32> update_tick{0};
std::atomic<u32> progress{0};
#pragma omp parallel for
for (u32 outer_index = 0; outer_index < brain_size; ++outer_index) {
auto &i = m_blocks[outer_index];
if (update_tick>update_period) {
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
status::update("building synapses %d%%",(int)(progress/(float)brain_size*100));
update_tick=0;
}
update_tick++;
u32 index = 0;
vector<pair<u32,double>> collect;
collect.reserve(brain_size);
// collect comparisons to all other blocks
for (auto &j:m_blocks) {
@ -304,7 +309,7 @@ void brain::build_synapses_fixed(search_params &params) {
i.get_synapse().push_back(collect[n].first);
}
++outer_index;
++progress;
}
status::update("Done: %d synapses grown for %d blocks",num_synapses*brain_size,brain_size);
}

View File

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>samplebrain 0.18.1</string>
<string>samplebrain 0.18.3</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -20,6 +20,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -39,6 +40,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -55,6 +57,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -114,6 +117,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -173,6 +177,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -195,6 +200,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -221,6 +227,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -249,6 +256,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -311,6 +319,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -373,6 +382,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -435,6 +445,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -503,6 +514,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -545,6 +557,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -607,6 +620,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -690,6 +704,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -703,6 +718,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -718,6 +734,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -748,6 +765,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -778,6 +796,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -837,6 +856,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -853,6 +873,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -870,6 +891,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -886,6 +908,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -942,6 +965,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -998,6 +1022,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1081,6 +1106,7 @@
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1127,7 +1153,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<width>424</width>
<height>198</height>
</rect>
</property>
@ -1146,6 +1172,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1159,6 +1186,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1172,6 +1200,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1189,6 +1218,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1219,6 +1249,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1249,6 +1280,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1308,6 +1340,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1323,6 +1356,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1336,6 +1370,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1399,6 +1434,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1425,6 +1461,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1500,6 +1537,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@ -1513,6 +1551,7 @@
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>

View File

@ -44,9 +44,9 @@ SOURCES += app/MainWindow.cpp \
INCLUDEPATH += brain/src
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /opt/homebrew/include
LIBS += -L.. -L/usr/local/lib -L/opt/homebrew/lib -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm
LIBS += -L.. -L/usr/local/lib -L/opt/homebrew/lib -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm -fopenmp
QMAKE_CXXFLAGS += -O3 -Wall -Wno-unused -std=c++11
QMAKE_CXXFLAGS += -O3 -fopenmp -Wall -Wno-unused -std=c++11
# assets
RESOURCES = app/samplebrain.qrc