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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to