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

Ternary operator on AMD vk drivers. #1284

Open
stolk opened this issue Dec 31, 2023 · 3 comments
Open

Ternary operator on AMD vk drivers. #1284

stolk opened this issue Dec 31, 2023 · 3 comments

Comments

@stolk
Copy link

stolk commented Dec 31, 2023

So, I am not sure if this is a bug in AMD drivers, or in clspv, but when I use this OpenCL construct:

const int8_t face = fac[rindex];
....
const int8_t bounced = face >= 0 ? 1 : 0;
...
const half ox = bounced ? hitx[rindex] : li[12];

then the values of ox can become 0 when they should not be, but only on AMD.

On nvidia GPU, Intel GPU, the code is fine.

The code is also fine when executed as OpenCL kernel.

But it goes awry when going through clspv on AMD GPU as vulkan spirv kernel.

I made sure to enable extensions:

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES,

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES,

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES,

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES,

The code also works if I replace the tertiary operator with a mix instruction:

const value_t ox = mix(li[12], hitx[rindex], bounced);

I tried diffing the spirv disassembly output, but the deltas are somehow very large.

I tried different transpiler options, to no avail. Last used:

CLSPVFLAGS = -g -O0 --fp16 --int8 --spv-version=1.5 --cl-native-math -DWGSZ=$(WGSZ)

Happens on other optimization levels too, and happens without native-math too. Also on different spv verions.

Observed on 3 different Radeon RX models.

Vulkan validation layer shows no issues.

OS: Ubuntu 23.04

@stolk stolk changed the title Tertiary operator on AMD vk drivers. Ternary operator on AMD vk drivers. Dec 31, 2023
@alan-baker
Copy link
Collaborator

Can you try with --decorate-nonuniform and see if that fixes your problem? You'll need to enable the descriptor indexing features on the Vulkan side too (specifically shaderStorageBufferArrayNonUniformIndexing assuming these end up in storage buffers).

@stolk
Copy link
Author

stolk commented Jan 3, 2024

Yep! With that flag, the issue goes away.

Do you know if this is caused by the amd driver, or by clspv?

@alan-baker
Copy link
Collaborator

It is a clspv issue, but since there might be a performance cost (and most cases don't need this) we don't enable it by default. Vulkan requires that non-uniform descriptor selection be annotated with as such.

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

No branches or pull requests

2 participants