Skip to content

Commit

Permalink
Add support for AbstractInts as inputs (#3306)
Browse files Browse the repository at this point in the history
This PR adds in abstract ints to the Scalar type system, and wires up
being able to write them as inputs as literals in shaders. Since they
are abstract values they will never be supported as buffer
inputs. Returning the values via buffers will be handled in a seperate
PR.

I have implemented the tests for AbstractInt -> i32 & u32 conversion
to confirm the implementation operates as expected.

There is a substantial number of changes related to the fact that the
existing code assumes all numerics are `number`s, but AbstractInts
need to be represented as BigInts.

I have also cleaned up a couple of places related to the AbstractFloat
implementation where there wasn't full testing coverage, etc.

Issue #3302
  • Loading branch information
zoddicus authored Jan 25, 2024
1 parent 66ef471 commit 0e38887
Show file tree
Hide file tree
Showing 30 changed files with 550 additions and 260 deletions.
1 change: 1 addition & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ const TypedArrayBufferViewInstances = [
new Float16Array(),
new Float32Array(),
new Float64Array(),
new BigInt64Array(),
] as const;

export type TypedArrayBufferView = (typeof TypedArrayBufferViewInstances)[number];
Expand Down
209 changes: 105 additions & 104 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,106 +1,107 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "2c5e7574",
"webgpu/shader/execution/binary/af_logical.bin": "2885252a",
"webgpu/shader/execution/binary/af_division.bin": "de2c92cc",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "3c01149a",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "bd4616a3",
"webgpu/shader/execution/binary/af_multiplication.bin": "30337a92",
"webgpu/shader/execution/binary/af_remainder.bin": "b974c5d4",
"webgpu/shader/execution/binary/af_subtraction.bin": "e532bbbe",
"webgpu/shader/execution/binary/f16_addition.bin": "36beac4c",
"webgpu/shader/execution/binary/f16_logical.bin": "48b5847",
"webgpu/shader/execution/binary/f16_division.bin": "5377812e",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "2f778220",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "8f7db49c",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "ccc6898f",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "66ab0554",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "c570c9d1",
"webgpu/shader/execution/binary/f16_multiplication.bin": "eb1180d7",
"webgpu/shader/execution/binary/f16_remainder.bin": "85b6f6f2",
"webgpu/shader/execution/binary/f16_subtraction.bin": "17cb0c61",
"webgpu/shader/execution/binary/f32_addition.bin": "7ed11615",
"webgpu/shader/execution/binary/f32_logical.bin": "49eb7a68",
"webgpu/shader/execution/binary/f32_division.bin": "73dbed8a",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "72980509",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "58aa220c",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "f8b0e4a8",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "7878810e",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "58d640f4",
"webgpu/shader/execution/binary/f32_multiplication.bin": "16e09d10",
"webgpu/shader/execution/binary/f32_remainder.bin": "a6c6a8fa",
"webgpu/shader/execution/binary/f32_subtraction.bin": "6fa482ff",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "9428fcd7",
"webgpu/shader/execution/binary/i32_comparison.bin": "11d07528",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "243cb8a1",
"webgpu/shader/execution/binary/u32_comparison.bin": "272ae0fa",
"webgpu/shader/execution/abs.bin": "aa2f77b4",
"webgpu/shader/execution/acos.bin": "223ed115",
"webgpu/shader/execution/acosh.bin": "e2b339c8",
"webgpu/shader/execution/asin.bin": "b09c87",
"webgpu/shader/execution/asinh.bin": "a269a791",
"webgpu/shader/execution/atan.bin": "72435ef",
"webgpu/shader/execution/atan2.bin": "c766ee54",
"webgpu/shader/execution/atanh.bin": "ca85d013",
"webgpu/shader/execution/bitcast.bin": "f1dfaef7",
"webgpu/shader/execution/ceil.bin": "956505f5",
"webgpu/shader/execution/clamp.bin": "f411b304",
"webgpu/shader/execution/cos.bin": "40a28b62",
"webgpu/shader/execution/cosh.bin": "ad54c793",
"webgpu/shader/execution/cross.bin": "520c3390",
"webgpu/shader/execution/degrees.bin": "c847ea4f",
"webgpu/shader/execution/determinant.bin": "c601a65d",
"webgpu/shader/execution/distance.bin": "466b0741",
"webgpu/shader/execution/dot.bin": "8150a481",
"webgpu/shader/execution/exp.bin": "47940592",
"webgpu/shader/execution/exp2.bin": "ee99106",
"webgpu/shader/execution/faceForward.bin": "71fd946c",
"webgpu/shader/execution/floor.bin": "dc1e0116",
"webgpu/shader/execution/fma.bin": "f8a5fcd0",
"webgpu/shader/execution/fract.bin": "d64b4648",
"webgpu/shader/execution/frexp.bin": "fcbd25a7",
"webgpu/shader/execution/inverseSqrt.bin": "b9516be3",
"webgpu/shader/execution/ldexp.bin": "cea8acfb",
"webgpu/shader/execution/length.bin": "f2c1b5d4",
"webgpu/shader/execution/log.bin": "50f2df6",
"webgpu/shader/execution/log2.bin": "3fed9ca1",
"webgpu/shader/execution/max.bin": "c687421f",
"webgpu/shader/execution/min.bin": "93d6f7dd",
"webgpu/shader/execution/mix.bin": "90fc51a1",
"webgpu/shader/execution/modf.bin": "ffa60832",
"webgpu/shader/execution/normalize.bin": "edab0498",
"webgpu/shader/execution/pack2x16float.bin": "157b9079",
"webgpu/shader/execution/pow.bin": "7013e734",
"webgpu/shader/execution/quantizeToF16.bin": "d1b7619f",
"webgpu/shader/execution/radians.bin": "35d5c4a4",
"webgpu/shader/execution/reflect.bin": "8c78147",
"webgpu/shader/execution/refract.bin": "f6797744",
"webgpu/shader/execution/round.bin": "87053dcd",
"webgpu/shader/execution/saturate.bin": "a6478965",
"webgpu/shader/execution/sign.bin": "6764de33",
"webgpu/shader/execution/sin.bin": "2a231111",
"webgpu/shader/execution/sinh.bin": "f1aa29f4",
"webgpu/shader/execution/smoothstep.bin": "446216ba",
"webgpu/shader/execution/sqrt.bin": "8686bbeb",
"webgpu/shader/execution/step.bin": "c7f41980",
"webgpu/shader/execution/tan.bin": "3839e7f0",
"webgpu/shader/execution/tanh.bin": "e98e67a7",
"webgpu/shader/execution/transpose.bin": "4e422cd2",
"webgpu/shader/execution/trunc.bin": "abc8cd37",
"webgpu/shader/execution/unpack2x16float.bin": "9d44b030",
"webgpu/shader/execution/unpack2x16snorm.bin": "2c62ccb1",
"webgpu/shader/execution/unpack2x16unorm.bin": "953c2189",
"webgpu/shader/execution/unpack4x8snorm.bin": "d7afd331",
"webgpu/shader/execution/unpack4x8unorm.bin": "1de18638",
"webgpu/shader/execution/unary/af_arithmetic.bin": "d81659dd",
"webgpu/shader/execution/unary/af_assignment.bin": "3c291894",
"webgpu/shader/execution/unary/bool_conversion.bin": "a772b7a8",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "42a82294",
"webgpu/shader/execution/unary/f16_conversion.bin": "187f2a7d",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "1e8f5ba5",
"webgpu/shader/execution/unary/f32_conversion.bin": "44626171",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "af2d5073",
"webgpu/shader/execution/unary/i32_complement.bin": "d2454830",
"webgpu/shader/execution/unary/i32_conversion.bin": "fff42cc4",
"webgpu/shader/execution/unary/u32_complement.bin": "f999c865",
"webgpu/shader/execution/unary/u32_conversion.bin": "a2f40c7e"
"webgpu/shader/execution/binary/af_addition.bin": "eba1476",
"webgpu/shader/execution/binary/af_logical.bin": "2fdff104",
"webgpu/shader/execution/binary/af_division.bin": "df548fe",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "33fce0f",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "d91874cd",
"webgpu/shader/execution/binary/af_multiplication.bin": "befd840b",
"webgpu/shader/execution/binary/af_remainder.bin": "3e618e69",
"webgpu/shader/execution/binary/af_subtraction.bin": "14237c9b",
"webgpu/shader/execution/binary/f16_addition.bin": "331cde43",
"webgpu/shader/execution/binary/f16_logical.bin": "2495b3b8",
"webgpu/shader/execution/binary/f16_division.bin": "11c2c421",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "49514138",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "2016658",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "c76b299d",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "4bec10fa",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "6192b162",
"webgpu/shader/execution/binary/f16_multiplication.bin": "a0d0527b",
"webgpu/shader/execution/binary/f16_remainder.bin": "b9839e66",
"webgpu/shader/execution/binary/f16_subtraction.bin": "ebf7f0f4",
"webgpu/shader/execution/binary/f32_addition.bin": "2f161871",
"webgpu/shader/execution/binary/f32_logical.bin": "b792bcce",
"webgpu/shader/execution/binary/f32_division.bin": "89cf19e6",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "a4fd125f",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "e73d99e2",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "81f12724",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "dfabd8ab",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "3cbcfe99",
"webgpu/shader/execution/binary/f32_multiplication.bin": "82ce5ae",
"webgpu/shader/execution/binary/f32_remainder.bin": "7eea3091",
"webgpu/shader/execution/binary/f32_subtraction.bin": "c4518267",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "35db562d",
"webgpu/shader/execution/binary/i32_comparison.bin": "3aea1709",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "309aa9e3",
"webgpu/shader/execution/binary/u32_comparison.bin": "74afab9",
"webgpu/shader/execution/abs.bin": "cfde2529",
"webgpu/shader/execution/acos.bin": "eb561980",
"webgpu/shader/execution/acosh.bin": "e4f1c0f0",
"webgpu/shader/execution/asin.bin": "a2fa8235",
"webgpu/shader/execution/asinh.bin": "96567f9d",
"webgpu/shader/execution/atan.bin": "6c853cbd",
"webgpu/shader/execution/atan2.bin": "82c97086",
"webgpu/shader/execution/atanh.bin": "5e60f704",
"webgpu/shader/execution/bitcast.bin": "87c146d5",
"webgpu/shader/execution/ceil.bin": "21383e91",
"webgpu/shader/execution/clamp.bin": "1c96b539",
"webgpu/shader/execution/cos.bin": "956b7a3d",
"webgpu/shader/execution/cosh.bin": "f2bb8e16",
"webgpu/shader/execution/cross.bin": "2a5f9027",
"webgpu/shader/execution/degrees.bin": "46294f0d",
"webgpu/shader/execution/determinant.bin": "23aa0a3e",
"webgpu/shader/execution/distance.bin": "2b461512",
"webgpu/shader/execution/dot.bin": "e38ea290",
"webgpu/shader/execution/exp.bin": "4455696f",
"webgpu/shader/execution/exp2.bin": "bb006599",
"webgpu/shader/execution/faceForward.bin": "2bbbb0bd",
"webgpu/shader/execution/floor.bin": "9b0d6e07",
"webgpu/shader/execution/fma.bin": "33bcd52",
"webgpu/shader/execution/fract.bin": "2ab6d19f",
"webgpu/shader/execution/frexp.bin": "8dce4a7a",
"webgpu/shader/execution/inverseSqrt.bin": "7c799f30",
"webgpu/shader/execution/ldexp.bin": "ff53724f",
"webgpu/shader/execution/length.bin": "348b0fe5",
"webgpu/shader/execution/log.bin": "d4537242",
"webgpu/shader/execution/log2.bin": "c4010158",
"webgpu/shader/execution/max.bin": "c72c2f27",
"webgpu/shader/execution/min.bin": "da1cc040",
"webgpu/shader/execution/mix.bin": "7124ff44",
"webgpu/shader/execution/modf.bin": "cce9a8fb",
"webgpu/shader/execution/normalize.bin": "2aa96726",
"webgpu/shader/execution/pack2x16float.bin": "3d47cf41",
"webgpu/shader/execution/pow.bin": "ced94069",
"webgpu/shader/execution/quantizeToF16.bin": "4d558863",
"webgpu/shader/execution/radians.bin": "539694e5",
"webgpu/shader/execution/reflect.bin": "fc996f65",
"webgpu/shader/execution/refract.bin": "d5c12e24",
"webgpu/shader/execution/round.bin": "8153f0e3",
"webgpu/shader/execution/saturate.bin": "35cfdcb0",
"webgpu/shader/execution/sign.bin": "b845eb5f",
"webgpu/shader/execution/sin.bin": "ca416640",
"webgpu/shader/execution/sinh.bin": "48a248a2",
"webgpu/shader/execution/smoothstep.bin": "a4262b99",
"webgpu/shader/execution/sqrt.bin": "ecb66d2f",
"webgpu/shader/execution/step.bin": "441a1ff0",
"webgpu/shader/execution/tan.bin": "139b44d2",
"webgpu/shader/execution/tanh.bin": "6f034864",
"webgpu/shader/execution/transpose.bin": "ce29e902",
"webgpu/shader/execution/trunc.bin": "78326103",
"webgpu/shader/execution/unpack2x16float.bin": "7d7f403e",
"webgpu/shader/execution/unpack2x16snorm.bin": "3cb1dd10",
"webgpu/shader/execution/unpack2x16unorm.bin": "e393809e",
"webgpu/shader/execution/unpack4x8snorm.bin": "3c7c876",
"webgpu/shader/execution/unpack4x8unorm.bin": "3cf4adca",
"webgpu/shader/execution/unary/af_arithmetic.bin": "36ca2efd",
"webgpu/shader/execution/unary/af_assignment.bin": "5952912c",
"webgpu/shader/execution/unary/bool_conversion.bin": "70142326",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "dccd3bb1",
"webgpu/shader/execution/unary/f16_conversion.bin": "b66d4a94",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "19370c80",
"webgpu/shader/execution/unary/f32_conversion.bin": "1c842ed",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "7e5dfb12",
"webgpu/shader/execution/unary/i32_complement.bin": "f49af0fa",
"webgpu/shader/execution/unary/i32_conversion.bin": "c7859be0",
"webgpu/shader/execution/unary/u32_complement.bin": "e32b513d",
"webgpu/shader/execution/unary/u32_conversion.bin": "ea2e6707",
"webgpu/shader/execution/unary/ai_assignment.bin": "cb143977"
}
Binary file modified src/resources/cache/webgpu/shader/execution/bitcast.bin
Binary file not shown.
Binary file not shown.
69 changes: 69 additions & 0 deletions src/unittests/serialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from '../webgpu/util/compare.js';
import { kValue } from '../webgpu/util/constants.js';
import {
abstractFloat,
abstractInt,
bool,
deserializeValue,
f16,
Expand Down Expand Up @@ -61,6 +63,18 @@ g.test('value').fn(t => {
u8(kValue.u8.max - 1),
u8(kValue.u8.max - 0),

abstractInt(kValue.i64.negative.min),
abstractInt(kValue.i64.negative.min + 1n),
abstractInt(kValue.i64.negative.min + 2n),
abstractInt(kValue.i64.negative.max - 2n),
abstractInt(kValue.i64.negative.max - 1n),
abstractInt(kValue.i64.positive.min),
abstractInt(kValue.i64.positive.min + 1n),
abstractInt(kValue.i64.positive.min + 2n),
abstractInt(kValue.i64.positive.max - 2n),
abstractInt(kValue.i64.positive.max - 1n),
abstractInt(kValue.i64.positive.max),

i32(kValue.i32.negative.min + 0),
i32(kValue.i32.negative.min + 1),
i32(kValue.i32.negative.min + 2),
Expand Down Expand Up @@ -97,6 +111,21 @@ g.test('value').fn(t => {
i8(kValue.i8.positive.max - 1),
i8(kValue.i8.positive.max - 0),

abstractFloat(0),
abstractFloat(-0),
abstractFloat(1),
abstractFloat(-1),
abstractFloat(0.5),
abstractFloat(-0.5),
abstractFloat(kValue.f64.positive.max),
abstractFloat(kValue.f64.positive.min),
abstractFloat(kValue.f64.positive.subnormal.max),
abstractFloat(kValue.f64.positive.subnormal.min),
abstractFloat(kValue.f64.negative.subnormal.max),
abstractFloat(kValue.f64.negative.subnormal.min),
abstractFloat(kValue.f64.positive.infinity),
abstractFloat(kValue.f64.negative.infinity),

f32(0),
f32(-0),
f32(1),
Expand Down Expand Up @@ -134,6 +163,13 @@ g.test('value').fn(t => {
vec3(u32(1), u32(2), u32(3)),
vec4(bool(false), bool(true), bool(false), bool(true)),

toMatrix(
[
[0.0, 1.0],
[2.0, 3.0],
],
abstractFloat
),
toMatrix(
[
[0.0, 1.0],
Expand All @@ -148,6 +184,13 @@ g.test('value').fn(t => {
],
f16
),
toMatrix(
[
[0.0, 1.0, 2.0, 3.0],
[4.0, 5.0, 6.0, 7.0],
],
abstractFloat
),
toMatrix(
[
[0.0, 1.0, 2.0, 3.0],
Expand All @@ -163,6 +206,14 @@ g.test('value').fn(t => {
],
f16
),
toMatrix(
[
[0.0, 1.0, 2.0],
[3.0, 4.0, 5.0],
[6.0, 7.0, 8.0],
],
abstractFloat
),
toMatrix(
[
[0.0, 1.0, 2.0],
Expand All @@ -179,6 +230,15 @@ g.test('value').fn(t => {
],
f16
),
toMatrix(
[
[0.0, 1.0],
[2.0, 3.0],
[4.0, 5.0],
[6.0, 7.0],
],
abstractFloat
),
toMatrix(
[
[0.0, 1.0],
Expand All @@ -197,6 +257,15 @@ g.test('value').fn(t => {
],
f16
),
toMatrix(
[
[0.0, 1.0, 2.0, 3.0],
[4.0, 5.0, 6.0, 7.0],
[8.0, 9.0, 10.0, 11.0],
[12.0, 13.0, 14.0, 15.0],
],
abstractFloat
),
toMatrix(
[
[0.0, 1.0, 2.0, 3.0],
Expand Down
3 changes: 2 additions & 1 deletion src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
slice = 0,
layout,
generateWarningOnly = false,
checkElementsBetweenFn = (act, [a, b]) => checkElementsBetween(act, [i => a[i], i => b[i]]),
checkElementsBetweenFn = (act, [a, b]) =>
checkElementsBetween(act, [i => a[i] as number, i => b[i] as number]),
}: {
exp: [TypedArrayBufferView, TypedArrayBufferView];
slice?: number;
Expand Down
3 changes: 3 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,9 @@
"webgpu:shader,execution,expression,unary,af_assignment:abstract:*": { "subcaseMS": 788.400 },
"webgpu:shader,execution,expression,unary,af_assignment:f16:*": { "subcaseMS": 1.000 },
"webgpu:shader,execution,expression,unary,af_assignment:f32:*": { "subcaseMS": 42.000 },
"webgpu:shader,execution,expression,unary,ai_assignment:abstract:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,unary,ai_assignment:i32:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,unary,ai_assignment:u32:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,unary,bool_conversion:bool:*": { "subcaseMS": 8.357 },
"webgpu:shader,execution,expression,unary,bool_conversion:f16:*": { "subcaseMS": 44.794 },
"webgpu:shader,execution,expression,unary,bool_conversion:f32:*": { "subcaseMS": 41.276 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn atomicAdd(atomic_ptr: ptr<AS, atomic<T>, read_write>, v: T) -> T
u
.combine('workgroupSize', workgroupSizes)
.combine('dispatchSize', dispatchSizes)
.combine('scalarType', ['u32', 'i32'])
.combine('scalarType', ['u32', 'i32'] as const)
)
.fn(t => {
const numInvocations = t.params.workgroupSize * t.params.dispatchSize;
Expand Down Expand Up @@ -72,7 +72,7 @@ fn atomicAdd(atomic_ptr: ptr<AS, atomic<T>, read_write>, v: T) -> T
u
.combine('workgroupSize', workgroupSizes)
.combine('dispatchSize', dispatchSizes)
.combine('scalarType', ['u32', 'i32'])
.combine('scalarType', ['u32', 'i32'] as const)
)
.fn(t => {
// Allocate one extra element to ensure it doesn't get modified
Expand Down
Loading

0 comments on commit 0e38887

Please sign in to comment.