Skip to content
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

Volume: Add volume SIMD build option #8682

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

btian1
Copy link
Contributor

@btian1 btian1 commented Jan 2, 2024

Based on #8787, this patch is adding volume build option for different HIFI levels.

@btian1 btian1 marked this pull request as ready for review January 2, 2024 06:13
src/audio/volume/Kconfig Outdated Show resolved Hide resolved
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu can you check? Not sure this is feasible given we have a hard requirement on the toolchain.

src/audio/volume/Kconfig Outdated Show resolved Hide resolved
@btian1 btian1 marked this pull request as draft January 3, 2024 06:30
@btian1 btian1 force-pushed the volume_kconfig_platform_change branch 2 times, most recently from 4e7f9c2 to d1efe48 Compare January 3, 2024 08:03
@btian1 btian1 marked this pull request as ready for review January 3, 2024 08:05
@btian1 btian1 requested a review from marc-hb as a code owner January 3, 2024 08:05
@btian1 btian1 changed the title Volume: change volume version select to platform based Volume: change volume version select based on HIFI version Jan 3, 2024
@btian1 btian1 requested review from lyakh and kv2019i January 3, 2024 08:08
src/audio/volume/Kconfig Outdated Show resolved Hide resolved
scripts/xtensa-build-zephyr.py Outdated Show resolved Hide resolved
src/audio/volume/Kconfig Outdated Show resolved Hide resolved
@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from d1efe48 to 818ecfd Compare January 4, 2024 03:17
marc-hb
marc-hb previously requested changes Jan 4, 2024
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use environment variables for build configuration: they're evil. They're evil because they're invisible/"secret" and make build reproduction very difficult - even when you're lucky and found about them.

For instance, configuring the Cadence toolchain requires environment variables and it's a constant pain and maintenace overhead, examples:

Kconfig is not always easy to use but it is very flexible and powerful and enough for this, so you don't need to change the build script. Keep all the build configuration in a SINGLE place: Kconfig.

https://docs.zephyrproject.org/latest/build/kconfig/tips.html

Keep in mind this build script is OPTIONAL, many people invoke west build directly.

We also have CONFIG overlays for fine-tuning if needed.

@andyross could you provide some Kconfig / HiFi toolchain guidance for this?

@btian1
Copy link
Contributor Author

btian1 commented Jan 4, 2024

Do not use environment variables for build configuration: they're evil. They're evil because they're invisible/"secret" and make build reproduction very difficult - even when you're lucky and found about them.

For instance, configuring the Cadence toolchain requires environment variables and it's a constant pain and maintenace overhead, examples:

Kconfig is not always easy to use but it is very flexible and powerful and enough for this, so you don't need to change the build script. Keep all the build configuration in a SINGLE place: Kconfig.

https://docs.zephyrproject.org/latest/build/kconfig/tips.html

Keep in mind this build script is OPTIONAL, many people invoke west build directly.

We also have CONFIG overlays for fine-tuning if needed.

@andyross could you provide some Kconfig / HiFi toolchain guidance for this?

Thanks, your point is also my vision to do this, however, I just can't find a better way to implement this, it is not easy to distinguish hifi3 and hifi4 in Kconfig, please share if you have better ideas.

I also noticed set_xtensa_params.sh for maintain, this is a patch work, also need add a new variable to do this.

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 4, 2024

it is not easy to distinguish hifi3 and hifi4 in Kconfig,

I see you have used choice in 818ecfd90b2d6c9b2, why is that not enough?
What's wrong with sof/scripts/xtensa-build-zephyr.py mtl -C=-DCONFIG_VOLUME_HIFI3 ?

Also, what is the purpose of overriding the toolchain default with Kconfig? Who's going to use this? Why is something like SRC_AUTOARCH in e8afa16 not enough?

this change makes volume version select based on

We see what this PR does but we don't see what problem(s) it tries to solve.

@btian1
Copy link
Contributor Author

btian1 commented Jan 4, 2024

it is not easy to distinguish hifi3 and hifi4 in Kconfig,

I see you have used choice in 818ecfd90b2d6c9b2, why is that not enough? What's wrong with sof/scripts/xtensa-build-zephyr.py mtl -C=-DCONFIG_VOLUME_HIFI3 ?
because we need set default as its origin toolchain HIFI version.
If add -D, current CI build need change, because default would be generic, I am not sure this is the right way.

