Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
fd6dbd5e
Commit
fd6dbd5e
authored
Jul 16, 2019
by
Joshua Z. Zhang
Committed by
Tianqi Chen
Jul 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix js test load module example (#3556)
parent
6d702ea8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
8 deletions
+16
-8
tests/web/prepare_test_libs.py
+3
-1
tests/web/test_module_load.js
+5
-2
web/README.md
+8
-5
No files found.
tests/web/prepare_test_libs.py
View file @
fd6dbd5e
...
...
@@ -30,7 +30,9 @@ def prepare_test_libs(base_path):
fadd1
=
tvm
.
build
(
s
,
[
A
,
B
],
target
,
name
=
"add_one"
)
obj_path
=
os
.
path
.
join
(
base_path
,
"test_add_one.bc"
)
fadd1
.
save
(
obj_path
)
emscripten
.
create_js
(
os
.
path
.
join
(
base_path
,
"test_module.js"
),
obj_path
)
emscripten
.
create_js
(
os
.
path
.
join
(
base_path
,
"test_module.js"
),
obj_path
,
options
=
[
"-s"
,
"WASM=0"
,
"-s"
,
"USE_GLFW=3"
,
"-s"
,
"USE_WEBGL2=1"
,
"-lglfw"
])
if
__name__
==
"__main__"
:
curr_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
__file__
)))
...
...
tests/web/test_module_load.js
View file @
fd6dbd5e
...
...
@@ -37,15 +37,18 @@ function randomArray(length, max) {
function
testAddOne
()
{
// grab pre-loaded function
var
faddOne
=
sysLib
.
getFunction
(
"add_one"
);
var
assert
=
require
(
'assert'
);
tvm
.
assert
(
tvm
.
isPackedFunc
(
faddOne
));
var
n
=
124
;
var
A
=
tvm
.
empty
(
n
).
copyFrom
(
randomArray
(
n
,
1
));
var
B
=
tvm
.
empty
(
n
);
// call the function.
faddOne
(
A
,
B
);
AA
=
A
.
asArray
();
// retrieve values in js array
BB
=
B
.
asArray
();
// retrieve values in js array
// verify
for
(
var
i
=
0
;
i
<
B
.
length
;
++
i
)
{
tvm
.
assert
(
B
[
i
]
==
A
[
i
]
+
1
);
for
(
var
i
=
0
;
i
<
B
B
.
length
;
++
i
)
{
assert
(
Math
.
abs
(
BB
[
i
]
-
(
AA
[
i
]
+
1
))
<
1
e
-
5
);
}
faddOne
.
release
();
}
...
...
web/README.md
View file @
fd6dbd5e
...
...
@@ -120,13 +120,13 @@ how to run the compiled library.
```
js
// Load Emscripten Module, need to change path to root/build
const
path
=
require
(
"path"
);
process
.
chdir
(
path
.
join
(
__dirname
,
"../../buld"
));
process
.
chdir
(
path
.
join
(
__dirname
,
"../../bu
i
ld"
));
var
Module
=
require
(
"../../build/test_module.js"
);
// Bootstrap TVMruntime with emscripten module.
const
tvm_runtime
=
require
(
"../../web/tvm_runtime.js"
);
const
tvm
=
tvm_runtime
.
create
(
Module
);
// Load system library, the compiled function
s
is registered in sysLib.
// Load system library, the compiled function is registered in sysLib.
var
sysLib
=
tvm
.
systemLib
();
function
randomArray
(
length
,
max
)
{
...
...
@@ -138,22 +138,25 @@ function randomArray(length, max) {
function
testAddOne
()
{
// grab pre-loaded function
var
faddOne
=
sysLib
.
getFunction
(
"add_one"
);
var
assert
=
require
(
'assert'
);
tvm
.
assert
(
tvm
.
isPackedFunc
(
faddOne
));
var
n
=
124
;
var
A
=
tvm
.
empty
(
n
).
copyFrom
(
randomArray
(
n
,
1
));
var
B
=
tvm
.
empty
(
n
);
// call the function.
faddOne
(
A
,
B
);
AA
=
A
.
asArray
();
// retrieve values in js array
BB
=
B
.
asArray
();
// retrieve values in js array
// verify
for
(
var
i
=
0
;
i
<
B
.
length
;
++
i
)
{
tvm
.
assert
(
B
[
i
]
==
A
[
i
]
+
1
);
for
(
var
i
=
0
;
i
<
B
B
.
length
;
++
i
)
{
assert
(
Math
.
abs
(
BB
[
i
]
-
(
AA
[
i
]
+
1
))
<
1
e
-
5
);
}
faddOne
.
release
();
}
testAddOne
();
sysLib
.
release
();
console
.
log
(
"Finish verifying test_module_load"
);
```
Current example supports static linking, which is the preferred way to get more efficiency
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment