Skip to content

there are issues with SIMD, lets fix them! #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ jobs:
- name: Run tox
run: tox

test-arm:
runs-on: ubuntu-22.04-arm
steps:
- uses: actions/checkout@v3
with:
lfs: true
submodules: true
- name: Initialize lfs
run: git lfs pull
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -U tox tox-gh-actions poetry
- name: Run tox
run: tox

build:
runs-on: ubuntu-20.04
steps:
Expand Down
4 changes: 2 additions & 2 deletions hvcc/generators/ir2c/static/HvSignalPhasor.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static void sPhasor_k_updatePhase(SignalPhasor *o, hv_uint32_t p) {
static void sPhasor_k_updateFrequency(SignalPhasor *o, float f, double r) {
#if HV_SIMD_AVX
o->step.f2sc = (float) (f/r);
o->inc = _mm256_set1_ps((float) (8.0f*f/r));
sPhasor_k_updatePhase(o, o->phase[0]);
o->inc = _mm256_set1_epi32((int)(f/r * 8388608.0f)); // 2^23 scaling
sPhasor_k_updatePhase(o, _mm256_castsi256_ps(o->phase)); // Adjust if needed
#elif HV_SIMD_SSE
o->step.s = (hv_int32_t) (f*(HV_PHASOR_2_32/r));
o->inc = _mm_set1_epi32(4*o->step.s);
Expand Down
17 changes: 10 additions & 7 deletions hvcc/generators/ir2c/static/HvSignalPhasor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ extern "C" {

typedef struct SignalPhasor {
#if HV_SIMD_AVX
__m256 phase; // current phase
__m256 inc; // phase increment
__m256i phase; // current phase
__m256i inc; // phase increment
#elif HV_SIMD_SSE
__m128i phase;
__m128i inc;
Expand Down Expand Up @@ -108,11 +108,14 @@ static inline void __hv_phasor_f(SignalPhasor *o, hv_bInf_t bIn, hv_bOutf_t bOut

static inline void __hv_phasor_k_f(SignalPhasor *o, hv_bOutf_t bOut) {
#if HV_SIMD_AVX
*bOut = _mm256_sub_ps(o->phase, _mm256_set1_ps(1.0f));
o->phase = _mm256_or_ps(_mm256_andnot_ps(
_mm256_set1_ps(-INFINITY),
_mm256_add_ps(o->phase, o->inc)),
_mm256_set1_ps(1.0f));
// Output current phase as float in [0,1)
*bOut = _mm256_sub_ps(_mm256_castsi256_ps(
_mm256_or_si256(_mm256_srli_epi32(o->phase, 9),
_mm256_set1_epi32(0x3F800000))),
_mm256_set1_ps(1.0f));

// Update phase as integer
o->phase = _mm256_add_epi32(o->phase, o->inc);
#elif HV_SIMD_SSE
*bOut = _mm_sub_ps(_mm_castsi128_ps(
_mm_or_si128(_mm_srli_epi32(o->phase, 9),
Expand Down
2 changes: 1 addition & 1 deletion hvcc/generators/ir2c/static/HvUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#if !(HV_SIMD_NONE || HV_SIMD_NEON || HV_SIMD_SSE || HV_SIMD_AVX)
#define HV_SIMD_NEON __ARM_NEON__
#define HV_SIMD_SSE (__SSE__ && __SSE2__ && __SSE3__ && __SSSE3__ && __SSE4_1__)
#define HV_SIMD_AVX (__AVX__ && HV_SIMD_SSE)
#define HV_SIMD_AVX (__AVX2__ && HV_SIMD_SSE)
#endif
#ifndef HV_SIMD_FMA
#define HV_SIMD_FMA __FMA__
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/base_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def compile_and_run(
str(block_size or 480),
str(num_iterations or 100)])

return wav_path
return exe_path, wav_path

def _compare_wave_output(self, out_dir, c_sources, golden_path, flag=None):
# http://stackoverflow.com/questions/10580676/comparing-two-numpy-arrays-for-equality-element-wise
Expand Down
3 changes: 3 additions & 0 deletions tests/framework/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def _compile_and_run(
source_files=source_files,
out_path=exe_path))

# run the clean command
subprocess.check_output(["make", "-C", os.path.dirname(makefile_path), "clean"])

# run the compile command
subprocess.check_output(["make", "-C", os.path.dirname(makefile_path), "-j"])

Expand Down
2 changes: 1 addition & 1 deletion tests/framework/template/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC=clang
CXX=clang++
COMMONFLAGS=-Werror -Wno-unused-function -Wno-\#warnings {{" ".join(simd_flags)}}
COMMONFLAGS=-Werror -Wno-unused-function -gdwarf-4 -Wno-\#warnings {{" ".join(simd_flags)}}
CFLAGS=-std=c11 $(COMMONFLAGS)
CXXFLAGS=-std=c++11 -fno-exceptions -fno-rtti $(COMMONFLAGS)

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, const char *argv[]) {
HeavyContextInterface *context = hv_heavy_new(48000.0);
hv_setPrintHook(context, &printHook);

float *outBuffers = (float *) malloc(numOutputChannels * BLOCK_SIZE * sizeof(float));
float *outBuffers = (float *) hv_malloc(numOutputChannels * BLOCK_SIZE * sizeof(float));

for (int i = 0; i < numIterations; ++i) {
hv_processInline(context, NULL, outBuffers, BLOCK_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, const char *argv[]) {

MidiEvent* mev;

float *outBuffers = (float *) malloc(numOutputChannels * BLOCK_SIZE * sizeof(float));
float *outBuffers = (float *) hv_malloc(numOutputChannels * BLOCK_SIZE * sizeof(float));

for (int i = 0; i < numIterations; ++i) {
for (int event=0; event < midifile[0].size(); event++) {
Expand Down
11 changes: 10 additions & 1 deletion tests/src/test_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
#include "tinywav.h"

int main(int argc, const char *argv[]) {
#if HV_SIMD_AVX
printf("AVX!\n");
#elif HV_SIMD_SSE
printf("SSE!\n");
#elif HV_SIMD_NEON
printf("NEON!\n");
#else // HV_SIMD_NONE
printf("NONE!\n");
#endif
if (argc < 5) return -1;
const char *outputPath = argv[1];
const double sampleRate = atof(argv[2]);
Expand All @@ -40,7 +49,7 @@ int main(int argc, const char *argv[]) {
(int32_t) hv_getSampleRate(context),
TW_FLOAT32, TW_INLINE, outputPath);

float *outBuffers = (float *) malloc(
float *outBuffers = (float *) hv_malloc(
hv_getNumOutputChannels(context) * blockSize * sizeof(float));

for (int i = 0; i < numIterations; ++i) {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_line(self):
def test_phasor_control(self):
self._test_signal_patch("test-phasor-control.pd")

def test_phasor_signal(self):
self._test_signal_patch("test-phasor-signal.pd")


def main():
parser = argparse.ArgumentParser(
Expand Down
Loading