Also, what is the purpose of overriding the toolchain default with Kconfig? Who's going to use this? Why is something like SRC_AUTOARCH in e8afa16 not enough?
its not overriding, it gives developer an option to select which version you want to have a try, sometimes, can be used for quick rootcause a bug that only happened in generic or HIFI version.

this change makes volume version select based on

We see what this PR does but we don't see what problem(s) it tries to solve.
it give developer flexbility to select which HIFI version for one module.

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 4, 2024

it gives developer an option to select which version you want to have a try, sometimes, can be used for quick rootcause a bug that only happened in generic or HIFI version.

If this is only for developers to debug then even Kconfig is not required because they can just change the source that they are already editing anyway. See the comment at the top of src/audio/src_config.h (commit e8afa16)

Also, why do it only for VOLUME? What about other code?

If add -D, current CI build need change, because default would be generic, I am not sure this is the right way.

I don't understand this sorry. How is CI related to this?

@kv2019i
Copy link
Collaborator

kv2019i commented Jan 4, 2024

@btian1 @marc-hb I see two ways to add Kconfig support:

  1. add a "VOLUME_HIGHEST_OPT_LEVEL" Kconfig option that is the default and implementaion is the current one (use highest optimization level the toolchain supports for this target)

  2. move generic build to an overlay and require builds (e.g. in github CI flows) to use the overlay to pick up generic implemenations for all componets. the default build would use hifi3/4 for Intel targets, but you could only build the default configuration with xtensa toolchain

... I'd personally prefer (1). That keeps the current logic, but allows to explicitly control optimization with Kconfig if user wants to.

@lgirdwood
Copy link
Member

Kconfig needs to be able to override tooling (for downgrade) and rtos specific headers (like core-isa.h) to select the SIMD version based on ARCH.

The intention is that Kconfig will select the SIMD config (i.e. be the single source of all configuration) for each component rather than XCC/core-isa.h (today) the extra benefit is we can downgrade SIMD (per module) when performance or logic bugs are detected as the SIMD code changes are large in many files.

@btian1
Copy link
Contributor Author

btian1 commented Jan 23, 2024

@marc-hb @lgirdwood @kv2019i

zephyrproject-rtos/zephyr@512407e

From above link information, at least, NXP still have dependency on IPC3 xtos build, which means we still can't fully depend on
zephyr to pass HIFIn information to module, maybe next year is a suitable time to remove core-isa dependency.

So we can take this PR as first step, i.e:

  1. Still use core-isa as first choice for HIFI version.
  2. Add a Choice( in this patch) for each module to make each module are configurable first.
  3. In 2025, after all users are switched to zephyr based SOF, remove core-isa dependency with #67513.

Please share your comments on this, above is my rough thought, if you are ok with this, I will address some review comments and update PR.

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 24, 2024

Still use core-isa as first choice for HIFI version.

This is the simplest way to make incremental progress and this is what I did in my very first attempt: #8720 . Dropping the #include core-isa.h is not required to achieve per-component Kconfigurability, that's a different requirement which clashes with XTOS platforms.

@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from 1984da2 to a2b5b46 Compare January 24, 2024 07:16
@btian1 btian1 changed the title Volume: Add volume performance build option Volume: Add volume simdbuild option Jan 24, 2024
@btian1
Copy link
Contributor Author

btian1 commented Jan 24, 2024

Still use core-isa as first choice for HIFI version.

This is the simplest way to make incremental progress and this is what I did in my very first attempt: #8720 . Dropping the #include core-isa.h is not required to achieve per-component Kconfigurability, that's a different requirement which clashes with XTOS platforms.

ok, we can use two step to meet orginal thought,

  1. use current PR to add build option for each module.
  2. once all SOF users are switched to zephyr, remove core-isa dependency( may need wait for one year, as Daniel mentioned)

@btian1 btian1 changed the title Volume: Add volume simdbuild option Volume: Add volume SIMD build option Jan 24, 2024
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I assume @marc-hb also aligned ?

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, a few notes/questions inline, please check

