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
29d5ffbb
Commit
29d5ffbb
authored
Jun 27, 2017
by
ziheng
Committed by
Tianqi Chen
Jun 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[INTRINSIC] Add sqrt (#202)
* [INTRINSIC] Add sqrt * [INTRINSIC] Expose on cpp
parent
b8e02348
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
0 deletions
+64
-0
include/tvm/ir_operator.h
+1
-0
python/tvm/intrin.py
+16
-0
src/codegen/intrin_rule.cc
+3
-0
src/codegen/intrin_rule_cuda.cc
+3
-0
src/codegen/intrin_rule_opencl.cc
+3
-0
src/codegen/llvm/intrin_rule_llvm.cc
+3
-0
tests/python/unittest/test_topi_basic.py
+2
-0
topi/include/topi/ewise.h
+1
-0
topi/python/topi/ewise.py
+32
-0
No files found.
include/tvm/ir_operator.h
View file @
29d5ffbb
...
@@ -51,6 +51,7 @@ Expr min(Expr source, Array<IterVar> axis);
...
@@ -51,6 +51,7 @@ Expr min(Expr source, Array<IterVar> axis);
TVM_DECLARE_INTRIN_UNARY
(
exp
);
TVM_DECLARE_INTRIN_UNARY
(
exp
);
TVM_DECLARE_INTRIN_UNARY
(
tanh
);
TVM_DECLARE_INTRIN_UNARY
(
tanh
);
TVM_DECLARE_INTRIN_UNARY
(
sigmoid
);
TVM_DECLARE_INTRIN_UNARY
(
sigmoid
);
TVM_DECLARE_INTRIN_UNARY
(
sqrt
);
}
// namespace tvm
}
// namespace tvm
#endif // TVM_IR_OPERATOR_H_
#endif // TVM_IR_OPERATOR_H_
python/tvm/intrin.py
View file @
29d5ffbb
...
@@ -166,6 +166,22 @@ def log(x):
...
@@ -166,6 +166,22 @@ def log(x):
return
call_pure_intrin
(
x
.
dtype
,
"log"
,
x
)
return
call_pure_intrin
(
x
.
dtype
,
"log"
,
x
)
def
sqrt
(
x
):
"""Take log of input x.
Parameters
----------
x : Expr
Input argument.
Returns
-------
y : Expr
The result.
"""
return
call_pure_intrin
(
x
.
dtype
,
"sqrt"
,
x
)
# Intrinsic rule related code
# Intrinsic rule related code
def
register_intrin_rule
(
target
,
intrin
,
f
=
None
,
override
=
False
):
def
register_intrin_rule
(
target
,
intrin
,
f
=
None
,
override
=
False
):
"""Register an intrinsic function generation rule.
"""Register an intrinsic function generation rule.
...
...
src/codegen/intrin_rule.cc
View file @
29d5ffbb
...
@@ -18,6 +18,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.default.log")
...
@@ -18,6 +18,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.default.log")
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.default.tanh"
)
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.default.tanh"
)
.
set_body
(
DispatchExtern
<
FloatSuffix
>
);
.
set_body
(
DispatchExtern
<
FloatSuffix
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.default.sqrt"
)
.
set_body
(
DispatchExtern
<
FloatSuffix
>
);
}
// namespace intrin
}
// namespace intrin
}
// namespace codegen
}
// namespace codegen
}
// namespace tvm
}
// namespace tvm
src/codegen/intrin_rule_cuda.cc
View file @
29d5ffbb
...
@@ -45,6 +45,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.cuda.log")
...
@@ -45,6 +45,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.cuda.log")
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.cuda.tanh"
)
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.cuda.tanh"
)
.
set_body
(
DispatchExtern
<
CUDAMath
>
);
.
set_body
(
DispatchExtern
<
CUDAMath
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.cuda.sqrt"
)
.
set_body
(
DispatchExtern
<
CUDAMath
>
);
}
// namespace intrin
}
// namespace intrin
}
// namespace codegen
}
// namespace codegen
}
// namespace tvm
}
// namespace tvm
src/codegen/intrin_rule_opencl.cc
View file @
29d5ffbb
...
@@ -18,6 +18,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.opencl.log")
...
@@ -18,6 +18,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.opencl.log")
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.opencl.tanh"
)
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.opencl.tanh"
)
.
set_body
(
DispatchExtern
<
FloatDirect
>
);
.
set_body
(
DispatchExtern
<
FloatDirect
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.opencl.sqrt"
)
.
set_body
(
DispatchExtern
<
FloatDirect
>
);
}
// namespace intrin
}
// namespace intrin
}
// namespace codegen
}
// namespace codegen
}
// namespace tvm
}
// namespace tvm
src/codegen/llvm/intrin_rule_llvm.cc
View file @
29d5ffbb
...
@@ -37,6 +37,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.exp")
...
@@ -37,6 +37,9 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.exp")
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.log"
)
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.log"
)
.
set_body
(
DispatchLLVMIntrin
<::
llvm
::
Intrinsic
::
log
>
);
.
set_body
(
DispatchLLVMIntrin
<::
llvm
::
Intrinsic
::
log
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.sqrt"
)
.
set_body
(
DispatchLLVMIntrin
<::
llvm
::
Intrinsic
::
sqrt
>
);
}
// namespace llvm
}
// namespace llvm
}
// namespace codegen
}
// namespace codegen
}
// namespace tvm
}
// namespace tvm
...
...
tests/python/unittest/test_topi_basic.py
View file @
29d5ffbb
...
@@ -14,6 +14,8 @@ def test_ewise():
...
@@ -14,6 +14,8 @@ def test_ewise():
test_apply
(
topi
.
exp
,
"exp"
)
test_apply
(
topi
.
exp
,
"exp"
)
test_apply
(
topi
.
tanh
,
"tanh"
)
test_apply
(
topi
.
tanh
,
"tanh"
)
test_apply
(
topi
.
sigmoid
,
"sigmoid"
)
test_apply
(
topi
.
sigmoid
,
"sigmoid"
)
test_apply
(
topi
.
log
,
"log"
)
test_apply
(
topi
.
sqrt
,
"sqrt"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
topi/include/topi/ewise.h
View file @
29d5ffbb
...
@@ -22,5 +22,6 @@ using namespace tvm;
...
@@ -22,5 +22,6 @@ using namespace tvm;
TOPI_DECLARE_UNARY_OP
(
exp
);
TOPI_DECLARE_UNARY_OP
(
exp
);
TOPI_DECLARE_UNARY_OP
(
tanh
);
TOPI_DECLARE_UNARY_OP
(
tanh
);
TOPI_DECLARE_UNARY_OP
(
sigmoid
);
TOPI_DECLARE_UNARY_OP
(
sigmoid
);
TOPI_DECLARE_UNARY_OP
(
sqrt
);
}
// namespace topi
}
// namespace topi
#endif // TOPI_EWISE_H_
#endif // TOPI_EWISE_H_
topi/python/topi/ewise.py
View file @
29d5ffbb
...
@@ -34,6 +34,38 @@ def tanh(x):
...
@@ -34,6 +34,38 @@ def tanh(x):
return
tvm
.
compute
(
x
.
shape
,
lambda
*
i
:
tvm
.
tanh
(
x
(
*
i
)))
return
tvm
.
compute
(
x
.
shape
,
lambda
*
i
:
tvm
.
tanh
(
x
(
*
i
)))
def
log
(
x
):
"""Take logarithm of input x.
Parameters
----------
x : tvm.Tensor
Input argument.
Returns
-------
y : tvm.Tensor
The result.
"""
return
tvm
.
compute
(
x
.
shape
,
lambda
*
i
:
tvm
.
log
(
x
(
*
i
)))
def
sqrt
(
x
):
"""Take square root of input x.
Parameters
----------
x : tvm.Tensor
Input argument.
Returns
-------
y : tvm.Tensor
The result.
"""
return
tvm
.
compute
(
x
.
shape
,
lambda
*
i
:
tvm
.
sqrt
(
x
(
*
i
)))
def
sigmoid
(
x
):
def
sigmoid
(
x
):
"""Take sigmoid tanh of input x.
"""Take sigmoid tanh of input x.
...
...
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