Skip to content

Commit 3c588e1

Browse files
feature: Add support for Experimental zexSysmanMemoryGetBandwidth
Related-To: LOCI-3838 Signed-off-by: Mayank Raghuwanshi <[email protected]> Source: d0d5a03
1 parent 28a1fcb commit 3c588e1

26 files changed

+393
-7
lines changed

level_zero/api/core/ze_driver_api_entrypoints.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -52,7 +52,7 @@ ze_result_t zeDriverGetExtensionFunctionAddress(
5252
ze_driver_handle_t hDriver,
5353
const char *name,
5454
void **ppFunctionAddress) {
55-
return L0::DriverHandle::fromHandle(hDriver)->getExtensionFunctionAddress(name, ppFunctionAddress);
55+
return L0::BaseDriver::fromHandle(hDriver)->getExtensionFunctionAddress(name, ppFunctionAddress);
5656
}
5757
} // namespace L0
5858

level_zero/api/driver_experimental/public/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ target_sources(${L0_STATIC_LIB_NAME}
1717
${CMAKE_CURRENT_SOURCE_DIR}/zex_memory.h
1818
${CMAKE_CURRENT_SOURCE_DIR}/zex_module.cpp
1919
${CMAKE_CURRENT_SOURCE_DIR}/zex_module.h
20+
${CMAKE_CURRENT_SOURCE_DIR}/zex_sysman_memory.h
21+
${CMAKE_CURRENT_SOURCE_DIR}/zex_sysman_memory.cpp
2022
)

level_zero/api/driver_experimental/public/zex_api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -13,12 +13,15 @@
1313

1414
// 'core' API headers
1515
#include <level_zero/ze_api.h>
16+
// 'sysman' API headers
17+
#include <level_zero/zes_api.h>
1618

1719
// driver experimental API headers
1820
#include "level_zero/api/driver_experimental/public/zex_cmdlist.h"
1921

2022
#include "zex_driver.h"
2123
#include "zex_memory.h"
2224
#include "zex_module.h"
25+
#include "zex_sysman_memory.h"
2326

