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
83b24b5b
Commit
83b24b5b
authored
Nov 19, 2018
by
Junru Shao
Committed by
Tianqi Chen
Nov 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TOPI] Minor fix in the LSTM recipe (#2131)
parent
7858a1ea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
topi/recipe/rnn/lstm.py
+9
-10
No files found.
topi/recipe/rnn/lstm.py
View file @
83b24b5b
"""LSTM Example, still work in progress.."""
import
tvm
import
time
import
os
import
argparse
from
tvm.contrib
import
nvcc
import
numpy
as
np
...
...
@@ -14,16 +12,19 @@ DETECT_GLOBAL_BARRIER = PERSIST_KERNEL
SKIP_CHECK
=
False
UNROLL_WLOAD
=
True
@tvm.register_func
def
tvm_callback_cuda_compile
(
code
):
"""Use nvcc compiler for better perf."""
ptx
=
nvcc
.
compile_cuda
(
code
,
target
=
"ptx"
)
return
ptx
def
write_code
(
code
,
fname
):
with
open
(
fname
,
"w"
)
as
f
:
f
.
write
(
code
)
@tvm.register_func
def
tvm_callback_cuda_postproc
(
code
):
if
not
os
.
path
.
exists
(
"perf"
):
...
...
@@ -33,16 +34,16 @@ def tvm_callback_cuda_postproc(code):
code
=
open
(
"perf/
%
s_manual.cu"
%
TASK
)
.
read
()
return
code
def
lstm
():
if
not
PERSIST_KERNEL
:
raise
ValueError
(
"Non persist LSTM not yet supported"
)
detect_global_barrier
=
DETECT_GLOBAL_BARRIER
num_thread_y
=
8
num_thread_x
=
16
*
3
/
2
num_thread_x
=
16
*
3
/
/
2
num_sm
=
24
n_num_step
=
128
num_step
=
tvm
.
var
(
'num_step'
)
num_hidden
=
1152
/
2
num_hidden
=
1152
/
/
2
batch_size
=
1
# Global transition matrix
# Input hidden channel can be pre-caculated by a gemm
...
...
@@ -165,11 +166,9 @@ def lstm():
flstm
(
Xi2h_a
,
Wh2h_a
,
scan_h_a
,
scan_c_a
)
ctx
.
sync
()
# measure time cost of second step.
tstart
=
time
.
time
()
flstm
(
Xi2h_a
,
Wh2h_a
,
scan_h_a
,
scan_c_a
)
ctx
.
sync
()
tgap
=
time
.
time
()
-
tstart
print
(
"Time cost=
%
g"
%
tgap
)
evaluator
=
flstm
.
time_evaluator
(
flstm
.
entry_name
,
ctx
,
1
,
repeat
=
1000
)
eval_result
=
evaluator
(
Xi2h_a
,
Wh2h_a
,
scan_h_a
,
scan_c_a
)
print
(
"Time cost=
%
g"
%
eval_result
.
mean
)
# set unroll_explicit for more readable code.
with
tvm
.
build_config
(
...
...
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