gyshi commented on a change in pull request #15973: Numpy . implement numpy op exp2 with tvm URL: https://github.com/apache/incubator-mxnet/pull/15973#discussion_r323524186
########## File path: contrib/tvmop/core/umath.py ########## @@ -0,0 +1,93 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# coding: utf-8 +import tvm +import topi +from .. import defop, AllTypes +from .. import assign_by_req, reduce_axes +import math + + +def compute_exp2(dtype, ndim): + A = tvm.placeholder([tvm.var() for _ in range(ndim)], name='A', dtype=dtype) + if dtype in ['float32', 'float64']: + B = tvm.compute([tvm.var() for _ in range(ndim)], + lambda *index: topi.power(2, A[index]), name='B') + else: + B = tvm.compute([tvm.var() for _ in range(ndim)], + lambda *index: topi.power(2, A[index].astype('float32')).astype(dtype), + name='B') + s = tvm.create_schedule(B.op) + return s, A, B + +@defop(name="exp2_cpu", target="cpu", auto_broadcast=False, + dtype=AllTypes, ndim=[5]) +def _exp2_cpu(dtype, ndim): + s, A, B = compute_exp2(dtype, ndim) + axes = [axis for axis in B.op.axis] + fused = s[B].fuse(*axes) + s[B].reorder(fused) + s[B].parallel(fused) + return s, [A, B] + + +@defop(name="exp2_gpu", target="cuda", auto_broadcast=False, + dtype=AllTypes, ndim=[5]) +def _exp2_gpu(dtype, ndim): + s, A, B= compute_exp2(dtype, ndim) + s = tvm.create_schedule(B.op) + axes = [axis for axis in B.op.axis] + fused = s[B].fuse(*axes) + bx, tx = s[B].split(fused, factor=64) Review comment: i think factor could be 32, 128 , it's also ok. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