src/audio/volume/Kconfig.simd Show resolved Hide resolved
src/audio/volume/Kconfig.simd Outdated Show resolved Hide resolved
src/audio/volume/Kconfig.simd Outdated Show resolved Hide resolved
@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from a2b5b46 to 130f26a Compare January 25, 2024 03:02
#else
# define VOLUME_GENERIC
# define CONFIG_VOLUME_GENERIC 1
Copy link
Collaborator

@marc-hb marc-hb Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to keep duplicating this #ifdef logic in every single C file. I just submitted #8787 which is equivalent to the current 130f26a state of this PR but without this duplication in every C file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #8787 got approved, I am ok with this, however, my personal opinion is: this will eventually be removed, no need to add extra logic for this(may bring other bugs), although current code looks a little duplicated.

@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from 130f26a to 5c7db5b Compare January 29, 2024 02:39
@btian1 btian1 requested a review from kv2019i January 29, 2024 03:27
@@ -587,7 +587,7 @@ static int volume_process(struct processing_module *mod,
cd->peak_cnt = 0;
peak_vol_update(cd);
memset(cd->peak_regs.peak_meter, 0, sizeof(cd->peak_regs.peak_meter));
#ifdef VOLUME_HIFI4
#if CONFIG_VOLUME_HIFI4
Copy link
Collaborator

@marc-hb marc-hb Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not this?

Suggested change
#if CONFIG_VOLUME_HIFI4
#if SOF_USE_HIFI(4, VOLUME) || SOF_USE_HIFI(5, VOLUME)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, just too much comments and I don't want to use a new PR to submit this patch, let's go for merge.

@marc-hb marc-hb dismissed their stale review January 29, 2024 03:52

stale review

@btian1 btian1 requested a review from marc-hb January 29, 2024 05:01
@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from 5c7db5b to 2a93445 Compare January 29, 2024 13:10
src/audio/volume/volume_hifi4.c Show resolved Hide resolved
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain the CONFIG_VOLUME_HIFI4 oddity. I spent a couple more minutes looking at it and I couldn't explain it.

Maybe it's correct for some reason but it needs at least an explanation.

@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from 2a93445 to 7a4f168 Compare January 30, 2024 01:44
Copy link
Contributor Author

@btian1 btian1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kv2019i @marc-hb , it is ready for merge now.

src/audio/volume/Kconfig.simd Show resolved Hide resolved
src/audio/volume/Kconfig.simd Outdated Show resolved Hide resolved
#else
# define VOLUME_GENERIC
# define CONFIG_VOLUME_GENERIC 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #8787 got approved, I am ok with this, however, my personal opinion is: this will eventually be removed, no need to add extra logic for this(may bring other bugs), although current code looks a little duplicated.

src/audio/volume/Kconfig.simd Show resolved Hide resolved
src/audio/volume/volume_hifi4.c Outdated Show resolved Hide resolved
@@ -587,7 +587,7 @@ static int volume_process(struct processing_module *mod,
cd->peak_cnt = 0;
peak_vol_update(cd);
memset(cd->peak_regs.peak_meter, 0, sizeof(cd->peak_regs.peak_meter));
#ifdef VOLUME_HIFI4
#if CONFIG_VOLUME_HIFI4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, just too much comments and I don't want to use a new PR to submit this patch, let's go for merge.

src/audio/volume/volume_hifi4.c Show resolved Hide resolved
@andrula-song
Copy link
Contributor

please modify the alignment set in volume_set_alignment as well to fit your new style, thanks.

@btian1 btian1 force-pushed the volume_kconfig_platform_change branch from 7a4f168 to 36e2357 Compare January 30, 2024 02:36
With common header file change merged, this patch is using the
new HIFI definition to build different volume modules based on toolchain.

Signed-off-by: Baofeng Tian <[email protected]>
@marc-hb marc-hb dismissed their stale review January 30, 2024 07:33

resolved

@kv2019i
Copy link
Collaborator

kv2019i commented Jan 30, 2024

One pause-resume fail in https://sof-ci.01.org/sofpr/PR8682/build2430/devicetest/index.html , but does not seem related to this PR. Rest of CI passing, so proceeding with merge.

@kv2019i kv2019i merged commit 2752cdf into thesofproject:main Jan 30, 2024
38 of 44 checks passed
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.

7 participants