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