Skip to content

Commit 78af92b

Browse files
mbaretkevinthesun
authored andcommitted
[TOPI] Added support for Mali Bifrost target (apache#4047)
1 parent 5f7f300 commit 78af92b

File tree

9 files changed

+1245
-9
lines changed

9 files changed

+1245
-9
lines changed

python/tvm/target.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,19 @@ def vta(model='unknown', options=None):
506506
return ret
507507

508508

509+
def bifrost(model='unknown', options=None):
510+
"""Return an ARM Mali GPU target (Bifrost architecture).
511+
512+
Parameters
513+
----------
514+
options : str or list of str
515+
Additional options
516+
"""
517+
opts = ["-device=bifrost", '-model=%s' % model]
518+
opts = _merge_opts(opts, options)
519+
return _api_internal._TargetCreate("opencl", *opts)
520+
521+
509522
def create(target_str):
510523
"""Get a target given target string.
511524

topi/python/topi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from . import cuda
2929
from . import arm_cpu
3030
from . import mali
31+
from . import bifrost
3132
from . import intel_graphics
3233
from . import opengl
3334
from . import util

topi/python/topi/arm_cpu/conv2d.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,28 +560,38 @@ def _alter_conv2d_layout_arm(attrs, inputs, tinfos, F):
560560
if "-device=arm_cpu" in target.options:
561561
tile_size = 4
562562
VC = cfg['tile_k'].size[-1]
563+
elif "-device=bifrost" in target.options:
564+
tile_size = 2
565+
VC = 0
563566
else:
564567
from ..mali.conv2d import _pick_tile_size
565568
tile_size = _pick_tile_size(tinfos[0], tinfos[1])
566569
VC = cfg['tile_bna'].val
567570

568571
weight = F.nn.contrib_conv2d_winograd_weight_transform(copy_inputs[1],
569572
tile_size=tile_size)
570-
weight = F.reshape(weight,
571-
newshape=(KH + tile_size - 1,
572-
KW + tile_size - 1,
573-
idxd(CO, VC), VC, CI))
574-
weight = F.transpose(weight, axes=[0, 1, 2, 4, 3])
573+
if VC > 0:
574+
weight = F.reshape(weight,
575+
newshape=(KH + tile_size - 1,
576+
KW + tile_size - 1,
577+
idxd(CO, VC), VC, CI))
578+
weight = F.transpose(weight, axes=[0, 1, 2, 4, 3])
579+
new_weight = tvm.placeholder((KH + tile_size - 1,
580+
KW + tile_size -1,
581+
idxd(CO, VC), CI, VC),
582+
kernel.dtype)
583+
else:
584+
weight = F.reshape(weight,
585+
newshape=(KH + tile_size - 1, KW + tile_size - 1, CO, CI))
586+
new_weight = tvm.placeholder(
587+
(KH + tile_size - 1, KW + tile_size -1, CO, CI), kernel.dtype
588+
)
575589

576590
copy_inputs[1] = weight
577591
new_attrs['tile_size'] = tile_size
578592

579593
# Store the same config for the altered operator (workload)
580594
new_data = data
581-
new_weight = tvm.placeholder((KH + tile_size - 1,
582-
KH + tile_size -1,
583-
idxd(CO, VC), CI, VC),
584-
kernel.dtype)
585595
new_workload = autotvm.task.args_to_workload(
586596
[new_data, new_weight, strides, padding, dilation,
587597
new_attrs[data_layout_key], out_dtype, tile_size],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pylint: disable=redefined-builtin, wildcard-import
2+
"""ARM Mali GPU specific declaration and schedules."""
3+
from __future__ import absolute_import as _abs
4+
5+
from .gemm import *
6+
from .conv2d import *
7+
from .dense import *
8+
from .depthwise_conv2d import *

0 commit comments

Comments
 (0)