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/05/19 22:05:58 UTC

[GitHub] [tvm] Lunderberg opened a new pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

Lunderberg opened a new pull request #8082:
URL: https://github.com/apache/tvm/pull/8082


   Goal for this commit was to give high-level documentation on what parts of the TVM codebase are specific to a particular hardware or API, and what common interface they implement.


-- 
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.

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



[GitHub] [tvm] Lunderberg commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who

Review comment:
       Change made, to be pushed shortly.




-- 
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.

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



[GitHub] [tvm] csullivan commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who

Review comment:
       ```suggestion
   how the TVM framework interacts with specific device APIs, or who
   ```

##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier

Review comment:
       ```suggestion
     exposed both to the target code generators and to the
   ```
   In principle the target can be used in any pass, and also I would expect later passes to be more target specific. So maybe best to avoid a relative qualifier here?

##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier
+  optimization passes.
+
+* The :ref:`target code generators <tvm-target-specific-codegen>`
+  construct a :ref:`Module <tvm-runtime-system-module>` consisting of
+  one or more :ref:`PackedFunc <tvm-runtime-system-packed-func>`, from
+  an IRModule.
+
+.. _tvm-target-specific-device-api:
+
+DeviceAPI
+---------
+
+The ``DeviceAPI`` represents a handle to a specific device.  In
+Python, these can be constructed using the
+:py:func:`tvm.runtime.device` function.
+
+.. _device_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/device_api.h
+
+* Attribute queries - ``GetAttr`` allows different
+  device-specific parameters to be queried, such as the device name,
+  number of threads, etc.  The parameters that can be queried are
+  defined in ``enum DeviceAttrKind`` in `device_api.h`_.  Not all
+  query-able parameters are supported by all devices.  If a parameter
+  cannot be queried (e.g. ``kMaxClockRate`` on Vulkan), or if a
+  parameter isn't applicable (e.g. ``kWarpSize`` on CPU), then those
+  queries should return ``nullptr``.
+
+* Setting active device - ``SetDevice`` should set a
+  particular device as being active.  If a ``PackedFunc`` generated by
+  the target-specific code gen requires execution on a device, it
+  should run on the active device.
+
+* Memory management - Utilities for allocating and deallocating memory
+  on the device.
+
+  * Allocate data space - ``AllocDataSpace`` and ``FreeDataSpace``
+    allocate and free space on the device.  It must be possible to
+    transfer data from the host to/from a data space.  The return
+    value is an opaque ``void*``, and will be passed unmodified into
+    other target-specific functions.

Review comment:
       It might also be worth noting that the pointer returned by the device API may be an opaque handle interpretable by the specific device backend only.

##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier
+  optimization passes.
+
+* The :ref:`target code generators <tvm-target-specific-codegen>`
+  construct a :ref:`Module <tvm-runtime-system-module>` consisting of
+  one or more :ref:`PackedFunc <tvm-runtime-system-packed-func>`, from
+  an IRModule.
+
+.. _tvm-target-specific-device-api:
+
+DeviceAPI
+---------
+
+The ``DeviceAPI`` represents a handle to a specific device.  In
+Python, these can be constructed using the
+:py:func:`tvm.runtime.device` function.
+
+.. _device_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/device_api.h
+
+* Attribute queries - ``GetAttr`` allows different
+  device-specific parameters to be queried, such as the device name,
+  number of threads, etc.  The parameters that can be queried are
+  defined in ``enum DeviceAttrKind`` in `device_api.h`_.  Not all
+  query-able parameters are supported by all devices.  If a parameter
+  cannot be queried (e.g. ``kMaxClockRate`` on Vulkan), or if a
+  parameter isn't applicable (e.g. ``kWarpSize`` on CPU), then those
+  queries should return ``nullptr``.
+
+* Setting active device - ``SetDevice`` should set a
+  particular device as being active.  If a ``PackedFunc`` generated by
+  the target-specific code gen requires execution on a device, it
+  should run on the active device.
+
+* Memory management - Utilities for allocating and deallocating memory
+  on the device.
+
+  * Allocate data space - ``AllocDataSpace`` and ``FreeDataSpace``
+    allocate and free space on the device.  It must be possible to
+    transfer data from the host to/from a data space.  The return
+    value is an opaque ``void*``, and will be passed unmodified into
+    other target-specific functions.
+
+  * Allocate work space - ``AllocWorkspace`` and ``FreeWorkspace``
+    allocate and free space on the device.  Unlike data space, these
+    are used for storage of intermediate values, and are not required
+    to be transferable to/from the host device.  If a ``DeviceAPI``

