Skip to content

Commit 3c8406d

Browse files
lonelyclickdsmilkov
authored andcommitted
[WASM] Add exp (#2517)
FEATURE
1 parent f08f684 commit 3c8406d

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

tfjs-backend-wasm/src/cc/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ tfjs_cc_library(
415415
],
416416
)
417417

418+
tfjs_cc_library(
419+
name = "Exp",
420+
srcs = ["kernels/Exp.cc"],
421+
deps = [
422+
":backend",
423+
":unary",
424+
],
425+
)
426+
418427
tfjs_cc_library(
419428
name = "util",
420429
hdrs = ["util.h"],
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Copyright 2019 Google Inc. All Rights Reserved.
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ===========================================================================*/
14+
15+
#ifdef __EMSCRIPTEN__
16+
#include <emscripten.h>
17+
#endif
18+
19+
#include <cmath>
20+
21+
#include "src/cc/backend.h"
22+
#include "src/cc/unary.h"
23+
24+
namespace tfjs {
25+
namespace wasm {
26+
// We use C-style API to interface with Javascript.
27+
extern "C" {
28+
29+
#ifdef __EMSCRIPTEN__
30+
EMSCRIPTEN_KEEPALIVE
31+
#endif
32+
void Exp(const int x_id, const int out_id) { unary(x_id, out_id, std::exp); }
33+
34+
} // extern "C"
35+
} // namespace wasm
36+
} // namespace tfjs

tfjs-backend-wasm/src/kernels/Exp.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc. 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+
import { registerUnaryKernel } from './unary_kernel';
19+
registerUnaryKernel('Exp');

tfjs-backend-wasm/src/kernels/all_kernels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ import './Slice';
5151
import './Square';
5252
import './Sub';
5353
import './Transpose';
54+
import './Exp';

0 commit comments

Comments
 (0)