forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
** Switch device planning etc to use SEScope **
[checkpoint] bad rebase [checkpoint] pretty printing fixes [checkpoint] Don't dup devices in executable, more unit tests [checkpoint] woops, left target str debug in Added Target::ToDebugString() so I can see the hosts since they were giving me a lot of trouble. [checkpoint] more pretty printing hackery, interpreter respects host devices Also try harder to integrate the existing target->host mechanism into CompilationConfig. [checkpoint] Almost working again - Unit test setup distinguishes CPU for prims from CPU for host. - Get pretty printing to use the SEScopeNode ReprPrinter. - Allow host and primitive to have same device types. test_dynamic_input failing [checkpoint] rebase [checkpoint] fix merge [checkpoint] lint [checkpoint] rebase [checkpoint] Fixed stray use of kDLCPU in vm/profiler/vm.cc [checkpoint] lint trivia [checkpoint] fix unit tests [checkpoint] device planner unit tests passing again [checkpoint] Switch over to new CompilerOptions [checkpoint] include [checkpoint] Almost working again Need to move the SEScopeCache into CompilationConfig and pass that into DeviceDomains instead of just the Vector<Target>. Then the host_se_scope can be memoized so that direct uses of that scope downstream will match up with se_scopes already established by PlanDevices. Sigh. [checkpoint] Use cache in device domains. [checkpoint] more moves [checkpoint] lints [checkpoint] Fix merge with VM profiling changes. [checkpoint] trivial [checkpoint] rebase fix [checkpoint] More unit tests. Getting ready to fork out SEScope changes alone. [checkpoint] lints [checkpoint] All plan devices unit tests pass [checkpoint] First unit test passes [checkpoint] Another go at target management This at least centralizes all the hackery. Compiles. [commit] Start to rollback resolving to target in planner. Better is to do it as stand alone pass I think. Besides it doesn't work with the structural test for expected output. [checkpoint] Almost have first unit test going. About to merge Michalis' changes. target_host is still a mess. Starting to eliminate target_map. [checkpoint] Cleanup VM device matching [checkpoint] Compiles [checkpoint] First sweep replacing DLDeviceType with SEScope VM still not done. [checkpoint] Expose CompilationConfig ctor in py [checkpoint] CompilationConfig is nullable for default ctor [checkpoint] Don't use target:: namespace [checkpoint] Promote CompilationConfig to be FFI-friendly Object Also rework to never mix the host_target into the 'primitive' targets. [checkpoint] ResolveSEScope on CompilationConfig [checkpoint] hash_reduce using target's data ptr [checkpoint] Share FullyUnconstrained [checkpoint] Backtrack on using global memoization for SEScope Realized while working through unit tests in the sequel that it's reasonable for folks to call build multiple times with distinct Target objects, in which case the global cache would grow without bound. I'll instead tackle memoization of SEScopes directly in device_domains.cc. [checkpoint] Improve back compat for homogeneous case If no host target is given but we have a unique target of kDLCPU device type then also use that for the host. Reworked to avoid global SEScopeCache. Realized while working through unit tests in the sequel that it's reasonable for folks to call build multiple times with distinct Target objects, in which case the global cache would grow without bound. So instead placed the cache in the CompilationConfig class. Since that class now has everything the device planner needs to do its job, promoted it to be an FFI-able Object, which is now in compilation_config.{h,cc}. I think we can do much better with CompilationConfig, but for now keeping it to the minimum I needed to prepare for device planning from all the executor compilation codepaths. Adds SEScope (Storage/Execution Scope) for use as new unit of planning in 'device' planning This is the first step in apache/tvm-rfcs#38 to bring devices and targets together when doing device planning. I've gone ahead and also included a memory scope in this object since we will also need to propagate memory scopes across Relay expressions once this basic preparation is in place. In the meantime that field will be left as "". Once device planning works in units of SEScopes it will be possible to directly read off the device and target for any Relay sub-expression without the need for TargetMaps ort the construction of default Targets. SEScopes also support 'Join' and 'Default' operations needed when constraint solving in the device planner. You can see those in use in my scratchpad branch: https://github.com/mbs-octoml/mbs-tvm/tree/mbs-scopes This PR also brings some duplicated and the ad-hoc 'default target' handling logic together into a CompilationConfig class. (Again, see the scratchpad branch for how that will end up being used). I've placed that next to SEScope since it's main purpose is to a) establish the default SEScope for primitive ops b) establish the SEScope for the 'host' c) feed a definitive vector of Targets into device planning so it can resolve all "on_device" and "device_copy" device references to their full SEScope form.
- Loading branch information
1 parent
63f1375
commit dfbb253
Showing
58 changed files
with
2,423 additions
and
1,931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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/relay/attrs/on_device.h | ||
* \brief Attribute for the on device annotation. | ||
*/ | ||
#ifndef TVM_RELAY_ATTRS_ON_DEVICE_H_ | ||
#define TVM_RELAY_ATTRS_ON_DEVICE_H_ | ||
|
||
#include <tvm/ir/attrs.h> | ||
#include <tvm/target/se_scope.h> | ||
|
||
#include <string> | ||
|
||
namespace tvm { | ||
namespace relay { | ||
|
||
/*! | ||
* \brief Attributes for the "on_device" special operator. | ||
* | ||
* The Relay call (aka 'annotation'): | ||
* \code | ||
* on_device(sub_expr, se_scope=S) | ||
* \endcode | ||
* constrains \p sub_expr to execute and store its result on the \p SEScope \p S. | ||
* However the annotation itself may appear in an expression to be executed and stored on a | ||
* different \p SEScope. If so the compiler will automatically insert a "device_copy" call to | ||
* mediate the transition between \p SEScopes. | ||
* | ||
* E.g.: Assuming %x and %y reside on the GPU and %z on the CPU then: | ||
* \code | ||
* multiply(on_device(add(%x, %y), se_scope=GPU), %z) | ||
* \endcode | ||
* indicates the \p add should execute on the GPU but the \p multiply should execute on the CPU. | ||
* The compiler will rewrite this to: | ||
* \code | ||
* multiply(device_copy(add(%x, %y), src_se_scope=GPU, dst_se_scope=CPU), %z) | ||
* \endcode | ||
* | ||
* The Relay call | ||
* \code | ||
* on_device(sub_expr, se_scope=S, is_fixed=True) | ||
* \endcode | ||
* is similar to the above, however the annotation itself must appear in an expression on the | ||
* same \p SEScope \p S. The compiler will check the \p SEScopes are consistent, and will not | ||
* insert any "device_copy" call. This form of annotation shouldn't be necessary in user programs. | ||
* However it is needed by the \p PlanDevices pass to fully specify the results of device planning | ||
* so that the pass is idempotent. | ||
* | ||
* E.g.: The following program is equivalent to the above: | ||
* \code | ||
* let %a = on_device(add(%x, %y), se_scope=GPU, is_fixed=True) | ||
* multiply(device_copy(%a, src_se_scope=GPU, dst_se_scope=CPU), %z) | ||
* \endcode | ||
* The "on_device" annotation with \p is_fixed=True indicates unambiguously that \p %a is stored | ||
* on the GPU. | ||
*/ | ||
struct OnDeviceAttrs : public tvm::AttrsNode<OnDeviceAttrs> { | ||
/*! | ||
* \brief (Virtual) \p SEScope on which the result of the argument expression should be stored. | ||
*/ | ||
SEScope se_scope = SEScope::FullyUnconstrained(); | ||
/*! | ||
* \brief If true, the result \p SEScope must also be \p se_scope, and device planning should | ||
* not insert any "device_copy" calls to respect this annotation. | ||
* | ||
* This is used by the device planning pass itself when annotating the planned program. | ||
*/ | ||
bool is_fixed = false; | ||
|
||
TVM_DECLARE_ATTRS(OnDeviceAttrs, "relay.attrs.OnDeviceAttrs") { | ||
TVM_ATTR_FIELD(se_scope) | ||
.describe("The (virtual) device and scope holding the expression result.") | ||
.set_default(SEScope::FullyUnconstrained()); | ||
TVM_ATTR_FIELD(is_fixed) | ||
.describe("If true, do not insert a \"device_copy\" call to respect this annotation.") | ||
.set_default(false); | ||
} | ||
}; | ||
|
||
} // namespace relay | ||
} // namespace tvm | ||
|
||
#endif // TVM_RELAY_ATTRS_ON_DEVICE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.