onnxruntime
1/**
2* @license
3* Copyright 2021 Google LLC. All Rights Reserved.
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15* =============================================================================
16*/
17
18// sampled from [@tensorflow/tfjs] tfjs-backend-webgpu/src/activation_util.ts
19//
20// modified to fit the needs of the project
21
22export const typeSnippet = (component: number, dataType: string) => {
23switch (component) {
24case 1:
25return dataType;
26case 2:
27return `vec2<${dataType}>`;
28case 3:
29return `vec3<${dataType}>`;
30case 4:
31return `vec4<${dataType}>`;
32default:
33throw new Error(`${component}-component is not supported.`);
34}
35};
36
37export const biasSnippet = (hasBias: boolean): string => `
38${hasBias ? 'value = value + getBiasByOutputCoords(coords);' : ''}
39`;
40