Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e433ad
[RELAX][PASS] Annotate Custom Scope layout pass for Adreno GPU
srkreddy1238 Dec 30, 2024
b6a4243
lint
srkreddy1238 Jan 21, 2025
c8f89c6
Optional attr addition in legalization
srkreddy1238 Jan 22, 2025
9bf983f
VDevice ptr equality.
srkreddy1238 Jan 27, 2025
90083c7
Rename pass - SpecializeTIRParams
srkreddy1238 Jan 27, 2025
8aa6665
Remote OptimizeBatchnorm pass. Redundant with DecomposeOpsForInference.
srkreddy1238 Jan 28, 2025
bf26730
review
srkreddy1238 Feb 7, 2025
fa40cd2
About to go for InferStructInfo query to set the scope
srkreddy1238 Feb 25, 2025
8865f8e
lint
srkreddy1238 Feb 26, 2025
9cf72cb
docs
srkreddy1238 Feb 26, 2025
07a2c85
Organize passes
srkreddy1238 Feb 26, 2025
d5bcf8c
tests
srkreddy1238 Feb 26, 2025
8dd1df6
new passes
srkreddy1238 Feb 26, 2025
15bbd35
Lint
srkreddy1238 Feb 26, 2025
7301aa8
Lint
srkreddy1238 Feb 26, 2025
2599a24
Update only VDevice.
srkreddy1238 Feb 26, 2025
856af52
Docs.
srkreddy1238 Feb 26, 2025
31d80d1
Test case rollback and fixes.
srkreddy1238 Feb 26, 2025
ba5a6b0
remove log prints
srkreddy1238 Feb 27, 2025
0b326ec
review comments
srkreddy1238 Mar 25, 2025
3139dfb
Review comments.
srkreddy1238 Mar 31, 2025
1bc8e80
Test case fix.
srkreddy1238 Apr 1, 2025
74cf9b2
Move adreno tests to specific folder
srkreddy1238 May 2, 2025
85fcf2a
Changes due to recent mainline ffi
srkreddy1238 Jun 4, 2025
f969d99
Remove VDevice from legalization. Let tir emit handle it.
srkreddy1238 Jun 25, 2025
a303873
Rebase
srkreddy1238 Jun 30, 2025
f1d6847
Rebase after reflection changes.
srkreddy1238 Jul 21, 2025
88fe95f
Cross compiler options to work with configure
srkreddy1238 Jul 26, 2025
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
src/relax/analysis/*.cc
src/relax/transform/*.cc
src/relax/backend/vm/*.cc
src/relax/backend/adreno/*.cc
src/relax/backend/task_extraction.cc
src/relax/backend/pattern_registry.cc
src/relax/utils.cc
Expand Down
4 changes: 3 additions & 1 deletion include/tvm/relax/attrs/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ struct ToVDeviceAttrs : public AttrsNodeReflAdapter<ToVDeviceAttrs> {
struct HintOnDeviceAttrs : public AttrsNodeReflAdapter<HintOnDeviceAttrs> {
int32_t dev_type;
int32_t dev_id;
MemoryScope memory_scope;

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<HintOnDeviceAttrs>()
.def_ro("dev_type", &HintOnDeviceAttrs::dev_type,
"The device type where the data is supposed to be executed.")
.def_ro("dev_id", &HintOnDeviceAttrs::dev_id, "The device id.");
.def_ro("dev_id", &HintOnDeviceAttrs::dev_id, "The device id.")
.def_ro("memory_scope", &HintOnDeviceAttrs::memory_scope, "The device memory scope.");
}

static constexpr const char* _type_key = "relax.attrs.HintOnDeviceAttrs";
Expand Down
67 changes: 67 additions & 0 deletions include/tvm/relax/backend/adreno/transform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.
*/

/*!
* \file tvm/relax/backend/adreno/transform.h
* \brief Adreno GPU specific transformation passes.
*/
#ifndef TVM_RELAX_BACKEND_ADRENO_TRANSFORM_H_
#define TVM_RELAX_BACKEND_ADRENO_TRANSFORM_H_

