Skip to content

[SYCL] Support query of free device memory extension #6604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions sycl/doc/extensions/supported/sycl_ext_intel_device_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The Feature Test Macro SYCL\_EXT\_INTEL\_DEVICE\_INFO will be defined as one of
| 1 | Initial extension version\. Base features are supported |
| 2 | Device UUID is supported |
| 3 | HW threads per EU device query is supported |
| 4 | Free device memory query is supported |


# Device UUID #
Expand Down Expand Up @@ -347,3 +348,41 @@ Then the maximum memory bandwidth can be obtained using the standard get\_info()
if (dev.has(aspect::ext_intel_max_mem_bandwidth)) {
auto maxBW = dev.get_info<info::device::ext_intel_max_mem_bandwidth>();
}

# Free Global Memory #

A new device descriptor will be added which will provide the number of bytes of free global memory for the device.

This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform. NOTE: one may need to set
ZES_ENABLE_SYSMAN=1 to fully enable this extension.


## Version ##

The extension supports this query in version 4 and later.


## Device Information Descriptors ##

| Device Descriptors | Return Type | Description |
| ------------------ | ----------- | ----------- |
| info\:\:device\:\:ext\_intel\_free\_memory | uint64\_t| Returns the memory avialble on the device in units of bytes.|


## Aspects ##

A new aspect, ext\_intel\_free\_memory, will be added.


## Error Condition ##

An invalid object runtime error will be thrown if the device does not support aspect\:\:ext\_intel\_free\_memory.


## Example Usage ##

Then the free device memory can be obtained using the standard get\_info() interface.

if (dev.has(aspect::ext_intel_free_memory)) {
auto FreeMemory = dev.get_info<info::device::ext_intel_free_memory>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,50 +452,6 @@ The behavior of the SYCL buffer destructor depends on the Ownership flag. As wit
* If the ownership is keep (i.e. the application retains ownership of the Level Zero memory allocation), then the SYCL buffer destructor blocks until all work in queues on the buffer have completed. The buffer's contents is not copied back to the Level Zero memory allocation.
* If the ownership is transfer (i.e. the SYCL runtime has ownership of the Level Zero memory allocation), then the SYCL buffer destructor does not need to block even if work on the buffer has not completed. The SYCL runtime frees the Level Zero memory allocation asynchronously when it is no longer in use in queues.

## 5 Level-Zero additional functionality

### 5.1 Device Information Descriptors
The Level Zero backend provides the following device information descriptors
that an application can use to query information about a Level Zero device.
Applications use these queries via the `device::get_backend_info<>()` member
function as shown in the example below (which illustrates the `free_memory`
query):

``` C++
sycl::queue Queue;
auto Device = Queue.get_device();

size_t freeMemory =
Device.get_backend_info<sycl::ext::oneapi::level_zero::info::device::free_memory>();
```

New descriptors added as part of this specification are described in the table below and in the subsequent synopsis.

| Descriptor | Description |
| ---------- | ----------- |
| `sycl::ext::oneapi::level_zero::info::device::free_memory` | Returns the number of bytes of free memory for the device. |


``` C++
namespace sycl{
namespace ext {
namespace oneapi {
namespace level_zero {
namespace info {
namespace device {

struct free_memory {
using return_type = size_t;
};

} // namespace device;
} // namespace info
} // namespace level_zero
} // namespace oneapi
} // namespace ext
} // namespace sycl
```

## Revision History
|Rev|Date|Author|Changes|
|-------------|:------------|:------------|:------------|
Expand All @@ -508,3 +464,4 @@ struct free_memory {
|7|2021-09-13|Sergey Maslov|Updated according to SYCL 2020 standard
|8|2022-01-06|Artur Gainullin|Introduced make_buffer() API
|9|2022-05-12|Steffen Larsen|Added device member to queue input type
|10|2022-08-18|Sergey Maslov|Moved free_memory device info query to be sycl_ext_intel_device_info extension
1 change: 1 addition & 0 deletions sycl/include/sycl/aspects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum class aspect {
ext_intel_gpu_hw_threads_per_eu = 33,
ext_oneapi_cuda_async_barrier = 34,
ext_oneapi_bfloat16 = 35,
ext_intel_free_memory = 36,
};

} // __SYCL_INLINE_VER_NAMESPACE(_V1)
Expand Down
5 changes: 4 additions & 1 deletion sycl/include/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
// 10.12 Change enum value PI_MEM_ADVICE_UNKNOWN from 0 to 999, and set enum
// PI_MEM_ADVISE_RESET to 0.
// 10.13 Added new PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS queue property.
// 10.14 Add PI_EXT_INTEL_DEVICE_INFO_FREE_MEMORY as an extension for
// piDeviceGetInfo.

#define _PI_H_VERSION_MAJOR 10
#define _PI_H_VERSION_MINOR 13
#define _PI_H_VERSION_MINOR 14

#define _PI_STRING_HELPER(a) #a
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
Expand Down Expand Up @@ -272,6 +274,7 @@ typedef enum {
PI_DEVICE_INFO_IMAGE_SRGB = 0x10027,
// Return true if sub-device should do its own program build
PI_DEVICE_INFO_BUILD_ON_SUBDEVICE = 0x10028,
PI_EXT_INTEL_DEVICE_INFO_FREE_MEMORY = 0x10029,
PI_DEVICE_INFO_ATOMIC_64 = 0x10110,
PI_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES = 0x10111,
PI_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES = 0x11000,
Expand Down
Loading