You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/09/01 09:31:29 UTC

[GitHub] [tvm] jroesch opened a new pull request #8892: [Lowering] Add TargetDevice composite data structure.

jroesch opened a new pull request #8892:
URL: https://github.com/apache/tvm/pull/8892


   This adds a new data structure which captures both the target and device as a composite data structure, see the comments for more motivation. The idea here is to enable us to track same device types with different targets. For example we could deal with ARM core with different targets for different CPUs, GPU, and NPU. 
   
   cc @junrushao1994 @areusch @mbs-octoml @csullivan @adstraw @manupa-arm @Mousius 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] manupa-arm commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-932020564


   Hi @jroesch ,
   
   I finally manage to get some time to read this :). I think code looks generally good modulo the comments. 
   
   I have a broad design question.
   
   At which phase, would we be doing the partitioning of devices for same kind ?
   Confusingly, at the minute we have two annotation (one in the BYOC pipeline) and one internally in the relay lowering pipeline.
   [Related PRs and discussion : https://github.com/apache/tvm/pull/7428 and https://discuss.tvm.apache.org/t/rfc-composite-target/7744/10? -- cc: @mbs-octoml ]
   
   The strategy we are using in the annotation target pass (of the BYOC pipeline -- it does not really need to be just a BYOC thing), is we greedily partition the Relay OPs given the knowledge that some target kinds are better in processing them.
   
   Therefore, this is a step beyond that where we have to deal with multiple devices of same kind and brings algorithmic problem of load balancing between devices. I appreciate that it can be a complex problem; however, my immediate question is what is the initial strategy that is being planned to use this from an annotation point of view ?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch edited a comment on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch edited a comment on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910036578


   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   @junrushao1994 how do you propose to infer the two-different-CPUs or two-different-FPGAs case? Also see my comments on the commentary at the top of target_device.cc. My thoughts are that being explicit at this level will provide a better user experience. I don't think it removes our ability to infer devices based on Target when there is no ambiguity, and it provides us a language in which we can warn the user when ambiguity exists.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch edited a comment on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch edited a comment on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910036578


   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   @junrushao1994 how do you propose to infer the two-different-CPUs or two-different-FPGAs case? Also see my comments on the commentary at the top of target_device.cc. My thoughts are that being explicit at this level will provide a better user experience. I don't think it removes our ability to infer devices based on Target when there is no ambiguity, and it provides us a language in which we can warn the user when ambiguity exists.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910036578


   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   @junrushao1994 how do you propose to infer the two-different-CPUs case?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Mousius commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
Mousius commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910458796


   >  Is idea of TargetDevice to replace both Target and Device? And if we do replace Target with TargetDevice, how will we indicate that the Target for an expression has been set but not the Device? Thanks :)
   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   These two comments together make me wonder if the correct mapping is directly from `Target` -> `Device` and from `TargetKind` to `DeviceType` rather than introducing a new structure?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-909733923


   Hey Jared, thanks for the PR!
   
   I understand the design of the virtual device id and it looks good to me if there are some use cases of it (usually we just assume it’s 0).
   
   On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-941525577


   @mbs-octoml seems you are taking this on so i will close this PR. @jroesch can feel free to reopen if he has cycles to push it through.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch closed pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch closed pull request #8892:
URL: https://github.com/apache/tvm/pull/8892


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-941525577


   @mbs-octoml seems you are taking this on so i will close this PR. @jroesch can feel free to reopen if he has cycles to push it through.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910036578


   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   @junrushao1994 how do you propose to infer the two-different-CPUs case?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r699958361



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical

Review comment:
       clean up this sentence a bit: 
   ```suggestion
    * Before inference, executors should map virtual device identifiers (included in the executor config) to physical
      device identifiers (e.g. DLDevice)
   ```

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,

Review comment:
       this isn't a file-level comment and belongs on the docstring for TargetDevice

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,

Review comment:
       i think just two CPU types is sufficient here

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we

