-
Couldn't load subscription status.
- Fork 99
Add documentation for the case cache #3178
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Case Cache | ||
|
|
||
| The WebGPU CTS contains many tests that check that the results of an operation | ||
| fall within limits defined by the WebGPU and WGSL specifications. The | ||
| computation of these allowed limits can be very expensive to calculate, however | ||
| the values do not vary by platform or device, and can be precomputed and reused | ||
| for multiple CTS runs. | ||
|
|
||
| ## File cache | ||
|
|
||
| To speed up execution of the CTS, the CTS git repo holds holds pre-computed | ||
| test cases, serialized in a set of gzip-compressed binary files under | ||
| [`src/resources/cache`](../src/resources/cache). | ||
|
|
||
| These files are regenerated by [`src/common/tools/gen_cache.ts`](../src/common/tools/gen_cache.ts) | ||
| which can be run with `npx grunt run:generate-cache`. | ||
| This tool is automatically run by the various Grunt build commands. | ||
|
|
||
| As generating the cache is expensive (hence why we build it ahead of time!) the | ||
| cache generation tool will only re-build the cache files it believes may be out | ||
| of date. To determine which files it needs to rebuild, the tool calculates a | ||
| hash of all the transitive source TypeScript files that are used to build the | ||
| output, and compares this hash to the hash stored in | ||
| [`src/resources/cache/hashes.json`](`../src/resources/cache/hashes.json`). Only | ||
| those cache files with differing hashes are rebuilt. | ||
ben-clayton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Since source changes will sometimes change the hash without changing the generated cache, | ||
| sometimes the cache will be regenerated unnecessarily. **This is OK, but try to avoid committing | ||
| no-op regenerations - this will happen if your version of Node produces different gzip outputs | ||
| than the original committer's Node did for the same input.** | ||
|
|
||
| The cache files are copied from [`src/resources/cache`](../src/resources/cache) | ||
| to the `resources/cache` subdirectory of the | ||
| [`out` and `out-node` build directories](build.md#build-types), so the runner | ||
| can load these cache files. | ||
|
|
||
| The GitHub presubmit checks will error if the cache files or | ||
| [`hashes.json`](`../src/resources/cache/hashes.json`) need updating. | ||
|
|
||
| ## In memory cache | ||
|
|
||
| If a cache file cannot be found, then the [`CaseCache`](../src/webgpu/shader/execution/expression/case_cache.ts) | ||
| will build the cases during CTS execution and store the results in an in-memory LRU cache. | ||
|
|
||
| ## Using the cache | ||
|
|
||
| To add test cases to the cache: | ||
|
|
||
| 1. Import `makeCaseCache` from [`'case_cache.js'`](../src/webgpu/shader/execution/expression/case_cache.ts); | ||
|
|
||
| ```ts | ||
| import { makeCaseCache } from '../case_cache.js'; // your relative path may vary | ||
| ``` | ||
|
|
||
| 2. Declare an exported global variable with the name `d`, assigned with the return value of `makeCaseCache()`: | ||
|
|
||
| ```ts | ||
| export const d = makeCaseCache('unique/path/of/your/cache/file', { | ||
| // Declare any number of fields that build the test cases | ||
| name_of_your_case: () => { | ||
| return fullI32Range().map(e => { // example case builder | ||
| return { input: i32(e), expected: i32(-e) }; | ||
| }); | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| 3. To load the cases from the cache, use `d.get();` | ||
|
|
||
| ```ts | ||
| const cases = await d.get('name_of_your_case'); | ||
| // cases will either be loaded from the cache file, loaded from the in-memory | ||
| // LRU, or built on the fly. | ||
| ``` | ||
|
|
||
| 4. Run `npx grunt run generate-cache` to generate the new cache file. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.