Ocloc: Set DeviceId in HwInfo

User can pass a heximal value of device id via -device param.
This change makes the setting of this value in hwInfo.

Signed-off-by: Daria Hinz <daria.hinz@intel.com>
This commit is contained in:
Daria Hinz
2022-03-24 12:29:06 +01:00
committed by Compute-Runtime-Automation
parent cdf3d00919
commit 88c16542a1
2 changed files with 29 additions and 7 deletions

View File

@@ -505,16 +505,28 @@ TEST_F(OfflineCompilerTests, GivenArgsWhenOfflineCompilerIsCreatedThenSuccessIsR
delete pOfflineCompiler;
}
TEST_F(OfflineCompilerTests, givenProperDeviceIdHexAsDeviceArgumentThenSuccessIsReturned) {
std::map<std::string, std::string> files;
std::unique_ptr<MockOclocArgHelper> argHelper = std::make_unique<MockOclocArgHelper>(files);
TEST_F(OfflineCompilerTests, givenDeviceIdHexValueWhenInitHwInfoThenItHasCorrectlySetValues) {
auto deviceId = oclocArgHelperWithoutInput->deviceProductTable[0].deviceId;
if (oclocArgHelperWithoutInput->deviceProductTable.size() == 1 && deviceId == 0) {
GTEST_SKIP();
}
if (argHelper->deviceProductTable.size() == 1 && argHelper->deviceProductTable[0].deviceId == 0) {
MockOfflineCompiler mockOfflineCompiler;
std::stringstream deviceString, productString;
deviceString << "0x" << std::hex << deviceId;
mockOfflineCompiler.initHardwareInfo(deviceString.str());
EXPECT_EQ(mockOfflineCompiler.hwInfo.platform.usDeviceID, deviceId);
}
TEST_F(OfflineCompilerTests, givenProperDeviceIdHexAsDeviceArgumentThenSuccessIsReturned) {
auto deviceId = oclocArgHelperWithoutInput->deviceProductTable[0].deviceId;
if (oclocArgHelperWithoutInput->deviceProductTable.size() == 1 && deviceId == 0) {
GTEST_SKIP();
}
std::stringstream deviceString, productString;
deviceString << "0x" << std::hex << argHelper->deviceProductTable[0].deviceId;
productString << argHelper->deviceProductTable[0].product;
deviceString << "0x" << std::hex << deviceId;
productString << oclocArgHelperWithoutInput->deviceProductTable[0].product;
std::vector<std::string> argv = {
"ocloc",
@@ -522,8 +534,11 @@ TEST_F(OfflineCompilerTests, givenProperDeviceIdHexAsDeviceArgumentThenSuccessIs
"test_files/copybuffer.cl",
"-device",
deviceString.str()};
testing::internal::CaptureStdout();
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
EXPECT_EQ(pOfflineCompiler->getHardwareInfo().platform.usDeviceID, deviceId);
auto output = testing::internal::GetCapturedStdout();
std::stringstream resString;
resString << "Auto-detected target based on " << deviceString.str() << " device id: " << productString.str() << "\n";
@@ -542,8 +557,10 @@ TEST_F(OfflineCompilerTests, givenIncorrectDeviceIdHexThenInvalidDeviceIsReturne
"test_files/copybuffer.cl",
"-device",
"0x0"};
testing::internal::CaptureStdout();
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
auto output = testing::internal::GetCapturedStdout();
EXPECT_EQ(nullptr, pOfflineCompiler);
EXPECT_STREQ(output.c_str(), "Could not determine target based on device id: 0x0\nError: Cannot get HW Info for device 0x0.\n");

View File

@@ -342,6 +342,7 @@ int OfflineCompiler::initHardwareInfo(std::string deviceName) {
overridePlatformName(deviceName);
std::transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower);
const char hexPrefix = 2;
auto deviceId = -1;
std::string product("");
auto numeration = argHelper->getMajorMinorRevision(deviceName);
@@ -362,7 +363,8 @@ int OfflineCompiler::initHardwareInfo(std::string deviceName) {
}
if (deviceName.substr(0, hexPrefix) == "0x" && std::all_of(deviceName.begin() + hexPrefix, deviceName.end(), (::isxdigit))) {
product = argHelper->returnProductNameForDevice(stoi(deviceName, 0, 16));
deviceId = stoi(deviceName, 0, 16);
product = argHelper->returnProductNameForDevice(deviceId);
if (!product.empty()) {
argHelper->printf("Auto-detected target based on %s device id: %s\n", deviceName.c_str(), product.c_str());
deviceName = product;
@@ -379,6 +381,9 @@ int OfflineCompiler::initHardwareInfo(std::string deviceName) {
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
if (deviceId != -1) {
hwInfo.platform.usDeviceID = deviceId;
}
auto hwInfoConfig = defaultHardwareInfoConfigTable[hwInfo.platform.eProductFamily];
setHwInfoValuesFromConfig(hwInfoConfig, hwInfo);