tvm icon indicating copy to clipboard operation
tvm copied to clipboard

Cannot store type float32 for fusion of bn and relu

Open weitliu opened this issue 9 years ago • 5 comments

I am trying to add the fusion of bn and relu for the depthwise conv forward for layout NHWC. When I try to build the bn with the s2 scheduler, it does not work. f2 = tvm.build(s2, [Input, Filter, Scale, Shift, ScaleShift], device) In the same test file, the depthwise conv forward test for both NHWC and NCHW passed. The bn and relu fusion for NCHW also passes. Am I missing something for NHWC layout with the fusion?

Traceback (most recent call last): File "test_topi_depthwise_conv2d_map.py", line 215, in test_depthwise_conv2d_map() File "test_topi_depthwise_conv2d_map.py", line 204, in test_depthwise_conv2d_map depthwise_conv2d_map_with_workload_nhwc(1, 728, 64, 1, 3, 1, "SAME") File "test_topi_depthwise_conv2d_map.py", line 188, in depthwise_conv2d_map_with_workload_nhwc check_device("cuda") File "test_topi_depthwise_conv2d_map.py", line 158, in check_device f2 = tvm.build(s2, [Input, Filter, Scale, Shift, ScaleShift], device) File "/home/liuwt92/.local/lib/python2.7/site-packages/tvm-0.1.0-py2.7-linux-x86_64.egg/tvm/build_module.py", line 345, in build mhost = codegen.build_module(fhost, target_host) File "/home/liuwt92/.local/lib/python2.7/site-packages/tvm-0.1.0-py2.7-linux-x86_64.egg/tvm/codegen.py", line 20, in build_module return _Build(lowered_func, target) File "/home/liuwt92/.local/lib/python2.7/site-packages/tvm-0.1.0-py2.7-linux-x86_64.egg/tvm/_ffi/function.py", line 255, in my_api_func return flocal(*args) File "tvm/_ffi/_cython/function.pxi", line 260, in core.FunctionBase.call (tvm/_ffi/_cython/core.cpp:6818) File "tvm/_ffi/_cython/function.pxi", line 209, in core.FuncCall (tvm/_ffi/_cython/core.cpp:6040) File "tvm/_ffi/_cython/function.pxi", line 201, in core.FuncCall3 (tvm/_ffi/_cython/core.cpp:5943) File "tvm/_ffi/_cython/base.pxi", line 130, in core.CALL (tvm/_ffi/_cython/core.cpp:1837) tvm._ffi.base.TVMError: [10:31:52] src/codegen/stack_vm/././stack_vm.h:382: Cannot store type float32

The code I modify from is this: https://github.com/dmlc/tvm/blob/master/topi/tests/python/test_topi_depthwise_conv2d_map.py Thank you!

weitliu avatar Aug 14 '17 17:08 weitliu

can you paste a copy of ir after tvm.lower?

tqchen avatar Aug 14 '17 18:08 tqchen

It seems it does not do the compute-inline. But it does get into this line of traverse (nhwc version): https://github.com/dmlc/tvm/blob/master/topi/python/topi/cuda/depthwise_conv2d_map.py#L107

