Skip to content

Commit

Permalink
Implement quantizeToF16 f32 tests (#1828)
Browse files Browse the repository at this point in the history
Adds tests for quantizeToF16 and related infrastructure

Implements f16 support in the framework as needed for quantizeToF16

Adds petamoriken/float16 v3.6.6

Upstream https://github.com/petamoriken/float16

This adds native-like float16 support for implementing quantizeToF16
tests, and future f16 work.

Fixes #1812
Fixes #1200
  • Loading branch information
zoddicus authored Sep 8, 2022
1 parent a6451cc commit a20c0a3
Show file tree
Hide file tree
Showing 18 changed files with 2,246 additions and 72 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/external/*
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
{
"target": "./src/common",
"from": "./src",
"except": ["./common"],
"except": ["./common", "./external"],
"message": "Non common/ code imported from common/"
}
]
Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function (grunt) {
cmd: 'node',
args: [
'node_modules/@babel/cli/bin/babel',
'--extensions=.ts',
'--extensions=.ts,.js',
'--source-maps=true',
'--out-dir=out/',
'src/',
Expand All @@ -42,7 +42,7 @@ module.exports = function (grunt) {
cmd: 'node',
args: [
'node_modules/@babel/cli/bin/babel',
'--extensions=.ts',
'--extensions=.ts,.js',
'--source-maps=false',
'--delete-dir-on-start',
'--out-dir=out-wpt/',
Expand Down
42 changes: 26 additions & 16 deletions src/common/tools/setup-ts-in-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@ const Module = require('module');
// Redirect imports of .js files to .ts files
const resolveFilename = Module._resolveFilename;
Module._resolveFilename = (request, parentModule, isMain) => {
if (request.startsWith('.') && parentModule.filename.endsWith('.ts')) {
// Required for browser (because it needs the actual correct file path and
// can't do any kind of file resolution).
if (request.endsWith('/index.js')) {
throw new Error(
"Avoid the name `index.js`; we don't have Node-style path resolution: " + request
);
}
do {
if (request.startsWith('.') && parentModule.filename.endsWith('.ts')) {
// Required for browser (because it needs the actual correct file path and
// can't do any kind of file resolution).
if (request.endsWith('/index.js')) {
throw new Error(
"Avoid the name `index.js`; we don't have Node-style path resolution: " + request
);
}

// Import of Node addon modules are valid and should pass through.
if (request.endsWith('.node')) {
return resolveFilename.call(this, request, parentModule, isMain);
}
// Import of Node addon modules are valid and should pass through.
if (request.endsWith('.node')) {
break;
}

if (!request.endsWith('.js')) {
throw new Error('All relative imports must end in .js: ' + request);
if (!request.endsWith('.js')) {
throw new Error('All relative imports must end in .js: ' + request);
}

try {
const tsRequest = request.substring(0, request.length - '.js'.length) + '.ts';
return resolveFilename.call(this, tsRequest, parentModule, isMain);
} catch (ex) {
// If the .ts file doesn't exist, try .js instead.
break;
}
}
request = request.substring(0, request.length - '.js'.length) + '.ts';
}
} while (0);

return resolveFilename.call(this, request, parentModule, isMain);
};

Expand Down
2 changes: 2 additions & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Float16Array } from '../../external/petamoriken/float16/float16.js';
import { Logger } from '../internal/logging/logger.js';

import { keysOf } from './data_tables.js';
Expand Down Expand Up @@ -195,6 +196,7 @@ const TypedArrayBufferViewInstances = [
new Int8Array(),
new Int16Array(),
new Int32Array(),
new Float16Array(),
new Float32Array(),
new Float64Array(),
] as const;
Expand Down
31 changes: 31 additions & 0 deletions src/external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# External Modules

This directory contains external modules that are used by the WebGPU
CTS. These are included in the repo, as opposed to being fetched via a
package manager or CDN, so that there is a single canonical source of
truth for the CTS tests and the CTS tests can be run as a standalone
suite without needing to pull from a CDN or similar process.

## Adding modules

Each module that is added should be done consciously with a clear
reasoning on what the module is providing, since the bar for adding
new modules should be relatively high.

The module will need to be licensed via a compatible license to the
BSD-3 clause & W3C CTS licenses that the CTS currently is covered by.

It is preferred to use a single source build of the module if possible.

In addition to the source for the module a LICENSE file should be
included in the directory clearly identifying the owner of the module
and the license it is covered by.

Details of the specific module, including version, origin and purpose
should be listed below.

## Current Modules

| **Name** | **Origin** | **License** | **Version** | **Purpose** |
|----------------------|--------------------------------------------------|-------------|-------------|------------------------------------------------|
| petamoriken/float16 | [github](https://github.com/petamoriken/float16) | MIT | 3.6.6 | Fluent support for f16 numbers via TypedArrays |
21 changes: 21 additions & 0 deletions src/external/petamoriken/float16/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-2021 Kenta Moriuchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit a20c0a3

Please sign in to comment.