Review comment:
       I kind of agree with this, but it requires a lot of other contextual information to understand things like the reach and purpose of this data structure. Specifically, it would be great to assume the reader does not understand the distinction between "concrete device" and "target" here (or explain it).
   
   I think you could say something like:
   ```
   This data structure defines a compile-time identifier for one of the devices specified in the Target. For instance, a Target string `cuda --target-host=llvm -mcpu=i386` requires the compiler to track two such devices: the GPU used by CUDA and the CPU targeted by LLVM. Before this data structure, the two different devices were configured by the runtime by finding a user-specified `DLDevice` whose `device_type` field matches the Target. More complex deployment scenarios can't be modeled coherently across compiler and runtime in this system without aliasing in the target string:
    * two of any `device_type` with differing capabilities
    * reconfigurable devices (e.g. FPGA) for which TVM requires two distinct configurations
    * devices with memory constraints (which need to be expressed in terms of a specific, but unresolved-at-compile-time DLDevice)
   ```

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,
+ * as well as NPU accelerator. It is important in these cases for us to be able to
+ * correctly partition the code for each device type and apply different compilation
+ * strategies.
+ *
+ * Today the compiler maps each device "type" to a single target, which does not work
+ * when you have multiple types of CPUs, GPUs or accelerators attached.
+ */
+#ifndef TVM_TARGET_TARGET_DEVICE_H_
+#define TVM_TARGET_TARGET_DEVICE_H_
+
+#include <tvm/ir/expr.h>
+#include <tvm/ir/module.h>
+#include <tvm/node/node.h>
+#include <tvm/support/with.h>
+#include <tvm/target/target.h>
+
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace tvm {
+
+class TargetDevice;

Review comment:
       TargetDevice makes sense in context of your previous explanation but not out of context. Can we pick a different name? I suggest we consider names that reflect the identifier used e.g. DeviceName or VirtualDevice or CompileTimeDevice. 
   
   I also prefer a string identifier so it can be given by the user or SDK authors. We can register these strings at runtime or produce enums if efficiency is a concern, but specifying memory layouts with respect to a virtual device id already seems obnoxious AF. I vastly prefer `"dsp-cpu"` over `1`.

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,
+ * as well as NPU accelerator. It is important in these cases for us to be able to
+ * correctly partition the code for each device type and apply different compilation
+ * strategies.
+ *
+ * Today the compiler maps each device "type" to a single target, which does not work
+ * when you have multiple types of CPUs, GPUs or accelerators attached.
+ */
+#ifndef TVM_TARGET_TARGET_DEVICE_H_
+#define TVM_TARGET_TARGET_DEVICE_H_
+
+#include <tvm/ir/expr.h>
+#include <tvm/ir/module.h>
+#include <tvm/node/node.h>
+#include <tvm/support/with.h>
+#include <tvm/target/target.h>
+
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace tvm {
+
+class TargetDevice;
+
+/*!
+ * \brief A representation of both the compile time and runtime data structure needed to represent a device.
+ * \sa TargetDevice
+ */
+class TargetDeviceNode : public Object {
+ public:
+  /*! \brief The compilation target to use for the device.  */
+  Target target;
+
+  /*! \brief The virtual device idenitfier which must be resolved to a physical device identifier before execution. */
+  int virtual_device_id;
+
+  /*! \brief The device type. */
+  DLDeviceType device_type;
+
+
+  void VisitAttrs(AttrVisitor* v) {
+    v->Visit("target", &target);
+    v->Visit("virtual_device_id", &virtual_device_id);
+    DLDeviceType* ptr = &device_type;
+    v->Visit("device_type", reinterpret_cast<int*>(ptr));

Review comment:
       why int*?

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the

Review comment:
       explain what "inject explicit virtual devices" means--are you placing this structure as an attribute in the program, or just the id, or ? How should this structure be identified, in general?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] electriclilies commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
electriclilies commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r699737446



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete

Review comment:
       Can you expand on what you mean by a virtual identifier?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-909733923


   Hey Jared, thanks for the PR!
   
   I understand the design of the virtual device id and it looks good to me if there are some use cases of it (usually we just assume it’s 0).
   
   On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mbs-octoml commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
mbs-octoml commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r700391213



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we

Review comment:
       BTW I owe you all an RFC to both justify this and bring together the threads on target maps, default targets, and unified target/device/memory scope planning.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Mousius edited a comment on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
Mousius edited a comment on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-910458796


   >  Is idea of TargetDevice to replace both Target and Device? And if we do replace Target with TargetDevice, how will we indicate that the Target for an expression has been set but not the Device? Thanks :)
   
   > On the other hand, there is direct correspondence between TargetKind to DLDeviceType, e.g. https://github.com/apache/tvm/blob/main/src/target/target_kind.cc#L278. So shall we just infer it from TargetNode::kind?
   
   These two comments together make me wonder if the correct mapping is directly from `Target` -> `Device` and from `TargetKind` to `DeviceType` rather than introducing a new structure?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mbs-octoml commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
mbs-octoml commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-932276723


   The RFC I promised in https://github.com/apache/tvm/pull/8892#discussion_r700391213 is now at up at https://github.com/apache/tvm-rfcs/pull/38


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch closed pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch closed pull request #8892:
URL: https://github.com/apache/tvm/pull/8892


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
areusch commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r699958361



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical

Review comment:
       clean up this sentence a bit: 
   ```suggestion
    * Before inference, executors should map virtual device identifiers (included in the executor config) to physical
      device identifiers (e.g. DLDevice)
   ```

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,

Review comment:
       this isn't a file-level comment and belongs on the docstring for TargetDevice

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,

Review comment:
       i think just two CPU types is sufficient here

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we

Review comment:
       I kind of agree with this, but it requires a lot of other contextual information to understand things like the reach and purpose of this data structure. Specifically, it would be great to assume the reader does not understand the distinction between "concrete device" and "target" here (or explain it).
   
   I think you could say something like:
   ```
   This data structure defines a compile-time identifier for one of the devices specified in the Target. For instance, a Target string `cuda --target-host=llvm -mcpu=i386` requires the compiler to track two such devices: the GPU used by CUDA and the CPU targeted by LLVM. Before this data structure, the two different devices were configured by the runtime by finding a user-specified `DLDevice` whose `device_type` field matches the Target. More complex deployment scenarios can't be modeled coherently across compiler and runtime in this system without aliasing in the target string:
    * two of any `device_type` with differing capabilities
    * reconfigurable devices (e.g. FPGA) for which TVM requires two distinct configurations
    * devices with memory constraints (which need to be expressed in terms of a specific, but unresolved-at-compile-time DLDevice)
   ```

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,
+ * as well as NPU accelerator. It is important in these cases for us to be able to
+ * correctly partition the code for each device type and apply different compilation
+ * strategies.
+ *
+ * Today the compiler maps each device "type" to a single target, which does not work
+ * when you have multiple types of CPUs, GPUs or accelerators attached.
+ */
+#ifndef TVM_TARGET_TARGET_DEVICE_H_
+#define TVM_TARGET_TARGET_DEVICE_H_
+
+#include <tvm/ir/expr.h>
+#include <tvm/ir/module.h>
+#include <tvm/node/node.h>
+#include <tvm/support/with.h>
+#include <tvm/target/target.h>
+
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace tvm {
+
+class TargetDevice;

Review comment:
       TargetDevice makes sense in context of your previous explanation but not out of context. Can we pick a different name? I suggest we consider names that reflect the identifier used e.g. DeviceName or VirtualDevice or CompileTimeDevice. 
   
   I also prefer a string identifier so it can be given by the user or SDK authors. We can register these strings at runtime or produce enums if efficiency is a concern, but specifying memory layouts with respect to a virtual device id already seems obnoxious AF. I vastly prefer `"dsp-cpu"` over `1`.

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,
+ * as well as NPU accelerator. It is important in these cases for us to be able to
+ * correctly partition the code for each device type and apply different compilation
+ * strategies.
+ *
+ * Today the compiler maps each device "type" to a single target, which does not work
+ * when you have multiple types of CPUs, GPUs or accelerators attached.
+ */
+#ifndef TVM_TARGET_TARGET_DEVICE_H_
+#define TVM_TARGET_TARGET_DEVICE_H_
+
+#include <tvm/ir/expr.h>
+#include <tvm/ir/module.h>
+#include <tvm/node/node.h>
+#include <tvm/support/with.h>
+#include <tvm/target/target.h>
+
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace tvm {
+
+class TargetDevice;
+
+/*!
+ * \brief A representation of both the compile time and runtime data structure needed to represent a device.
+ * \sa TargetDevice
+ */
+class TargetDeviceNode : public Object {
+ public:
+  /*! \brief The compilation target to use for the device.  */
+  Target target;
+
+  /*! \brief The virtual device idenitfier which must be resolved to a physical device identifier before execution. */
+  int virtual_device_id;
+
+  /*! \brief The device type. */
+  DLDeviceType device_type;
+
+
+  void VisitAttrs(AttrVisitor* v) {
+    v->Visit("target", &target);
+    v->Visit("virtual_device_id", &virtual_device_id);
+    DLDeviceType* ptr = &device_type;
+    v->Visit("device_type", reinterpret_cast<int*>(ptr));

Review comment:
       why int*?

##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the

Review comment:
       explain what "inject explicit virtual devices" means--are you placing this structure as an attribute in the program, or just the id, or ? How should this structure be identified, in general?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Mousius commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r700376890



##########
File path: src/target/target_device.cc
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+/*!
+ * \brief The implementation of the TargetDevice object for representing compilation target + virtual device.

Review comment:
       Similarly here, re-order to `\file` then `\brief`

##########
File path: python/tvm/relay/transform/transform.py
##########
@@ -728,13 +728,18 @@ def PartitionGraph(mod_name="default"):
 
 
 def AnnotateTarget(targets, include_non_call_ops=True):
-    """Annotate ops in an experession with a provied compiler/target and then
-    use it for codegen.
+    """
+    The annotate the operations in an expression with the provided compiler target

Review comment:
       ```suggestion
       Annotate the operations in an expression with the provided compiler target,
   ```

##########
File path: src/target/target.cc
##########
@@ -17,7 +17,7 @@
  * under the License.
  */
 /*!
- *  Compile executable modules.
+ * \brief Implementation of methods, and FFI interfaces for the compilation target object.

Review comment:
       Really minor nit, can you do `\file` then `\brief` ?

##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -204,6 +204,10 @@ using FForwardRewrite = TypedPackedFunc<Expr(const Call& ref_call, const Array<E
 //----------------------------------------------
 class ForwardPrep : private MixedModeVisitor {
  public:
+  // This is needed to silence a clang-warning about not correclty detecting

Review comment:
       ```suggestion
     // This is needed to silence a clang-warning about not correctly detecting
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Mousius commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r700382993



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete
+ * device type.
+ *
+ * Executors are required to handle how to map virtual device identifiers to physical
+ * device identifiers.
+ *
+ * The reason to introduce this data structure is that for much of compilation we
+ * require understanding both of the target that we plan to compile the code for
+ * as well as the concrete device which is used to initiate copies and other
+ * device API actions.
+ *
+ * The idea is that we will carry around TargetDevice structures until device and
+ * target planning at which time we can inject explicit virtual devices in the
+ * program, and annotate explicit targets on the code to be generated.
+ *
+ * This will enable us to mix and match multiple devices of the same type with
+ * different targets or compilation options, and eventually resolve to a phyical
+ * set of devices with code specialized using the correct target.
+ *
+ * For example consider mobile SoCs which may contain two CPU types, a mobile GPU,
+ * as well as NPU accelerator. It is important in these cases for us to be able to
+ * correctly partition the code for each device type and apply different compilation
+ * strategies.
+ *
+ * Today the compiler maps each device "type" to a single target, which does not work
+ * when you have multiple types of CPUs, GPUs or accelerators attached.
+ */
+#ifndef TVM_TARGET_TARGET_DEVICE_H_
+#define TVM_TARGET_TARGET_DEVICE_H_
+
+#include <tvm/ir/expr.h>
+#include <tvm/ir/module.h>
+#include <tvm/node/node.h>
+#include <tvm/support/with.h>
+#include <tvm/target/target.h>
+
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace tvm {
+
+class TargetDevice;

Review comment:
       Potentially it's worth adding a default attribute to `Target` which is `alias` rather than adding it to this structure?
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] electriclilies commented on a change in pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
electriclilies commented on a change in pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#discussion_r699737446



##########
File path: include/tvm/target/target_device.h
##########
@@ -0,0 +1,118 @@
+/*
+ * 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/target/target_device.h
+ * \brief A compile time representation of a target device.
+ *
+ * This data structure consists of both the compiler target and a virtual device,
+ * a tvm::Device where the the identifier is a virtual identifier and a concrete

Review comment:
       Can you expand on what you mean by a virtual identifier?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mbs-octoml commented on pull request #8892: [Lowering] Add TargetDevice composite data structure.

Posted by GitBox <gi...@apache.org>.
mbs-octoml commented on pull request #8892:
URL: https://github.com/apache/tvm/pull/8892#issuecomment-939154077


   I've merged this PR into my exploration and suggest we withdraw it from here.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org