Does the scale shift and relu also has layout to be considered? // attr [DepthwiseConv2d] storage_scope = "global" allocate DepthwiseConv2d[float32 * 1 * 64 * 64 * 728] produce DepthwiseConv2d { // attr [iter_var(blockIdx.x, , blockIdx.x)] thread_extent = 1024 // attr [Filter.shared] storage_scope = "shared" allocate Filter.shared[float32 * 3 * 3 * 728 * 1] produce Filter.shared { for (ax0, 0, 3) { for (ax1, 0, 3) { // attr [iter_var(threadIdx.x, , threadIdx.x)] thread_extent = 728 Filter.shared[((((ax0*3) + ax1)728) + threadIdx.x)] = Filter[(((((blockIdx.x/1024)728) + (ax02184)) + (ax1728)) + threadIdx.x)] } } } for (i.inner, 0, 2) { for (j.inner, 0, 2) { // attr [iter_var(threadIdx.x, , threadIdx.x)] thread_extent = 728 DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] = 0.000000f for (di, 0, 3) { for (dj, 0, 3) { DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] = (DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] + (select(((((((1 - di) - i.inner) <= (((blockIdx.x % 1024)/32)*2)) && ((((blockIdx.x % 1024)/32)*2) < ((65 - di) - i.inner))) && (((1 - dj) - j.inner) <= (((blockIdx.x % 1024) % 32)*2))) && ((((blockIdx.x % 1024) % 32)2) < ((65 - dj) - j.inner))), Input[((((((((((blockIdx.x % 1024) % 32)1456) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + (((blockIdx.x/1024)728) + threadIdx.x)) + (di46592)) + (dj728)) + -47320)], 0.000000f)Filter.shared[((((((blockIdx.x/1024)728) + threadIdx.x) + (di2184)) + (dj728)) - ((blockIdx.x/1024)728))])) } } } } } produce ScaleShift { for (c, 0, 64) { for (i, 0, 64) { for (j, 0, 728) { ScaleShift[((((c64) + i)728) + j)] = ((DepthwiseConv2d[((((c64) + i)*728) + j)]*Scale[c]) + Shift[c]) } } } }

weitliu avatar Aug 14 '17 18:08 weitliu

@tqchen The problem is that scale shift supports only NCHW layout. I will add another layout to it. Thank you!

weitliu avatar Aug 14 '17 18:08 weitliu

Unfortunately, the problem remains. Here is the tvm.lower:

// attr [DepthwiseConv2d] storage_scope = "global" allocate DepthwiseConv2d[float32 * 1 * 64 * 64 * 728] produce DepthwiseConv2d { // attr [iter_var(blockIdx.x, , blockIdx.x)] thread_extent = 1024 // attr [Filter.shared] storage_scope = "shared" allocate Filter.shared[float32 * 3 * 3 * 728 * 1] produce Filter.shared { for (ax0, 0, 3) { for (ax1, 0, 3) { // attr [iter_var(threadIdx.x, , threadIdx.x)] thread_extent = 728 Filter.shared[((((ax0*3) + ax1)728) + threadIdx.x)] = Filter[(((((blockIdx.x/1024)728) + (ax02184)) + (ax1728)) + threadIdx.x)] } } } for (i.inner, 0, 2) { for (j.inner, 0, 2) { // attr [iter_var(threadIdx.x, , threadIdx.x)] thread_extent = 728 DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] = 0.000000f for (di, 0, 3) { for (dj, 0, 3) { DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] = (DepthwiseConv2d[(((((((blockIdx.x/1024)*728) + (((blockIdx.x % 1024) % 32)1456)) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + threadIdx.x)] + (select(((((((1 - di) - i.inner) <= (((blockIdx.x % 1024)/32)*2)) && ((((blockIdx.x % 1024)/32)*2) < ((65 - di) - i.inner))) && (((1 - dj) - j.inner) <= (((blockIdx.x % 1024) % 32)*2))) && ((((blockIdx.x % 1024) % 32)2) < ((65 - dj) - j.inner))), Input[((((((((((blockIdx.x % 1024) % 32)1456) + (((blockIdx.x % 1024)/32)93184)) + (i.inner46592)) + (j.inner728)) + (((blockIdx.x/1024)728) + threadIdx.x)) + (di46592)) + (dj728)) + -47320)], 0.000000f)Filter.shared[((((((blockIdx.x/1024)728) + threadIdx.x) + (di2184)) + (dj728)) - ((blockIdx.x/1024)728))])) } } } } } produce ScaleShift { for (i, 0, 64) { for (j, 0, 64) { for (c, 0, 728) { ScaleShift[((((i64) + j)728) + c)] = ((DepthwiseConv2d[((((i64) + j)*728) + c)]*Scale[c]) + Shift[c]) } } } }

Thank you!

weitliu avatar Aug 14 '17 20:08 weitliu

This is because the schedule does not successfully fused the compute into scaleshift, and schedule shift computation becomes CPU computation

tqchen avatar Aug 14 '17 21:08 tqchen