Review comment:
       ```suggestion
       allocate and free space on the device.  Unlike data space, these
       are used for storage of intermediate values within an operator 
       definition, and are not able to be transferable to/from the 
       host device.  If a ``DeviceAPI``
   ```

##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier
+  optimization passes.
+
+* The :ref:`target code generators <tvm-target-specific-codegen>`
+  construct a :ref:`Module <tvm-runtime-system-module>` consisting of
+  one or more :ref:`PackedFunc <tvm-runtime-system-packed-func>`, from
+  an IRModule.
+
+.. _tvm-target-specific-device-api:
+
+DeviceAPI
+---------
+
+The ``DeviceAPI`` represents a handle to a specific device.  In
+Python, these can be constructed using the
+:py:func:`tvm.runtime.device` function.
+
+.. _device_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/device_api.h
+
+* Attribute queries - ``GetAttr`` allows different
+  device-specific parameters to be queried, such as the device name,
+  number of threads, etc.  The parameters that can be queried are
+  defined in ``enum DeviceAttrKind`` in `device_api.h`_.  Not all
+  query-able parameters are supported by all devices.  If a parameter
+  cannot be queried (e.g. ``kMaxClockRate`` on Vulkan), or if a
+  parameter isn't applicable (e.g. ``kWarpSize`` on CPU), then those
+  queries should return ``nullptr``.
+
+* Setting active device - ``SetDevice`` should set a
+  particular device as being active.  If a ``PackedFunc`` generated by
+  the target-specific code gen requires execution on a device, it
+  should run on the active device.
+
+* Memory management - Utilities for allocating and deallocating memory
+  on the device.
+
+  * Allocate data space - ``AllocDataSpace`` and ``FreeDataSpace``
+    allocate and free space on the device.  It must be possible to
+    transfer data from the host to/from a data space.  The return
+    value is an opaque ``void*``, and will be passed unmodified into
+    other target-specific functions.

Review comment:
       ```suggestion
       allocate and free space on the device. These allocations can be provided 
       as inputs and outputs to an operator and make up the primary data flow
       of the operator graph. It must be possible to
       transfer data from the host to/from a data space.  The return
       value is an opaque ``void*``, and will be passed unmodified into
       other target-specific functions.
   ```
   
   DataSpace APIs allocate and free graph operator output tensors. Data space allocations may be graph intermediates, or graph outputs, and in the latter case they will be read from directly as you state.

##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a

Review comment:
       The github RTF markdown preview for `:ref:` doesn't seem to be parsing as expected




-- 
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.

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



[GitHub] [tvm] masahi merged pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #8082:
URL: https://github.com/apache/tvm/pull/8082


   


-- 
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.

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



[GitHub] [tvm] Lunderberg commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier
+  optimization passes.
+
+* The :ref:`target code generators <tvm-target-specific-codegen>`
+  construct a :ref:`Module <tvm-runtime-system-module>` consisting of
+  one or more :ref:`PackedFunc <tvm-runtime-system-packed-func>`, from
+  an IRModule.
+
+.. _tvm-target-specific-device-api:
+
+DeviceAPI
+---------
+
+The ``DeviceAPI`` represents a handle to a specific device.  In
+Python, these can be constructed using the
+:py:func:`tvm.runtime.device` function.
+
+.. _device_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/device_api.h
+
+* Attribute queries - ``GetAttr`` allows different
+  device-specific parameters to be queried, such as the device name,
+  number of threads, etc.  The parameters that can be queried are
+  defined in ``enum DeviceAttrKind`` in `device_api.h`_.  Not all
+  query-able parameters are supported by all devices.  If a parameter
+  cannot be queried (e.g. ``kMaxClockRate`` on Vulkan), or if a
+  parameter isn't applicable (e.g. ``kWarpSize`` on CPU), then those
+  queries should return ``nullptr``.
+
+* Setting active device - ``SetDevice`` should set a
+  particular device as being active.  If a ``PackedFunc`` generated by
+  the target-specific code gen requires execution on a device, it
+  should run on the active device.
+
+* Memory management - Utilities for allocating and deallocating memory
+  on the device.
+
+  * Allocate data space - ``AllocDataSpace`` and ``FreeDataSpace``
+    allocate and free space on the device.  It must be possible to
+    transfer data from the host to/from a data space.  The return
+    value is an opaque ``void*``, and will be passed unmodified into
+    other target-specific functions.
+
+  * Allocate work space - ``AllocWorkspace`` and ``FreeWorkspace``
+    allocate and free space on the device.  Unlike data space, these
+    are used for storage of intermediate values, and are not required
+    to be transferable to/from the host device.  If a ``DeviceAPI``

