Skip to content

Commit 60e392d

Browse files
SSE and AVX implementations
1 parent b90b626 commit 60e392d

11 files changed

+920
-600
lines changed

modules/cmake/RuntimeSIMDLib.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
include(CheckCXXCompilerFlag)
2-
function(make_lib_simd_runtime name file)
2+
function(make_lib_simd_runtime name)
3+
set(multiValueArgs SOURCES)
4+
cmake_parse_arguments(ARG "" "" "${multiValueArgs}" ${ARGN})
5+
36
add_library(${name}_sse_or_arm STATIC)
4-
target_sources(${name}_sse_or_arm PRIVATE ${file})
7+
target_sources(${name}_sse_or_arm PRIVATE ${ARG_SOURCES})
58

69
add_library(${name}_avx STATIC)
7-
target_sources(${name}_avx PRIVATE ${file})
10+
target_sources(${name}_avx PRIVATE ${ARG_SOURCES})
811
target_compile_definitions(${name}_avx PRIVATE BYOD_COMPILING_WITH_AVX=1)
912
if(WIN32)
1013
CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)

src/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ if (NOT(${JAI_COMPILER} STREQUAL "JAI_COMPILER-NOTFOUND"))
167167
target_compile_definitions(BYOD PRIVATE BYOD_BUILDING_JAI_MODULES=1)
168168
endif()
169169

170-
# AVX/SSE files for accelerated neural nets
171-
make_lib_simd_runtime(rnn_accelerated processors/drive/neural_utils/RNNAccelerated.cpp)
172-
foreach(target IN ITEMS rnn_accelerated_sse_or_arm rnn_accelerated_avx)
170+
# AVX/SSE files for accelerated neural nets and other DSP
171+
make_lib_simd_runtime(dsp_accelerated
172+
SOURCES
173+
processors/drive/neural_utils/RNNAccelerated.cpp
174+
processors/other/poly_octave/PolyOctaveV2FilterBankImpl.cpp
175+
)
176+
foreach(target IN ITEMS dsp_accelerated_sse_or_arm dsp_accelerated_avx)
173177
target_link_libraries(${target}
174178
PRIVATE
175179
math_approx
@@ -182,17 +186,21 @@ foreach(target IN ITEMS rnn_accelerated_sse_or_arm rnn_accelerated_avx)
182186
${CMAKE_CURRENT_SOURCE_DIR}/../modules/RTNeural
183187
${CMAKE_CURRENT_SOURCE_DIR}/../modules/RTNeural/modules/xsimd/include
184188
)
185-
target_compile_definitions(${target} PRIVATE RTNEURAL_USE_XSIMD=1)
189+
target_compile_definitions(${target}
190+
PRIVATE
191+
RTNEURAL_USE_XSIMD=1
192+
_USE_MATH_DEFINES=1
193+
)
186194
set_target_properties(${target} PROPERTIES
187195
POSITION_INDEPENDENT_CODE TRUE
188196
VISIBILITY_INLINES_HIDDEN TRUE
189197
C_VISIBILITY_PRESET hidden
190198
CXX_VISIBILITY_PRESET hidden
191199
)
192200
endforeach()
193-
target_compile_definitions(rnn_accelerated_sse_or_arm PRIVATE RTNEURAL_DEFAULT_ALIGNMENT=16 RTNEURAL_NAMESPACE=RTNeural_sse_arm)
194-
target_compile_definitions(rnn_accelerated_avx PRIVATE RTNEURAL_DEFAULT_ALIGNMENT=32 RTNEURAL_NAMESPACE=RTNeural_avx)
195-
target_link_libraries(BYOD PRIVATE rnn_accelerated)
201+
target_compile_definitions(dsp_accelerated_sse_or_arm PRIVATE RTNEURAL_DEFAULT_ALIGNMENT=16 RTNEURAL_NAMESPACE=RTNeural_sse_arm)
202+
target_compile_definitions(dsp_accelerated_avx PRIVATE RTNEURAL_DEFAULT_ALIGNMENT=32 RTNEURAL_NAMESPACE=RTNeural_avx)
203+
target_link_libraries(BYOD PRIVATE dsp_accelerated)
196204

197205
# special flags for MSVC
198206
if (MSVC)

src/processors/other/poly_octave/PolyOctave.cpp

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "PolyOctave.h"
2-
#include "PolyOctaveFilterBandHelpers.h"
2+
#include "PolyOctaveV1FilterBankImpl.h"
3+
#include "PolyOctaveV2FilterBankImpl.h"
34
#include "processors/ParameterHelpers.h"
45

56
namespace PolyOctaveTags
@@ -13,11 +14,11 @@ const String v1Tag = "v1_mode";
1314

