Skip to content

Commit

Permalink
[Relay] s/SEScope/VirtualDevice/g (apache#9759)
Browse files Browse the repository at this point in the history
* [Relay] s/SEScope/VirtualDevice/g

Nobody liked 'SEScope', and 'DeviceMcDeviceFace' is too verbose, so it
seems 'VirtualDevice' has the popular vote.
  • Loading branch information
mbs-octoml authored and ylc committed Jan 13, 2022
1 parent 9465da8 commit 4281a30
Show file tree
Hide file tree
Showing 59 changed files with 1,514 additions and 1,424 deletions.
14 changes: 7 additions & 7 deletions include/tvm/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace tvm {

using tvm::runtime::String;

// Forward-declare SEScope to avoid circular imports.
class SEScope;
// Forward-declare VirtualDevice to avoid circular imports.
class VirtualDevice;

/*!
* \brief Base type of all the expressions.
Expand Down Expand Up @@ -169,7 +169,7 @@ class RelayExprNode : public BaseExprNode {
inline const TTypeNode* type_as() const;

/*!
* \brief The virtual device (SEScope) for this node (the result of device planning).
* \brief The virtual device (VirtualDevice) for this node (the result of device planning).
* For first-order expressions (non functions), this describes where the result of evaluating the
* expression should be stored. Note that currently, all composite first-order values (tuples,
* references, ADTs) must be stored on the same virtual device. This means that it is not possible
Expand All @@ -178,18 +178,18 @@ class RelayExprNode : public BaseExprNode {
*
* For expressions that have the function type, the virtual device describes where the result of
* the call to the function or closure is stored (instead of where the function itself is stored).
* The SEScope's Target field describes how the body of the function should be compiled.
* The VirtualDevice's Target field describes how the body of the function should be compiled.
*
* \note Unfortunately, the type of virtual_device_ needs to be ObjectRef to avoid a circular
* import.
*/
mutable ObjectRef virtual_device_;

/*!
* \return The virtual device (SEScope).
* If the virtual device is not defined, returns SEScope::FullyUnconstrained().
* \return The virtual device (VirtualDevice).
* If the virtual device is not defined, returns VirtualDevice::FullyUnconstrained().
*/
SEScope virtual_device() const;
VirtualDevice virtual_device() const;

static constexpr const char* _type_key = "RelayExpr";
static constexpr const uint32_t _type_child_slots = 22;
Expand Down
12 changes: 6 additions & 6 deletions include/tvm/ir/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,24 @@ constexpr const char* kTarget = "target";
constexpr const char* kGlobalSymbol = "global_symbol";

/*!
* \brief The SEScope which will hold each of the functions parameters.
* \brief The \p VirtualDevice which will hold each of the functions parameters.
*
* Only supported on Relay \p Functions. Generally added by the \p PlanDevices pass, but
* may be included as an annotation on user programs.
*
* Type: Array<SEScope>
* Type: Array<VirtualDevice>
*/
constexpr const char* kParamSEScopes = "param_se_scopes";
constexpr const char* kParamVirtualDevice = "param_virtual_devices";

/*!
* \brief The SEScope which will hold the function result.
* \brief The \p VirtualDevice which will hold the function result.
*
* Only supported on Relay \p Functions. Generally added by the \p PlanDevices pass, but
* may be included as an annotation on user programs.
*
* Type: SEScope
* Type: VirtualDevice
*/
constexpr const char* kResultSEScope = "result_se_scope";
constexpr const char* kResultVirtualDevice = "result_virtual_device";

} // namespace attr
} // namespace tvm
Expand Down
10 changes: 5 additions & 5 deletions include/tvm/relay/attrs/device_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define TVM_RELAY_ATTRS_DEVICE_COPY_H_

#include <tvm/ir/attrs.h>
#include <tvm/target/se_scope.h>
#include <tvm/target/virtual_device.h>

#include <string>

