Skip to content

Commit

Permalink
[GPU] Added UUID property(#81574) (openvinotoolkit#11567)
Browse files Browse the repository at this point in the history
Co-authored-by: Ahn, Paul Y <[email protected]>

Co-authored-by: Vladimir Paramuzov <[email protected]>
  • Loading branch information
ahnyoung-paul and vladimir-paramuzov authored May 26, 2022
1 parent ccd001f commit c185198
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/inference/include/openvino/runtime/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
#pragma once

#include <array>
#include <iomanip>
#include <istream>
#include <map>
#include <string>
Expand Down Expand Up @@ -611,6 +613,45 @@ static constexpr Property<std::string, PropertyMutability::RO> full_name{"FULL_D
*/
static constexpr Property<std::string, PropertyMutability::RO> architecture{"DEVICE_ARCHITECTURE"};

/**
* @brief Structure which defines format of UUID.
* @ingroup ov_runtime_cpp_prop_api
*/
struct UUID {
static const uint64_t MAX_UUID_SIZE = 16; //!< Max size of uuid array (128 bits)
std::array<uint8_t, MAX_UUID_SIZE> uuid; //!< Array with uuid for a device
};

/** @cond INTERNAL */
inline std::ostream& operator<<(std::ostream& os, const UUID& device_uuid) {
std::stringstream s;
for (auto& c : device_uuid.uuid) {
s << std::hex << std::setw(2) << std::setfill('0') << +c;
}
return os << s.str();
}

inline std::istream& operator>>(std::istream& is, UUID& device_uuid) {
std::string s;
auto flags = is.flags();
for (size_t i = 0; i < UUID::MAX_UUID_SIZE; i++) {
is >> std::setw(2) >> s;
std::istringstream ss2(s);
int val;
ss2 >> std::hex >> val;
device_uuid.uuid[i] = static_cast<uint8_t>(val);
}
is.flags(flags);
return is;
}
/** @endcond */

/**
* @brief Read-only property which defines the UUID of the device.
* @ingroup ov_runtime_cpp_prop_api
*/
static constexpr Property<UUID, PropertyMutability::RO> uuid{"DEVICE_UUID"};

/**
* @brief Enum to define possible device types
* @ingroup ov_runtime_cpp_prop_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <vector>
#include <tuple>
#include <array>

namespace cldnn {
/// @addtogroup cpp_api C++ API
Expand All @@ -21,6 +22,12 @@ enum class device_type {
discrete_gpu = 1
};

/// @brief Structure to represent gpu device UUID
struct device_uuid {
static const constexpr size_t max_uuid_size = 16;
std::array<uint8_t, max_uuid_size> val;
};

/// @brief Defines version of GFX IP
struct gfx_version {
uint16_t major;
Expand Down Expand Up @@ -74,6 +81,8 @@ struct device_info {
uint32_t num_sub_slices_per_slice; ///< Number of subslices in a slice
uint32_t num_eus_per_sub_slice; ///< Number of execution units per subslice
uint32_t num_threads_per_eu; ///< Number of hardware threads per execution unit

device_uuid uuid; ///< UUID of the gpu device
};

/// @}
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/intel_gpu/src/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ Parameter Plugin::GetMetric(const std::string& name, const std::map<std::string,
ov::PropertyName{ov::optimal_batch_size.name(), PropertyMutability::RO},
ov::PropertyName{ov::max_batch_size.name(), PropertyMutability::RO},
ov::PropertyName{ov::device::full_name.name(), PropertyMutability::RO},
ov::PropertyName{ov::device::uuid.name(), PropertyMutability::RO},
ov::PropertyName{ov::device::type.name(), PropertyMutability::RO},
ov::PropertyName{ov::device::gops.name(), PropertyMutability::RO},
ov::PropertyName{ov::device::capabilities.name(), PropertyMutability::RO},
Expand Down Expand Up @@ -863,6 +864,10 @@ Parameter Plugin::GetMetric(const std::string& name, const std::map<std::string,
GPU_DEBUG_COUT << "ACTUAL OPTIMAL BATCH: " << batch << std::endl;
}
return decltype(ov::optimal_batch_size)::value_type {batch};
} else if (name == ov::device::uuid) {
ov::device::UUID uuid;
std::copy_n(std::begin(device_info.uuid.val), cldnn::device_uuid::max_uuid_size, std::begin(uuid.uuid));
return decltype(ov::device::uuid)::value_type {uuid};
} else if (name == ov::device::full_name) {
auto deviceName = StringRightTrim(device_info.dev_name, "NEO", false);
deviceName += std::string(" (") + (device_info.dev_type == cldnn::device_type::discrete_gpu ? "dGPU" : "iGPU") + ")";
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,15 @@ device_info init_device_info(const cl::Device& device) {
info.supported_simd_sizes = {8, 16, 32};
}

bool device_attr_supported = extensions.find("cl_intel_device_attribute_query") != std::string::npos;
bool device_uuid_supported = extensions.find("cl_khr_device_uuid") != std::string::npos;
if (device_uuid_supported) {
static_assert(CL_UUID_SIZE_KHR == device_uuid::max_uuid_size, "");
info.uuid.val = device.getInfo<CL_DEVICE_UUID_KHR>();
} else {
std::fill_n(std::begin(info.uuid.val), device_uuid::max_uuid_size, 0);
}

bool device_attr_supported = extensions.find("cl_intel_device_attribute_query") != std::string::npos;
if (device_attr_supported) {
info.gfx_ver = parse_version(device.getInfo<CL_DEVICE_IP_VERSION_INTEL>());
info.device_id = device.getInfo<CL_DEVICE_ID_INTEL>();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once
#include <CL/opencl.hpp>
#include <CL/cl_ext.h>
#define NOMINMAX
#ifdef _WIN32
#include <CL/cl_d3d11.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ INSTANTIATE_TEST_SUITE_P(nightly_OVClassGetMetricTest,
OVClassGetMetricTest_FULL_DEVICE_NAME,
::testing::Values("GPU", "MULTI", "HETERO", "AUTO", "BATCH"));

INSTANTIATE_TEST_SUITE_P(nightly_OVClassGetMetricTest,
OVClassGetMetricTest_DEVICE_UUID,
::testing::Values("GPU"));

INSTANTIATE_TEST_SUITE_P(nightly_OVClassGetMetricTest,
OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES,
::testing::Values("GPU"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ using OVClassGetMetricTest_SUPPORTED_CONFIG_KEYS = OVClassBaseTestP;
using OVClassGetMetricTest_AVAILABLE_DEVICES = OVClassBaseTestP;
using OVClassGetMetricTest_FULL_DEVICE_NAME = OVClassBaseTestP;
using OVClassGetMetricTest_FULL_DEVICE_NAME_with_DEVICE_ID = OVClassBaseTestP;
using OVClassGetMetricTest_DEVICE_UUID = OVClassBaseTestP;
using OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES = OVClassBaseTestP;
using OVClassGetMetricTest_DEVICE_GOPS = OVClassBaseTestP;
using OVClassGetMetricTest_DEVICE_TYPE = OVClassBaseTestP;
Expand Down Expand Up @@ -639,6 +640,16 @@ TEST_P(OVClassGetMetricTest_FULL_DEVICE_NAME_with_DEVICE_ID, GetMetricAndPrintNo
}
}

TEST_P(OVClassGetMetricTest_DEVICE_UUID, GetMetricAndPrintNoThrow) {
ov::Core ie = createCoreWithTemplate();
ov::device::UUID t;

OV_ASSERT_NO_THROW(t = ie.get_property(deviceName, ov::device::uuid));
std::cout << "Device uuid: " << std::endl << t << std::endl;

OV_ASSERT_PROPERTY_SUPPORTED(ov::device::uuid);
}

TEST_P(OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES, GetMetricAndPrintNoThrow) {
ov::Core ie = createCoreWithTemplate();
std::vector<std::string> t;
Expand Down

0 comments on commit c185198

Please sign in to comment.