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