reminisce 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_r317890317
 
 

 ##########
 File path: contrib/tvmop/basic/ufunc.py
 ##########
 @@ -98,3 +99,71 @@ def backward_vadd_gpu(dtype, ndim, reduce1st, req):
         s[t].bind(bx, block_x)
         s[t].bind(tx, thread_x)
     return s, [X, in_grad_a, in_grad]
+
+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", target="cpu", auto_broadcast=True,
+       dtype=AllTypes, ndim=list(range(0, 6)))
+def exp2(dtype, ndim):
+    s, A, B = compute_exp2(dtype, ndim)
+    axes = [axis for axis in B.op.axis]
+    fused = s[B].fuse(*axes)
+    s[B].parallel(fused)
+    return s, [A, B]
+
+
+@defop(name="cuda_exp2", target="cuda", auto_broadcast=True,
+       dtype=AllTypesButHalf, ndim=list(range(0, 6)))
+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)
+    s[B].bind(bx, tvm.thread_axis("blockIdx.x"))
+    s[B].bind(tx, tvm.thread_axis("threadIdx.x"))
+    return s, [A, B]
+
+
+def compute_backward_exp2(dtype, ndim):
+    A = tvm.placeholder([tvm.var() for _ in range(ndim)], name='A', 
dtype=dtype)
+    B = tvm.placeholder([tvm.var() for _ in range(ndim)], name='B', 
dtype=dtype)
+    C = tvm.placeholder([tvm.var() for _ in range(ndim)], name='C', 
dtype=dtype)
+    D = tvm.compute([tvm.var() for _ in range(ndim)],
 
 Review comment:
   This seems wrong. Considering `y = 2^x`, `dy/dx` should be `2^x * ln2`. 
Please verify the implementation by comparing the results with numerical 
gradient, instead of hand-written gradient formula using numpy.

----------------------------------------------------------------
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

Reply via email to