Expand All @@ -36,13 +36,13 @@ namespace relay {
* \brief Options for the device copy operators.
*/
struct DeviceCopyAttrs : public tvm::AttrsNode<DeviceCopyAttrs> {
SEScope src_se_scope = SEScope::FullyUnconstrained();
SEScope dst_se_scope = SEScope::FullyUnconstrained();
VirtualDevice src_virtual_device = VirtualDevice::FullyUnconstrained();
VirtualDevice dst_virtual_device = VirtualDevice::FullyUnconstrained();

TVM_DECLARE_ATTRS(DeviceCopyAttrs, "relay.attrs.DeviceCopyAttrs") {
TVM_ATTR_FIELD(src_se_scope)
TVM_ATTR_FIELD(src_virtual_device)
.describe("The (virtual) device and scope where the op copies data from.");
TVM_ATTR_FIELD(dst_se_scope)
TVM_ATTR_FIELD(dst_virtual_device)
.describe("The (virtual) device and scope where the op copies data to.");
}
};
Expand Down
6 changes: 3 additions & 3 deletions include/tvm/relay/attrs/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <tvm/ir/attrs.h>
#include <tvm/relay/expr.h>
#include <tvm/target/se_scope.h>
#include <tvm/target/virtual_device.h>

#include <string>
#include <vector>
Expand All @@ -43,13 +43,13 @@ Expr ToTupleType(const Type& t, const std::vector<Expr>& exprs);
*/
struct AllocStorageAttrs : public tvm::AttrsNode<AllocStorageAttrs> {
DataType dtype;
SEScope se_scope = SEScope::FullyUnconstrained();
VirtualDevice virtual_device = VirtualDevice::FullyUnconstrained();

TVM_DECLARE_ATTRS(AllocStorageAttrs, "relay.attrs.AllocStorageAttrs") {
TVM_ATTR_FIELD(dtype)
.describe("The dtype of the tensor to allocate.")
.set_default(DataType::Float(32, 1));
TVM_ATTR_FIELD(se_scope).describe("The SEScope on which to allocate memory.");
TVM_ATTR_FIELD(virtual_device).describe("The virtual device on which to allocate memory.");
}
};

Expand Down
29 changes: 15 additions & 14 deletions include/tvm/relay/attrs/on_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define TVM_RELAY_ATTRS_ON_DEVICE_H_

#include <tvm/ir/attrs.h>
#include <tvm/target/se_scope.h>
#include <tvm/target/virtual_device.h>

#include <string>

Expand All @@ -37,42 +37,43 @@ namespace relay {
*
* The Relay call:
* \code
* on_device(sub_expr, se_scope=S)
* on_device(sub_expr, virtual_device=S)
* \endcode
* constrains \p sub_expr to execute and store its result on the \p SEScope \p S.
* constrains \p sub_expr to execute and store its result on the \p VirtualDevice \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.
* different \p VirtualDevice. If so the compiler will automatically insert a "device_copy" call to
* mediate the transition between \p VirtualDevices.
*
* 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)
* multiply(on_device(add(%x, %y), virtual_device=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)
* multiply(device_copy(add(%x, %y), src_virtual_device=GPU, dst_virtual_device=CPU), %z)
* \endcode
*
* The \p constraint_body (default true) and \p constraint_result (default false) fields can be
* used by passes for finer-grained control over how the \p SEScope constraint should be applied.
* used by passes for finer-grained control over how the \p VirtualDevice constraint should be
* applied.
*/
struct OnDeviceAttrs : public tvm::AttrsNode<OnDeviceAttrs> {
/*!
* \brief The \p SEScope to constraint to apply to the body, result, or both body and result
* \brief The \p VirtualDevice to constraint to apply to the body, result, or both body and result
* of the "on_device" call.
*/
SEScope se_scope = SEScope::FullyUnconstrained();
VirtualDevice virtual_device = VirtualDevice::FullyUnconstrained();

/*!
* \brief If false (the default), the result of the "on_device" call is not constrained to be
* \p se_scope.
* \p virtual_device.
*/
bool constrain_result = false;

/*!
* \brief If true (the default), the body of the "on_device" call is constrained to be \p
* se_scope.
* virtual_device.
*/
bool constrain_body = true;

Expand All @@ -87,9 +88,9 @@ struct OnDeviceAttrs : public tvm::AttrsNode<OnDeviceAttrs> {
bool is_normal() const { return !constrain_result && constrain_body; }

TVM_DECLARE_ATTRS(OnDeviceAttrs, "relay.attrs.OnDeviceAttrs") {
TVM_ATTR_FIELD(se_scope)
TVM_ATTR_FIELD(virtual_device)
.describe("The (virtual) device to constrain to.")
.set_default(SEScope::FullyUnconstrained());
.set_default(VirtualDevice::FullyUnconstrained());
TVM_ATTR_FIELD(constrain_result)
.describe("Whether the constraint applies to the overall expression")
.set_default(false);
Expand Down
20 changes: 10 additions & 10 deletions include/tvm/relay/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <tvm/ir/expr.h>
#include <tvm/ir/module.h>
#include <tvm/ir/op.h>
#include <tvm/target/se_scope.h>
#include <tvm/target/virtual_device.h>

#include <functional>
#include <stack>
Expand Down Expand Up @@ -158,7 +158,7 @@ class Tuple : public Expr {
* ret_tuple->span = tuple->span.
*/
Tuple WithFields(Tuple tuple, Optional<Array<Expr>> opt_fields = Optional<Array<Expr>>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*!
Expand Down Expand Up @@ -264,7 +264,7 @@ class Var : public Expr {
*/
Var WithFields(Var var, Optional<Id> opt_vid = Optional<Id>(),
Optional<Type> opt_type_annotation = Optional<Type>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*!
Expand Down Expand Up @@ -391,7 +391,7 @@ Call WithFields(Call call, Optional<Expr> opt_op = Optional<Expr>(),
Optional<Array<Expr>> opt_args = Optional<Array<Expr>>(),
Optional<Attrs> opt_attrs = Optional<Attrs>(),
Optional<Array<Type>> opt_type_args = Optional<Array<Type>>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*!
Expand Down Expand Up @@ -487,7 +487,7 @@ class Let : public Expr {
Let WithFields(Let let, Optional<Var> opt_var = Optional<Var>(),
Optional<Expr> opt_value = Optional<Expr>(),
Optional<Expr> opt_body = Optional<Expr>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*!
Expand Down Expand Up @@ -574,7 +574,7 @@ class If : public Expr {
If WithFields(If if_expr, Optional<Expr> opt_cond = Optional<Expr>(),
Optional<Expr> opt_true_branch = Optional<Expr>(),
Optional<Expr> opt_false_branch = Optional<Expr>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*! \brief Get index-th field out of a tuple. */
Expand Down Expand Up @@ -640,7 +640,7 @@ class TupleGetItem : public Expr {
*/
TupleGetItem WithFields(TupleGetItem tuple_get_item, Optional<Expr> opt_tuple = Optional<Expr>(),
Optional<Integer> opt_index = Optional<Integer>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*! \brief Create a new Reference out of initial value. */
Expand Down Expand Up @@ -701,7 +701,7 @@ class RefCreate : public Expr {
* ret_ref_create->value = opt_value.value()).
*/
RefCreate WithFields(RefCreate ref_create, Optional<Expr> opt_value = Optional<Expr>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*! \brief Get value out of Reference. */
Expand Down Expand Up @@ -761,7 +761,7 @@ class RefRead : public Expr {
* if opt_ref.value() != ref_read->ref, then ret_ref_read->ref = opt_ref.value()).
*/
RefRead WithFields(RefRead ref_read, Optional<Expr> opt_ref = Optional<Expr>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*! \brief Set value of Reference. The whole expression evaluates to an Empty Tuple. */
Expand Down Expand Up @@ -829,7 +829,7 @@ class RefWrite : public Expr {
*/
RefWrite WithFields(RefWrite ref_write, Optional<Expr> opt_ref = Optional<Expr>(),
Optional<Expr> opt_value = Optional<Expr>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*!
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/relay/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Function WithFields(Function function, Optional<Array<Var>> opt_params = Optiona
Optional<Type> opt_ret_type = Optional<Type>(),
Optional<Array<TypeVar>> opt_ty_params = Optional<Array<TypeVar>>(),
Optional<DictAttrs> opt_attrs = Optional<DictAttrs>(),
Optional<SEScope> opt_virtual_device = Optional<SEScope>(),
Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
Optional<Span> opt_span = Optional<Span>());

/*
Expand Down
14 changes: 7 additions & 7 deletions include/tvm/relay/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include <tvm/relay/op.h>
#include <tvm/relay/op_attr_types.h>
#include <tvm/target/compilation_config.h>
#include <tvm/target/se_scope.h>
#include <tvm/target/target.h>
#include <tvm/target/virtual_device.h>

#include <string>

Expand Down Expand Up @@ -449,22 +449,22 @@ TVM_DLL Pass RelayToTIRTargetHook();
* \brief A pass for manifesting explicit memory allocations and rewriting
* specific dialects.
*
* \param cpu_se_scope SEScope for computations and data which must reside on a CPU, such as
* shapes and shape functions.
* \param cpu_virtual_device VirtualDevice for computations and data which must reside on a CPU,
* such as shapes and shape functions.
*
* \return The pass.
*/
TVM_DLL Pass ManifestAlloc(SEScope cpu_se_scope);
TVM_DLL Pass ManifestAlloc(VirtualDevice cpu_virtual_device);

/*!
* \brief Uses existing "on_device" and "device_copy" CallNodes to infer the \p SEScope on which
* every Relay sub-expression should run and the result stored. Captures the result of that
* \brief Uses existing "on_device" and "device_copy" CallNodes to infer the \p VirtualDevice on
* which every Relay sub-expression should run and the result stored. Captures the result of that
* analysis using new "on_device" and "device_copy" CallNodes.
*
* See tvm::relay::transform::{LexicalOnDeviceMixin,DeviceAwareExprVisitor,DeviceAwareExprMutator}
* for help recovering the device for an arbitrary sub-expression in downstream transformations.
*
* \param config Describes the targets and default \p SEScope for all primitive operators and
* \param config Describes the targets and default \p VirtualDevice for all primitive operators and
* host sub-expressions.
*
* \return The pass.
Expand Down
Loading

0 comments on commit 4281a30

Please sign in to comment.