Review comment:
       Makes sense, changed.




-- 
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.

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



[GitHub] [tvm] csullivan commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a

Review comment:
       The github RTF markdown preview for `:ref:` doesn't seem to be parsing as expected




-- 
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.

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



[GitHub] [tvm] Lunderberg commented on pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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


   Potential reviewers: @hogepodge for general documentation updates, @zxybazh for `Target`-specific documentation.


-- 
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.

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



[GitHub] [tvm] hogepodge commented on pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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


   Just gave it a read-through. I'm not an expert in this part of the code, but the documentation looks clear and really well organized. Thank you for writing it up!
   


-- 
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.

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



[GitHub] [tvm] zxybazh commented on pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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


   Thanks @Lunderberg for adding the detailed documentation. I am not familiar with the tvm device part but the tvm target part looks good to me. Just to point out, the canonical and suggested way to create target is to use a json object like `tvm.target.Target(‘{“kind”:”cuda”, “host”:”llvm”}’)`.


-- 
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.

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



[GitHub] [tvm] Lunderberg commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier

Review comment:
       Makes sense, update made.




-- 
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.

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



[GitHub] [tvm] Lunderberg commented on a change in pull request #8082: [Docs] Added developer documentation for DeviceAPI and Target.

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



##########
File path: docs/dev/device_target_interactions.rst
##########
@@ -0,0 +1,227 @@
+..  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.
+
+.. _tvm-target-specific-overview:
+
+Device/Target Interactions
+--------------------------
+
+This documented is intended for developers interested in understanding
+how the TVM framework interacts with specific API interacts, or who
+may want to implement support for a new API or new hardware.
+
+There are three main aspects that must be implemented for any new
+runtime environment.
+
+* The :ref:`DeviceAPI <tvm-target-specific-device-api>` class gives a
+  handle to a specific device, and the API used to interact with it.
+  It defines a common interface for querying device parameters
+  (e.g. memory available, number of threads, etc.) and for performing
+  simple actions (e.g. copying memory from the host, or between
+  buffers on the device).
+
+* The :ref:`Target <tvm-target-specific-target>` class contains a
+  description of the device on which a function will run.  It is
+  exposed both to the target code generators and to the earlier
+  optimization passes.
+
+* The :ref:`target code generators <tvm-target-specific-codegen>`
+  construct a :ref:`Module <tvm-runtime-system-module>` consisting of
+  one or more :ref:`PackedFunc <tvm-runtime-system-packed-func>`, from
+  an IRModule.
+
+.. _tvm-target-specific-device-api:
+
+DeviceAPI
+---------
+
+The ``DeviceAPI`` represents a handle to a specific device.  In
+Python, these can be constructed using the
+:py:func:`tvm.runtime.device` function.
+
+.. _device_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/device_api.h
+
+* Attribute queries - ``GetAttr`` allows different
+  device-specific parameters to be queried, such as the device name,
+  number of threads, etc.  The parameters that can be queried are
+  defined in ``enum DeviceAttrKind`` in `device_api.h`_.  Not all
+  query-able parameters are supported by all devices.  If a parameter
+  cannot be queried (e.g. ``kMaxClockRate`` on Vulkan), or if a
+  parameter isn't applicable (e.g. ``kWarpSize`` on CPU), then those
+  queries should return ``nullptr``.
+
+* Setting active device - ``SetDevice`` should set a
+  particular device as being active.  If a ``PackedFunc`` generated by
+  the target-specific code gen requires execution on a device, it
+  should run on the active device.
+
+* Memory management - Utilities for allocating and deallocating memory
+  on the device.
+
+  * Allocate data space - ``AllocDataSpace`` and ``FreeDataSpace``
+    allocate and free space on the device.  It must be possible to
+    transfer data from the host to/from a data space.  The return
+    value is an opaque ``void*``, and will be passed unmodified into
+    other target-specific functions.

Review comment:
       Changes make sense, and I added an explicit line that these may be opaque handles.




-- 
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.

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