Skip to content

Conversation

@Gui-Yom
Copy link
Contributor

@Gui-Yom Gui-Yom commented Mar 29, 2023

  • Rust vector backend
  • Do not use address offsets when accessing buffers (gRemoveVarAddress)
  • Zero-initialize stack arrays
  • No () for single term expressions
  • Render ForLoopInst as for ranges
  • Fix incorrect assertion in the DeclareVarInst visitor in struct_manager.hh
  • Fix inconsistent formatting in various files
  • Correctly generate slice type
  • Remove usage of libm
  • Simplify boolean conditions
  • Intermediate cast to an integer when casting a bool to a float

@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from e9dcb08 to a9b4b7c Compare May 11, 2023 16:57
@sletz
Copy link
Member

sletz commented May 16, 2023

Thanks. You'll have to check:

@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from a9b4b7c to 3a03cf5 Compare June 16, 2023 16:20
@Gui-Yom
Copy link
Contributor Author

Gui-Yom commented Jun 16, 2023

Last changes includes :

  • Put the repr(C) attribute under a feature gate (Set repr(C) on the Dsp struct to recover performance #889). Through benchmarking I can't seem to prove reprc(C) is necessarily better.
  • Complete rework of the main dsp loop by using a chunk iterator (inputs[0].chunks(vsize) & outputs[0].chunks_mut(vsize)). This eliminates the need for a last pass with the remaining samples (when sample count isn't a multiple of vsize), the Rust compiler understands chunks very well and generates optimized assembly for us.

I'll try to make impulse tests work.

@Gui-Yom Gui-Yom marked this pull request as ready for review June 16, 2023 16:35
@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from 3a03cf5 to 62319d2 Compare June 20, 2023 20:18
@sletz
Copy link
Member

sletz commented Jun 21, 2023

Thanks. Tests are OK in solar mode. But faust -lang rust -vec foo.dsp is crashing here.

@bluenote10
Copy link
Contributor

Please don't put repr(C) under a feature flag. My understanding from the internals discussion is that should always have used repr(C) to begin with. The performance regression is visible basically in all my DSPs models, and it is really significant. You could reproduce it either with the example I posted in that discussion or with the benchmarks here.

@sletz
Copy link
Member

sletz commented Jun 22, 2023

Recompiling current version, I get:

[ 42%] Building CXX object CMakeFiles/faust.dir/Users/letz/Developpements/faust/compiler/generator/instructions_compiler1.cpp.o
/Users/letz/Developpements/faust/compiler/generator/instructions.cpp:167:25: error: out-of-line definition of 'DeclareBufferIterators' does not match any declaration in 'DeclareBufferIterators'
DeclareBufferIterators::DeclareBufferIterators(const std::string& name1,
                        ^~~~~~~~~~~~~~~~~~~~~~
[ 42%] Building CXX object CMakeFiles/faust.dir/Users/letz/Developpements/faust/compiler/generator/instructions_compiler_jax.cpp.o

@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from c138bfc to a8f5a05 Compare June 22, 2023 16:11
@sletz
Copy link
Member

sletz commented Jun 26, 2023

many tests in -vec mode don't work. Is the PR still stable enough to improve the scalar mode? Or should I wait before merging?

@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from a8f5a05 to 7722881 Compare June 28, 2023 19:08
@Gui-Yom
Copy link
Contributor Author

Gui-Yom commented Jun 28, 2023

The issue with the main loop epilogue has been fixed, though the solution is not very elegant.

Failing tests with -vec -vs 4 :

  • constant
  • delays
  • pitch_shifter
  • thru_zero_flanger
  • zita_rev1

Because of an unknown error in codegen :

ASSERT : no vector name for : IN[0]
ASSERT : please report this message, the stack trace, and the failing DSP file to Faust developers (file: C:\W\PR\faust\compiler\generator\dag_instructions_compiler.cpp, line: 438, version: 2.60.4, options: -a archs/rust/architecture.rs -lang rust -i -ct 1 -es 1 -mcd 16 -double -ftz 0 -vec -lv 0 -vs 32 )
make[1]: *** [Make.rust:115: ir/rust/constant.ir] Error 1

Additional failing tests with -vec -vs 32 :

  • reverb_designer
  • spectral_level
  • virtual_analog_oscillators

Because of an incorrect struct variable access :

error[E0425]: cannot find value `fRec29_tmp` in this scope
    --> src\bin\virtual_analog_oscillators.rs:5766:54
     |
5766 |                 self.fVbargraph14 = fSlow41 + 2e+01 * F64::log10(fRec29_tmp[(i32::wrapping_add(4, ...
     |                                                                  ^^^^^^^^^^ help: you might have meant to use the available field: `self.fRec29_tmp`

I'll try to fix those asap.


Also @bluenote10, I investigated a bit about the impact of repr(C) (see some preliminary benchmark results here : https://github.com/Gui-Yom/faust-rs). While it seems to always result in a win in scalar mode, using it on the struct generated with -vec can sometimes result in a loss. The reprc(C) attribute should definitely not be under a feature flag though but instead a faust cli flag.

@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from 7722881 to badc9da Compare July 3, 2023 11:47
Gui-Yom added 7 commits July 6, 2023 18:08
- Intermediate cast to an integer when casting a bool to a float
- Correctly generate slice type
- Remove usage of libm
- Simplify boolean conditions
- Rust vector backend
- Do not use address offsets when accessing buffers (`gRemoveVarAddress`)
- Zero-initialize stack arrays
- No `()` for single term expressions
- Render ForLoopInst as for ranges
- Fix incorrect assertion in the `DeclareVarInst` visitor in `struct_manager.hh`
- Fix inconsistent formatting in various files
Reverted some of the original changes with parentheses
Use DeclareBufferIterator and IteratorForLoopInst instead, which handle mut lifetimes better.

Add rust vec tests. All tests are passing (with -vs 4), except :
- constant
- delays
- pitch_shifter
- thru_zero_flanger
- zita_rev1

Current code is failing with -vs 32 because of a problem with the main loop epilogue
@Gui-Yom Gui-Yom force-pushed the guiyom/rustvector branch from badc9da to ebf682d Compare July 6, 2023 16:09
@sletz
Copy link
Member

sletz commented Jul 17, 2023

Cleanup and merged, thanks!

@sletz sletz closed this Jul 17, 2023
@bluenote10
Copy link
Contributor

The reprc(C) attribute should definitely not be under a feature flag though but instead a faust cli flag.

The default should have been "on" though, not "off".

Defaulting to not using it is unfortunate, because one starts to depend on the non-determinism introduced by field re-ordering, which can vary with the Rust version. We should default to something that is deterministic instead, and most likely is more performant. People may not be aware that this issue (and the switch) exists and scratch their heads for a long time like I did when running into this non-deterministic behavior.

@sletz
Copy link
Member

sletz commented Jul 18, 2023

Do you mean having gReprC = true; in compiler/global.cpp ?

@bluenote10
Copy link
Contributor

Yes I think so. I haven't read the code in detail, but guess this is where the value comes from if not defined. And the command line switch would then have disabling semantics to explicitly turn it off, i.e., something like --no-reprc or --rust-allow-field-reordering or so.

@sletz
Copy link
Member

sletz commented Jul 18, 2023

@bluenote10 or @Gui-Yom can you possibly prepare a PR ?

@Gui-Yom Gui-Yom deleted the guiyom/rustvector branch July 18, 2023 19:36
@Gui-Yom Gui-Yom mentioned this pull request Jul 18, 2023
@crop2000
Copy link
Contributor

@Gui-Yom did you benchmarked the code with that uses the -vec option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants