From 43e6d0ceca26bb434590d862a72a2ec2b735f72b Mon Sep 17 00:00:00 2001 From: lonelyclick Date: Sun, 8 Dec 2019 01:44:22 +0800 Subject: [PATCH] [WASM] add `exp` --- tfjs-backend-wasm/src/cc/BUILD | 9 +++++ tfjs-backend-wasm/src/cc/kernels/Exp.cc | 36 ++++++++++++++++++++ tfjs-backend-wasm/src/kernels/Exp.ts | 19 +++++++++++ tfjs-backend-wasm/src/kernels/all_kernels.ts | 1 + 4 files changed, 65 insertions(+) create mode 100644 tfjs-backend-wasm/src/cc/kernels/Exp.cc create mode 100644 tfjs-backend-wasm/src/kernels/Exp.ts diff --git a/tfjs-backend-wasm/src/cc/BUILD b/tfjs-backend-wasm/src/cc/BUILD index f76643b36bf..e2c50c04a57 100644 --- a/tfjs-backend-wasm/src/cc/BUILD +++ b/tfjs-backend-wasm/src/cc/BUILD @@ -415,6 +415,15 @@ tfjs_cc_library( ], ) +tfjs_cc_library( + name = "Exp", + srcs = ["kernels/Exp.cc"], + deps = [ + ":backend", + ":unary", + ], +) + tfjs_cc_library( name = "util", hdrs = ["util.h"], diff --git a/tfjs-backend-wasm/src/cc/kernels/Exp.cc b/tfjs-backend-wasm/src/cc/kernels/Exp.cc new file mode 100644 index 00000000000..5805b8aadec --- /dev/null +++ b/tfjs-backend-wasm/src/cc/kernels/Exp.cc @@ -0,0 +1,36 @@ +/* Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ===========================================================================*/ + +#ifdef __EMSCRIPTEN__ +#include +#endif + +#include + +#include "src/cc/backend.h" +#include "src/cc/unary.h" + +namespace tfjs { +namespace wasm { +// We use C-style API to interface with Javascript. +extern "C" { + +#ifdef __EMSCRIPTEN__ +EMSCRIPTEN_KEEPALIVE +#endif +void Exp(const int x_id, const int out_id) { unary(x_id, out_id, std::exp); } + +} // extern "C" +} // namespace wasm +} // namespace tfjs diff --git a/tfjs-backend-wasm/src/kernels/Exp.ts b/tfjs-backend-wasm/src/kernels/Exp.ts new file mode 100644 index 00000000000..b131f2abd4b --- /dev/null +++ b/tfjs-backend-wasm/src/kernels/Exp.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +import { registerUnaryKernel } from './unary_kernel'; +registerUnaryKernel('Exp'); diff --git a/tfjs-backend-wasm/src/kernels/all_kernels.ts b/tfjs-backend-wasm/src/kernels/all_kernels.ts index 4d6dea9a2a3..363b27b8e28 100644 --- a/tfjs-backend-wasm/src/kernels/all_kernels.ts +++ b/tfjs-backend-wasm/src/kernels/all_kernels.ts @@ -51,3 +51,4 @@ import './Slice'; import './Square'; import './Sub'; import './Transpose'; +import './Exp';