#include <tvm/relax/expr.h>
#include <tvm/relax/transform.h>
namespace tvm {
namespace relax {
namespace backend {
namespace adreno {
namespace transform {

using Pass = tvm::transform::Pass;
using PassInfo = tvm::transform::PassInfo;
using PassContext = tvm::transform::PassContext;
using Function = tvm::relax::Function;
using DataflowBlock = tvm::relax::DataflowBlock;
using tvm::relax::transform::CreateFunctionPass;
using tvm::transform::CreateModulePass;

/*!
* \brief This pass is designed to annotate the memory scope information via VDevice attribute.
* This pass need operator attrbutes which in general vanish aftre legalization.
* FuseOps and FuseTIR are modified to pass on the operator specific attributes and also
* op_pattern details as part of the PrimFunc. This pass is Adreno specific and annotates each
* BindingVar with appropriate HintInDevice. RealizeVDevice pass followed by handles these hints.
* Followed by this pass we also invoke SpecializePrimFuncBasedOnCallSite which updates the
* var_buffer_map based on this new VDevice information.
*/
TVM_DLL Pass AnnotateCustomMemoryScope(Target target);

/*
* \brief This is a texture specific pass that can optimize unnecessary to_device copies.
* Like texture_scope -> ToVDevice -> global scope. In this case the producer can directly
* store into global scope avoiding unnecessary device copy.
*/
TVM_DLL Pass FoldVDeviceScopeChange();

} // namespace transform
} // namespace adreno
} // namespace backend
} // namespace relax
} // namespace tvm

#endif // TVM_RELAX_BACKEND_ADRENO_TRANSFORM_H_
6 changes: 5 additions & 1 deletion include/tvm/relax/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ class CallNode : public ExprNode {

/*!
* \brief The structure info arguments of a CallNode.
* sinfo_args is designed to be non-empty only for intrinsic op (e.g.,
* sinfo_args is by default designed to be non-empty only for intrinsic op (e.g.,
* call_tir, call_builtin_with_ctx, etc.) and calls to ExternFuncs, with the main
* usage of structure info inference.
*
* Regular ops also at times may have sinfo_args defined to specialize partial
* or complete structure info. Like VDevice customization with mixed input memory_scopes.
* The customized pass can set this info and operator specific inference will respect it.
*/
Array<StructInfo> sinfo_args;

Expand Down
11 changes: 10 additions & 1 deletion include/tvm/relax/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ TVM_DLL Pass FoldConstant();
*
* \param cmap The customized operator legalization function map. The customized function
* will override the default one.
* \param skip_ops The list operator names which need to be skipped from legalization
* \param enable_warning A boolean value indicating if to print warnings for TIR functions not
* showing up in the database.
* \return The Pass.
*/
TVM_DLL Pass LegalizeOps(Optional<Map<String, ffi::Function>> cmap, bool enable_warning = false);
TVM_DLL Pass LegalizeOps(Optional<Map<String, ffi::Function>> cmap,
Optional<Array<String>> skip_ops, bool enable_warning = false);

/*!
* \brief Propagate virtual device information.
Expand Down Expand Up @@ -673,6 +675,13 @@ TVM_DLL Pass RewriteCUDAGraph();
*/
TVM_DLL Pass FewShotTuning(int valid_count, bool benchmark);

/*!
* \brief This pass updates the var_buffer mapping of PrimFunctions from the call_tir info.
* Primarily used to update the VDevice information if any changes occured from the caller.
* This pass recreates the buffers and updates the map.
*/
TVM_DLL Pass SpecializePrimFuncBasedOnCallSite();

} // namespace transform
} // namespace relax
} // namespace tvm
Expand Down
10 changes: 10 additions & 0 deletions include/tvm/runtime/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ class NDArray : public tvm::ffi::NDArray {
*/
TVM_DLL static void CopyToBytes(const DLTensor* from, void* to, size_t nbytes,
TVMStreamHandle stream = nullptr);

/*!
* \brief Function to copy data from one array to a byte buffer.
* \param from The source array.
* \param to The target byte buffer.
* \param nbytes The size of the data buffer.
* \param stream The stream used in copy.
*/
TVM_DLL static void CopyFromBytes(const DLTensor* to, void* from, size_t nbytes,
TVMStreamHandle stream = nullptr);
};

/*!
Expand Down
1 change: 1 addition & 0 deletions python/tvm/dlight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
"""DLight package provides efficient schedules out-of-box for deep learning workloads."""
from . import gpu
from . import adreno
from . import cpu
from .analysis import (
BlockInfo,
Expand Down
20 changes: 20 additions & 0 deletions python/tvm/dlight/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.
"""
Adreno schedule rules.
"""
from .convolution import Conv2d
41 changes: 41 additions & 0 deletions python/tvm/dlight/adreno/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.
"""Base schedule rule for Adreno operators."""

from tvm.target import Target

from ..base import ScheduleRule


class AdrenoScheduleRule(ScheduleRule): # pylint: disable=too-few-public-methods
"""The Schedule Rule specific to Adreno targets,
will return None if the target is not Adreno."""

def is_target_available(self, target: Target) -> bool:
"""Check whether the target is available for Adreno rule.

Parameters
----------
target : Target
The compilation target to check.

Returns
-------
available : bool
Whether the target is available for this rule.
"""
return super().is_target_available(target) and "adreno" in target.keys
Loading
Loading