1415
PolyOctave::PolyOctave (UndoManager* um)
1516
: BaseProcessor (
16-
"Poly Octave",
17-
createParameterLayout(),
18-
BasicInputPort {},
19-
OutputPort {},
20-
um)
17+
"Poly Octave",
18+
createParameterLayout(),
19+
BasicInputPort {},
20+
OutputPort {},
21+
um)
2122
{
2223
using namespace ParameterHelpers;
2324
const auto setupGainParam = [this] (const juce::String& paramID,
@@ -42,6 +43,14 @@ PolyOctave::PolyOctave (UndoManager* um)
4243
uiOptions.powerColour = Colour { 0xffe70510 };
4344
uiOptions.info.description = "A \"polyphonic octave generator\" effect.";
4445
uiOptions.info.authors = StringArray { "Jatin Chowdhury" };
46+
47+
#if JUCE_INTEL
48+
if (juce::SystemStats::hasAVX() && juce::SystemStats::hasFMA3())
49+
{
50+
juce::Logger::writeToLog ("Using Poly Octave with AVX SIMD instructions!");
51+
use_avx = true;
52+
}
53+
#endif
4554
}
4655

4756
ParamLayout PolyOctave::createParameterLayout()
@@ -94,9 +103,9 @@ void PolyOctave::prepare (double sampleRate, int samplesPerBlock)
94103
}
95104

96105
mixOutBuffer.setSize (2, samplesPerBlock);
97-
up1OutBuffer.setSize (2, 4 * samplesPerBlock + 8); // padding for SIMD
98-
up2OutBuffer.setSize (2, 4 * samplesPerBlock + 8); // padding for SIMD
99-
down1OutBuffer.setSize (2, 4 * samplesPerBlock + 8); // padding for SIMD
106+
up1OutBuffer.setSize (2, 8 * samplesPerBlock + 32); // padding for SIMD
107+
up2OutBuffer.setSize (2, 8 * samplesPerBlock + 32); // padding for SIMD
108+
down1OutBuffer.setSize (2, samplesPerBlock);
100109
}
101110

102111
void PolyOctave::processAudio (AudioBuffer<float>& buffer)
@@ -127,21 +136,45 @@ void PolyOctave::processAudio (AudioBuffer<float>& buffer)
127136
// "up1" processing
128137
for (auto [ch, data_in, data_out] : chowdsp::buffer_iters::zip_channels (std::as_const (buffer), up1OutBuffer))
129138
{
130-
poly_octave_v2::process<1> (octaveUpFilterBank[ch],
131-
data_in.data(),
132-
data_out.data(),
133-
numSamples);
139+
#if JUCE_INTEL
140+
if (use_avx)
141+
{
142+
poly_octave_v2::process_avx<1> (octaveUpFilterBank[ch],
143+
data_in.data(),
144+
data_out.data(),
145+
numSamples);
146+
}
147+
else
148+
#endif
149+
{
150+
poly_octave_v2::process<1> (octaveUpFilterBank[ch],
151+
data_in.data(),
152+
data_out.data(),
153+
numSamples);
154+
}
134155
}
135156
upOctaveGain.process (numSamples);
136157
chowdsp::BufferMath::applyGainSmoothedBuffer (up1OutBuffer, upOctaveGain);
137158

138159
// "up2" processing
139160
for (auto [ch, data_in, data_out] : chowdsp::buffer_iters::zip_channels (std::as_const (buffer), up2OutBuffer))
140161
{
141-
poly_octave_v2::process<2> (octaveUp2FilterBank[ch],
142-
data_in.data(),
143-
data_out.data(),
144-
numSamples);
162+
#if JUCE_INTEL
163+
if (use_avx)
164+
{
165+
poly_octave_v2::process_avx<2> (octaveUp2FilterBank[ch],
166+
data_in.data(),
167+
data_out.data(),
168+
numSamples);
169+
}
170+
else
171+
#endif
172+
{
173+
poly_octave_v2::process<2> (octaveUp2FilterBank[ch],
174+
data_in.data(),
175+
data_out.data(),
176+
numSamples);
177+
}
145178
}
146179
up2OctaveGain.process (numSamples);
147180
chowdsp::BufferMath::applyGainSmoothedBuffer (up2OutBuffer, up2OctaveGain);

src/processors/other/poly_octave/PolyOctave.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

33
#include "DelayPitchShifter.h"
4-
#include "PolyOctaveFilterBankTypes.h"
4+
#include "PolyOctaveV1FilterBank.h"
5+
#include "PolyOctaveV2FilterBank.h"
56
#include "processors/BaseProcessor.h"
67

78
class PolyOctave : public BaseProcessor
@@ -61,5 +62,9 @@ class PolyOctave : public BaseProcessor
6162
juce::AudioBuffer<float> up2OutBuffer;
6263
juce::AudioBuffer<float> down1OutBuffer;
6364

65+
#if JUCE_INTEL
66+
bool use_avx = false;
67+
#endif
68+
6469
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PolyOctave)
6570
};

0 commit comments

Comments
 (0)