RESOURCE_GROUPS.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. RESOURCE_GROUPS
  2. ---------------
  3. .. versionadded:: 3.16
  4. Specify resources required by a test, grouped in a way that is meaningful to
  5. the test. See :ref:`resource allocation <ctest-resource-allocation>`
  6. for more information on how this property integrates into the CTest resource
  7. allocation feature.
  8. The ``RESOURCE_GROUPS`` property is a :ref:`semicolon-separated list <CMake
  9. Language Lists>` of group descriptions. Each entry consists of an optional
  10. number of groups using the description followed by a series of resource
  11. requirements for those groups. These requirements (and the number of groups)
  12. are separated by commas. The resource requirements consist of the name of a
  13. resource type, followed by a colon, followed by an unsigned integer
  14. specifying the number of slots required on one resource of the given type.
  15. The ``RESOURCE_GROUPS`` property tells CTest what resources a test expects
  16. to use grouped in a way meaningful to the test. The test itself must read
  17. the :ref:`environment variables <ctest-resource-environment-variables>` to
  18. determine which resources have been allocated to each group. For example,
  19. each group may correspond to a process the test will spawn when executed.
  20. Consider the following example:
  21. .. code-block:: cmake
  22. add_test(NAME MyTest COMMAND MyExe)
  23. set_property(TEST MyTest PROPERTY RESOURCE_GROUPS
  24. "2,gpus:2"
  25. "gpus:4,crypto_chips:2")
  26. In this example, there are two group descriptions (implicitly separated by a
  27. semicolon.) The content of the first description is ``2,gpus:2``. This
  28. description specifies 2 groups, each of which requires 2 slots from a single
  29. GPU. The content of the second description is ``gpus:4,crypto_chips:2``. This
  30. description does not specify a group count, so a default of 1 is assumed.
  31. This single group requires 4 slots from a single GPU and 2 slots from a
  32. single cryptography chip. In total, 3 resource groups are specified for this
  33. test, each with its own unique requirements.
  34. Note that the number of slots following the resource type specifies slots from
  35. a *single* instance of the resource. If the resource group can tolerate
  36. receiving slots from different instances of the same resource, it can indicate
  37. this by splitting the specification into multiple requirements of one slot. For
  38. example:
  39. .. code-block:: cmake
  40. add_test(NAME MyTest COMMAND MyExe)
  41. set_property(TEST MyTest PROPERTY RESOURCE_GROUPS
  42. "gpus:1,gpus:1,gpus:1,gpus:1")
  43. In this case, the single resource group indicates that it needs four GPU slots,
  44. all of which may come from separate GPUs (though they don't have to; CTest may
  45. still assign slots from the same GPU.)
  46. When CTest sets the :ref:`environment variables
  47. <ctest-resource-environment-variables>` for a test, it assigns a group number
  48. based on the group description, starting at 0 on the left and the number of
  49. groups minus 1 on the right. For example, in the example above, the two
  50. groups in the first description would have IDs of 0 and 1, and the single
  51. group in the second description would have an ID of 2.
  52. Both the ``RESOURCE_GROUPS`` and :prop_test:`RESOURCE_LOCK` properties serve
  53. similar purposes, but they are distinct and orthogonal. Resources specified by
  54. ``RESOURCE_GROUPS`` do not affect :prop_test:`RESOURCE_LOCK`, and vice versa.
  55. Whereas :prop_test:`RESOURCE_LOCK` is a simpler property that is used for
  56. locking one global resource, ``RESOURCE_GROUPS`` is a more advanced property
  57. that allows multiple tests to simultaneously use multiple resources of the
  58. same type, specifying their requirements in a fine-grained manner.