Skip to content

[webgpu] make shader cache and shader key correctly for all case #2669

@axinging

Description

@axinging

This issue is from PR #2670. And below comments is copied from it.

What happens:
Run case one by one (yarn test --grep=), pass. But when run several together. Some case may fail.

Example case:
Case may be failed due to cache reasons(div/Arithmetic_test.ts):
'gradient: Tensor1D with int32', // Actual != expected.
'gradient: Tensor2D', // Actual != expected.
'gradient: Tensor2D / Tensor2D w/ broadcast', // Actual != expected.

Root cause:
This problem is introduced by two reasons:
1), makeShaderKey called before the real shader generated(compileProgram and makeShader).
Which means, two different shaders may possibly share the same shader key.

2), The shader key optimization(#2451), which use
several key properties of the shader instead of the full shader source as shader key.
For most case, especially all properties are self-contained in the shader`s WebGPUProgram
file, this works. But when some properties are originated from the shader_preprocessor.ts,
two different shader may be collided with the same shader key.

Currently the fix is to disable the shader key and shader cache first.

Case passed when disable cache:
mul: strict int32 * int32; gradient;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions