Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/tvm/relay/op/strategy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from .generic import *
from . import x86
from . import adreno
from . import arm_cpu
from . import cuda
from . import hls
Expand Down
94 changes: 94 additions & 0 deletions python/tvm/relay/op/strategy/adreno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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.
"""Definition of adreno operator strategy."""
# pylint: disable=invalid-name,unused-argument,wildcard-import,unused-wildcard-import
from tvm import topi
from .generic import *
from .. import op as _op


@conv2d_strategy.register("adreno")
def conv2d_strategy_adreno(attrs, inputs, out_type, target):
"""conv2d adreno strategy"""
strategy = _op.OpStrategy()
data, kernel = inputs
dilation_h, dilation_w = attrs.get_int_tuple("dilation")
groups = attrs.groups
data_layout = attrs.data_layout
kernel_layout = attrs.kernel_layout
if dilation_h < 1 or dilation_w < 1:
raise ValueError("dilation should be positive value")

if groups == 1:
if data_layout == "NCHW" and kernel_layout == "OIHW":
strategy.add_implementation(
wrap_compute_conv2d(topi.cuda.conv2d_nchw),
wrap_topi_schedule(topi.cuda.schedule_conv2d_nchw),
name="conv2d_nchw.cuda",
)
elif data_layout == "NCHW4c" and kernel_layout == "OIHW4o":
strategy.add_implementation(
wrap_compute_conv2d(topi.adreno.conv2d_nchwc),
wrap_topi_schedule(topi.adreno.schedule_conv2d_nchwc),
name="conv2d_nchwc.image2d",
plevel=10,
)
strategy.add_implementation(
wrap_compute_conv2d(topi.adreno.conv2d_nchwc_acc32),
wrap_topi_schedule(topi.adreno.schedule_conv2d_nchwc_acc32),
name="conv2d_nchwc_acc32.image2d",
plevel=20,
)
else:
raise RuntimeError(
"Layout not supported: ("
+ data_layout
+ ", "
+ kernel_layout
+ ") - only support NCHW4c / OIHW4o layouts for conv2d"
)
elif is_depthwise_conv2d(data.shape, data_layout, kernel.shape, kernel_layout, groups):
if data_layout == "NCHW" and kernel_layout == "OIHW":
strategy.add_implementation(
wrap_compute_conv2d(topi.cuda.depthwise_conv2d_nchw),
wrap_topi_schedule(topi.cuda.schedule_depthwise_conv2d_nchw),
name="depthwise_conv2d_nchw.cuda",
)
elif data_layout == "NCHW4c" and kernel_layout == "OIHW4o":
strategy.add_implementation(
wrap_compute_conv2d(topi.adreno.depthwise_conv2d_nchwc),
wrap_topi_schedule(topi.adreno.schedule_depthwise_conv2d_nchwc),
name="depthwise_conv2d_nchwc.image2d",
plevel=10,
)
strategy.add_implementation(
wrap_compute_conv2d(topi.adreno.depthwise_conv2d_nchwc_acc32),
wrap_topi_schedule(topi.adreno.schedule_depthwise_conv2d_nchwc_acc32),
name="depthwise_conv2d_nchwc_acc32.image2d",
plevel=20,
)
else:
raise RuntimeError(
"Layout not supported: ("
+ data_layout
+ ", "
+ kernel_layout
+ ") - only support NCHW4c / OIHW4o layouts for conv2d"
)
else:
raise RuntimeError("General group convolution is not currently supported")
return strategy
15 changes: 15 additions & 0 deletions python/tvm/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ def mali(model="unknown", options=None):
return Target(" ".join(["opencl"] + opts))


def adreno(model="unknown", options=None):
"""Returns a Qualcomm GPU target.

Parameters
----------
model: str
The model of this device
options : str or list of str
Additional options
"""
opts = ["-device=adreno", "-model=%s" % model]
opts = _merge_opts(opts, options)
return Target(" ".join(["opencl"] + opts))


def intel_graphics(model="unknown", options=None):
"""Returns an Intel Graphics target.

Expand Down
1 change: 1 addition & 0 deletions python/tvm/topi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from . import x86
from . import cuda
from . import gpu
from . import adreno
from . import arm_cpu
from . import mali
from . import bifrost
Expand Down
20 changes: 20 additions & 0 deletions python/tvm/topi/adreno/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.

# pylint: disable=redefined-builtin, wildcard-import
"""Qualcomm Adreno GPU specific declaration and schedules."""
from .conv2d import *
Loading