Skip to content

Commit

Permalink
webgl: Add packed op for sin/cos (#7382)
Browse files Browse the repository at this point in the history
Fixed #7372

Co-authored-by: Ping Yu <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
  • Loading branch information
3 people authored Feb 16, 2023
1 parent 5b7a4e9 commit 717d081
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tfjs-backend-webgl/src/kernels/Cos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@

import {Cos, KernelConfig} from '@tensorflow/tfjs-core';

import {CHECK_NAN_SNIPPET_PACKED} from '../binaryop_packed_gpu';
import {CHECK_NAN_SNIPPET_UNARY, unaryKernelFunc} from '../kernel_utils/kernel_funcs_utils';

const COS = CHECK_NAN_SNIPPET_UNARY + `
return cos(x);
`;

export const cos = unaryKernelFunc({opSnippet: COS});
const COS_PACKED = `
vec4 result = cos(x);
bvec4 isNaN = isnan(x);
${CHECK_NAN_SNIPPET_PACKED}
return result;
`;

export const cos =
unaryKernelFunc({opSnippet: COS, packedOpSnippet: COS_PACKED});

export const cosConfig: KernelConfig = {
kernelName: Cos,
Expand Down
11 changes: 10 additions & 1 deletion tfjs-backend-webgl/src/kernels/Sin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@

import {KernelConfig, Sin} from '@tensorflow/tfjs-core';

import {CHECK_NAN_SNIPPET_PACKED} from '../binaryop_packed_gpu';
import {CHECK_NAN_SNIPPET_UNARY, unaryKernelFunc} from '../kernel_utils/kernel_funcs_utils';

const SIN = CHECK_NAN_SNIPPET_UNARY + `
return sin(x);
`;

export const sin = unaryKernelFunc({opSnippet: SIN});
const SIN_PACKED = `
vec4 result = sin(x);
bvec4 isNaN = isnan(x);
${CHECK_NAN_SNIPPET_PACKED}
return result;
`;

export const sin =
unaryKernelFunc({opSnippet: SIN, packedOpSnippet: SIN_PACKED});

export const sinConfig: KernelConfig = {
kernelName: Sin,
Expand Down

0 comments on commit 717d081

Please sign in to comment.