Skip to content

Commit

Permalink
Add comprehensive memory model tests (#1330)
Browse files Browse the repository at this point in the history
* Add comprehensive coherence tests

* Add comprehensive barrier tests

* Add all weak memory tests

* Update runtimes

* Remove unneeded params

* Revert package-lock

* Add a few more rmw variants
  • Loading branch information
reeselevine authored May 11, 2022
1 parent d7d7544 commit aafa50d
Show file tree
Hide file tree
Showing 5 changed files with 912 additions and 46 deletions.
4 changes: 1 addition & 3 deletions src/webgpu/shader/execution/memory_model/atomicity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const memoryModelTestParams: MemoryModelTestParams = {
permuteSecond: 419,
memStride: 4,
aliasedMemory: false,
numMemLocations: 1,
numReadOutputs: 1,
numBehaviors: 4,
};

Expand Down Expand Up @@ -100,5 +98,5 @@ g.test('atomicity')
testShader,
resultShader
);
await memModelTester.run(20, 3);
await memModelTester.run(10, 3);
});
117 changes: 114 additions & 3 deletions src/webgpu/shader/execution/memory_model/barrier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const memoryModelTestParams: MemoryModelTestParams = {
permuteSecond: 419,
memStride: 4,
aliasedMemory: false,
numMemLocations: 1,
numReadOutputs: 1,
numBehaviors: 2,
};

Expand Down Expand Up @@ -96,5 +94,118 @@ g.test('workgroup_barrier_store_load')
testShader,
resultShader
);
await memModelTester.run(20, 1);
await memModelTester.run(15, 1);
});

const storageMemoryBarrierLoadStoreTestCode = `
let r0 = test_locations.value[x_0];
workgroupBarrier();
test_locations.value[x_1] = 1u;
atomicStore(&results.value[shuffled_workgroup * workgroupXSize + id_0].r0, r0);
`;

const workgroupMemoryBarrierLoadStoreTestCode = `
let r0 = wg_test_locations[x_0];
workgroupBarrier();
wg_test_locations[x_1] = 1u;
atomicStore(&results.value[shuffled_workgroup * workgroupXSize + id_0].r0, r0);
`;

g.test('workgroup_barrier_load_store')
.desc(
`Checks whether the workgroup barrier properly synchronizes a non-atomic write and read on
separate threads in the same workgroup. Within a workgroup, the barrier should force an invocation
before the barrier to not read the write from an invocation after the barrier.
`
)
.paramsSimple([
{ memType: MemoryType.NonAtomicStorageClass, _testCode: storageMemoryBarrierLoadStoreTestCode },
{
memType: MemoryType.NonAtomicWorkgroupClass,
_testCode: workgroupMemoryBarrierLoadStoreTestCode,
},
])
.fn(async t => {
const resultCode = `
if (r0 == 0u) {
atomicAdd(&test_results.seq, 1u);
} else if (r0 == 1u) {
atomicAdd(&test_results.weak, 1u);
}
`;
const testShader = buildTestShader(
t.params._testCode,
t.params.memType,
TestType.IntraWorkgroup
);
const resultShader = buildResultShader(
resultCode,
TestType.IntraWorkgroup,
ResultType.TwoBehavior
);
const memModelTester = new MemoryModelTester(
t,
memoryModelTestParams,
testShader,
resultShader
);
await memModelTester.run(12, 1);
});

const storageMemoryBarrierStoreStoreTestCode = `
test_locations.value[x_0] = 1u;
storageBarrier();
test_locations.value[x_1] = 2u;
`;

const workgroupMemoryBarrierStoreStoreTestCode = `
wg_test_locations[x_0] = 1u;
workgroupBarrier();
wg_test_locations[x_1] = 2u;
workgroupBarrier();
test_locations.value[shuffled_workgroup * workgroupXSize * stress_params.mem_stride * 2u + x_1] = wg_test_locations[x_1];
`;

g.test('workgroup_barrier_store_store')
.desc(
`Checks whether the workgroup barrier properly synchronizes non-atomic writes on
separate threads in the same workgroup. Within a workgroup, the barrier should force the value in memory
to be the result of the write after the barrier, not the write before.
`
)
.paramsSimple([
{
memType: MemoryType.NonAtomicStorageClass,
_testCode: storageMemoryBarrierStoreStoreTestCode,
},
{
memType: MemoryType.NonAtomicWorkgroupClass,
_testCode: workgroupMemoryBarrierStoreStoreTestCode,
},
])
.fn(async t => {
const resultCode = `
if (mem_x_0 == 2u) {
atomicAdd(&test_results.seq, 1u);
} else if (mem_x_0 == 1u) {
atomicAdd(&test_results.weak, 1u);
}
`;
const testShader = buildTestShader(
t.params._testCode,
t.params.memType,
TestType.IntraWorkgroup
);
const resultShader = buildResultShader(
resultCode,
TestType.IntraWorkgroup,
ResultType.TwoBehavior
);
const memModelTester = new MemoryModelTester(
t,
memoryModelTestParams,
testShader,
resultShader
);
await memModelTester.run(10, 1);
});
Loading

0 comments on commit aafa50d

Please sign in to comment.