2427
#endif // _ZEX_API_H
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/api/driver_experimental/public/zex_sysman_memory.h"
9+
10+
#include "level_zero/api/driver_experimental/public/zex_api.h"
11+
#include "level_zero/core/source/driver/driver.h"
12+
#include "level_zero/core/source/driver/driver_handle.h"
13+
#include "level_zero/sysman/source/sysman_device.h"
14+
#include "level_zero/sysman/source/sysman_driver.h"
15+
#include "level_zero/sysman/source/sysman_driver_handle.h"
16+
#include "level_zero/tools/source/sysman/memory/memory.h"
17+
#include "level_zero/tools/source/sysman/sysman.h"
18+
19+
namespace L0 {
20+
21+
ze_result_t ZE_APICALL
22+
zexSysmanMemoryGetBandwidth(
23+
zes_mem_handle_t hMemory,
24+
uint64_t *pReadCounters,
25+
uint64_t *pWriteCounters,
26+
uint64_t *pMaxBandwidth,
27+
uint64_t timeout) {
28+
if (L0::sysmanInitFromCore) {
29+
return L0::Memory::fromHandle(hMemory)->memoryGetBandwidthEx(pReadCounters, pWriteCounters, pMaxBandwidth, timeout);
30+
}
31+
return L0::Sysman::Memory::fromHandle(hMemory)->memoryGetBandwidthEx(pReadCounters, pWriteCounters, pMaxBandwidth, timeout);
32+
}
33+
34+
} // namespace L0
35+
36+
extern "C" {
37+
38+
ZE_APIEXPORT ze_result_t ZE_APICALL
39+
zexSysmanMemoryGetBandwidth(
40+
zes_mem_handle_t hMemory,
41+
uint64_t *pReadCounters,
42+
uint64_t *pWriteCounters,
43+
uint64_t *pMaxBandwidth,
44+
uint64_t timeout) {
45+
return L0::zexSysmanMemoryGetBandwidth(hMemory, pReadCounters, pWriteCounters, pMaxBandwidth, timeout);
46+
}
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#ifndef _ZEX_SYSMAN_MEMORY_H
9+
#define _ZEX_SYSMAN_MEMORY_H
10+
#if defined(__cplusplus)
11+
#pragma once
12+
#endif
13+
14+
#include "level_zero/api/driver_experimental/public/zex_api.h"
15+
16+
namespace L0 {
17+
///////////////////////////////////////////////////////////////////////////////
18+
/// @brief Get memory bandwidth
19+
///
20+
/// @details
21+
/// - The application may call this function from simultaneous threads.
22+
/// - The implementation of this function should be lock-free.
23+
///
24+
/// @returns
25+
/// - ::ZE_RESULT_SUCCESS
26+
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
27+
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
28+
/// - ::ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY
29+
/// - ::ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY
30+
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
31+
/// + `nullptr == hMemory`
32+
/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER
33+
/// + `nullptr == pBandwidth`
34+
/// - ::ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS
35+
/// + User does not have permissions to query this telemetry.
36+
ze_result_t ZE_APICALL
37+
zexSysmanMemoryGetBandwidth(
38+
zes_mem_handle_t hMemory, ///<[in] Handleforthecomponent.
39+
uint64_t *pReadCounters, ///<[out] Total bytes read from memory in duration
40+
uint64_t *pWriteCounters, ///<[out] Total bytes written to memory in duration
41+
uint64_t *pMaxBandwidth, ///<[out] Maximum bandwidth in units of bytes/sec
42+
uint64_t duration ///<[in] duration in milliseconds
43+
);
44+
45+
} // namespace L0
46+
#endif

level_zero/core/source/driver/driver_handle.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ namespace L0 {
2828
struct Device;
2929
struct L0EnvVariables;
3030

31-
struct DriverHandle : _ze_driver_handle_t {
31+
struct BaseDriver : _ze_driver_handle_t {
32+
virtual ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) = 0;
33+
static BaseDriver *fromHandle(ze_driver_handle_t handle) { return static_cast<BaseDriver *>(handle); }
34+
};
35+
36+
struct DriverHandle : BaseDriver {
3237
virtual ze_result_t createContext(const ze_context_desc_t *desc,
3338
uint32_t numDevices,
3439
ze_device_handle_t *phDevices,
@@ -37,7 +42,6 @@ struct DriverHandle : _ze_driver_handle_t {
3742
virtual ze_result_t getProperties(ze_driver_properties_t *properties) = 0;
3843
virtual ze_result_t getApiVersion(ze_api_version_t *version) = 0;
3944
virtual ze_result_t getIPCProperties(ze_driver_ipc_properties_t *pIPCProperties) = 0;
40-
virtual ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) = 0;
4145
virtual ze_result_t getExtensionProperties(uint32_t *pCount,
4246
ze_driver_extension_properties_t *pExtensionProperties) = 0;
4347

level_zero/core/source/get_extension_function_lookup_map.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -25,6 +25,7 @@ std::unordered_map<std::string, void *> getExtensionFunctionsLookupMap() {
2525

2626
addToMap(lookupMap, zexCommandListAppendWaitOnMemory);
2727
addToMap(lookupMap, zexCommandListAppendWriteToMemory);
28+
addToMap(lookupMap, zexSysmanMemoryGetBandwidth);
2829
#undef addToMap
2930

3031
return lookupMap;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!---
2+
3+
Copyright (C) 2023 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
-->
8+
9+
# Sysman Memory Bandwidth
10+
11+
* [Overview](#Overview)
12+
* [Interfaces](#Interfaces)
13+
* [Known Issues and Limitations](#Known-Issues-and-Limitations)
14+
15+
# Overview
16+
17+
`zesMemoryGetBandwidth` exposes memory read, write counters and timestamp. The expectation is these
18+
counters are monotonically increasing and user can get bandwidth information using two snapshots of
19+
the read and write counters taken at different instances. However, the counters could overflow
20+
depending on underlying width of the counter presented by the hardware, and currently there is no
21+
mechanism with which user can detect these overflows. Therefore `zexSysmanMemoryGetBandwidth` is
22+
introduced to resolve this problem it takes care of overflow internally.
23+
`zexSysmanMemoryGetBandwidth` takes duration as input argument and provides reads and write counter
24+
values that elapsed in that duration. This interface blocks host thread progress for the duration
25+
specified by the user.
26+
To calculate the bandwidth using `zexSysmanMemoryGetBandwidth` use the formula
27+
`Bandwidth = (Readcounters + WriteCounters) / duration`
28+
29+
# Interfaces
30+
31+
```cpp
32+
///////////////////////////////////////////////////////////////////////////////
33+
/// @brief Get memory bandwidth
34+
///
35+
/// @details
36+
/// - The application may call this function from simultaneous threads.
37+
/// - The implementation of this function should be lock-free.
38+
///
39+
/// @returns
40+
/// - ::ZE_RESULT_SUCCESS
41+
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
42+
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
43+
/// - ::ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY
44+
/// - ::ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY
45+
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
46+
/// + `nullptr == hMemory`
47+
/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER
48+
/// + `nullptr == pBandwidth`
49+
/// - ::ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS
50+
/// + User does not have permissions to query this telemetry.
51+
ze_result_t ZE_APICALL
52+
zexSysmanMemoryGetBandwidth(
53+
zes_mem_handle_t hMemory, ///<[in] Handleforthecomponent.
54+
uint64_t *pReadCounters, ///<[out] Total bytes read from memory in duration
55+
uint64_t *pWriteCounters, ///<[out] Total bytes written to memory in duration
56+
uint64_t *pMaxBandwidth, ///<[out] Maximum bandwidth in units of bytes/sec
57+
uint64_t duration ///<[in] duration in milliseconds
58+
);
59+
```
60+
61+
```cpp
62+
typedef ze_result_t (*pFnzexSysmanMemoryGetBandwidth)(zes_mem_handle_t, uint64 *, uint64 *, uint64 *, uint64);
63+
...
64+
65+
pFnzexSysmanMemoryGetBandwidth zexSysmanMemoryGetBandwidth = nullptr;
66+
ze_result_t res = zeDriverGetExtensionFunctionAddress(hDriver, "zexSysmanMemoryGetBandwidth", reinterpret_cast<void **>(&zexSysmanMemoryGetBandwidth)));
67+
```
68+
69+
# Known Issues and Limitations
70+
71+
* Implemented and validation only on Xe HPC (PVC).

level_zero/sysman/source/memory/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Memory : _zes_mem_handle_t {
2323
virtual ze_result_t memoryGetProperties(zes_mem_properties_t *pProperties) = 0;
2424
virtual ze_result_t memoryGetBandwidth(zes_mem_bandwidth_t *pBandwidth) = 0;
2525
virtual ze_result_t memoryGetState(zes_mem_state_t *pState) = 0;
26+
virtual ze_result_t memoryGetBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) = 0;
2627

2728
static Memory *fromHandle(zes_mem_handle_t handle) {
2829
return static_cast<Memory *>(handle);

level_zero/sysman/source/memory/memory_imp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ze_result_t MemoryImp::memoryGetProperties(zes_mem_properties_t *pProperties) {
2323
return ZE_RESULT_SUCCESS;
2424
}
2525

26+
ze_result_t MemoryImp::memoryGetBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) {
27+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
28+
}
29+
2630
void MemoryImp::init() {
2731
this->initSuccess = pOsMemory->isMemoryModuleSupported();
2832
if (this->initSuccess == true) {

level_zero/sysman/source/memory/memory_imp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MemoryImp : public Memory, NEO::NonCopyableOrMovableClass {
2020
ze_result_t memoryGetProperties(zes_mem_properties_t *pProperties) override;
2121
ze_result_t memoryGetBandwidth(zes_mem_bandwidth_t *pBandwidth) override;
2222
ze_result_t memoryGetState(zes_mem_state_t *pState) override;
23+
ze_result_t memoryGetBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) override;
2324

2425
MemoryImp(OsSysman *pOsSysman, bool onSubdevice, uint32_t subDeviceId);
2526
~MemoryImp() override;

level_zero/sysman/source/sysman_driver_handle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace L0 {
1616
namespace Sysman {
1717

18-
struct SysmanDriverHandle : _ze_driver_handle_t {
18+
struct SysmanDriverHandle : BaseDriver {
1919
static SysmanDriverHandle *fromHandle(zes_driver_handle_t handle) { return static_cast<SysmanDriverHandle *>(handle); }
2020
inline zes_driver_handle_t toHandle() { return this; }
2121

level_zero/sysman/source/sysman_driver_handle_imp.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "shared/source/helpers/hw_info.h"
1414
#include "shared/source/os_interface/os_interface.h"
1515

16+
#include "level_zero/core/source/get_extension_function_lookup_map.h"
1617
#include "level_zero/sysman/source/sysman_device.h"
1718
#include "level_zero/sysman/source/sysman_driver.h"
1819

@@ -44,6 +45,15 @@ ze_result_t SysmanDriverHandleImp::initialize(NEO::ExecutionEnvironment &executi
4445
return ZE_RESULT_SUCCESS;
4546
}
4647

48+
ze_result_t SysmanDriverHandleImp::getExtensionFunctionAddress(const char *pFuncName, void **pfunc) {
49+
auto funcAddr = extensionFunctionsLookupMap.find(std::string(pFuncName));
50+
if (funcAddr != extensionFunctionsLookupMap.end()) {
51+
*pfunc = funcAddr->second;
52+
return ZE_RESULT_SUCCESS;
53+
}
54+
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
55+
}
56+
4757
SysmanDriverHandle *SysmanDriverHandle::create(NEO::ExecutionEnvironment &executionEnvironment, ze_result_t *returnValue) {
4858
SysmanDriverHandleImp *driverHandle = new SysmanDriverHandleImp;
4959
UNRECOVERABLE_IF(nullptr == driverHandle);
@@ -56,6 +66,7 @@ SysmanDriverHandle *SysmanDriverHandle::create(NEO::ExecutionEnvironment &execut
5666
return nullptr;
5767
}
5868

69+
driverHandle->extensionFunctionsLookupMap = getExtensionFunctionsLookupMap();
5970
GlobalSysmanDriver = driverHandle;
6071
*returnValue = res;
6172
return driverHandle;

level_zero/sysman/source/sysman_driver_handle_imp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#pragma once
99
#include "level_zero/sysman/source/sysman_driver_handle.h"
1010

11+
#include <string>
12+
#include <unordered_map>
13+
1114
namespace L0 {
1215
namespace Sysman {
1316
struct SysmanDevice;
@@ -18,6 +21,9 @@ struct SysmanDriverHandleImp : SysmanDriverHandle {
1821
ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) override;
1922
std::vector<SysmanDevice *> sysmanDevices;
2023
uint32_t numDevices = 0;
24+
25+
ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) override;
26+
std::unordered_map<std::string, void *> extensionFunctionsLookupMap;
2127
};
2228

2329
extern struct SysmanDriverHandleImp *GlobalSysmanDriver;

level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
4141
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
4242
}
4343

44+
ze_result_t LinuxMemoryImp::getBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) {
45+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
46+
}
47+
4448
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
4549
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
4650
return pLinuxMemoryImp;

level_zero/tools/source/sysman/memory/linux/os_memory_imp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
2121
ze_result_t getProperties(zes_mem_properties_t *pProperties) override;
2222
ze_result_t getBandwidth(zes_mem_bandwidth_t *pBandwidth) override;
2323
ze_result_t getState(zes_mem_state_t *pState) override;
24+
ze_result_t getBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) override;
25+
2426
bool isMemoryModuleSupported() override;
2527
LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
2628
LinuxMemoryImp() = default;

level_zero/tools/source/sysman/memory/linux/os_memory_imp_dg1.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
4141
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
4242
}
4343

44+
ze_result_t LinuxMemoryImp::getBandwidthEx(uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout) {
45+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
46+
}
47+
4448
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
4549
std::vector<NEO::MemoryRegion> deviceRegions;
4650
if (pDrm->queryMemoryInfo() == false) {

0 commit comments

Comments
 (0)