Adding support for passing proper extensions list from cloc to compilers

Change-Id: I89249cd6ccae9996cd33d7ba26007c778207f028
This commit is contained in:
Koska, Andrzej 2018-01-15 18:16:50 +01:00
parent 044fd1ab81
commit be0306ca68
13 changed files with 210 additions and 46 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2017, Intel Corporation
# Copyright (c) 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@ -29,6 +29,8 @@ set(CLOC_SRCS_LIB
${IGDRCL_SOURCE_DIR}/offline_compiler/helper.cpp
${IGDRCL_SOURCE_DIR}/runtime/compiler_interface/create_main.cpp
${IGDRCL_SOURCE_DIR}/runtime/helpers/hw_info.cpp
${IGDRCL_SOURCE_DIR}/runtime/platform/extensions.h
${IGDRCL_SOURCE_DIR}/runtime/platform/extensions.cpp
${IGDRCL_SOURCE_DIR}/runtime/helpers/file_io.cpp
${IGDRCL_SOURCE_DIR}/runtime/helpers/abort.cpp
${IGDRCL_SOURCE_DIR}/runtime/helpers/debug_helpers.cpp

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -37,6 +37,7 @@
#include "runtime/helpers/debug_helpers.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/validators.h"
#include "runtime/platform/extensions.h"
#include "elf/writer.h"
#include <iomanip>
#include <list>
@ -489,6 +490,8 @@ int OfflineCompiler::parseCommandLine(uint32_t numArgs, const char **argv) {
if (retVal != CL_SUCCESS) {
printf("Error: Cannot get HW Info for device %s.\n", deviceName.c_str());
}
std::string extensionsList = getExtensionsList(*hwInfo);
internalOptions.append(convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str()));
}
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2017, Intel Corporation
# Copyright (c) 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@ -420,6 +420,8 @@ set (RUNTIME_SRCS_PLATFORM
platform/platform.cpp
platform/platform.h
platform/platform_info.h
platform/extensions.cpp
platform/extensions.h
)
set (RUNTIME_SRCS_PROGRAM

View File

@ -30,6 +30,7 @@
#include "runtime/device/driver_info.h"
#include "CL/cl_ext_intel.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/platform/extensions.h"
namespace OCLRT {
extern const char *familyName[];
@ -40,24 +41,6 @@ static std::string profile = "FULL_PROFILE";
static std::string spirVersions = "1.2 ";
static const char *spirvVersion = "SPIR-V_1.0 ";
static std::string driverVersion = NEO_DRIVER_VERSION;
static const std::string deviceExtensionsList = "cl_khr_3d_image_writes "
"cl_khr_byte_addressable_store "
"cl_khr_fp16 "
"cl_khr_depth_images "
"cl_khr_global_int32_base_atomics "
"cl_khr_global_int32_extended_atomics "
"cl_khr_icd "
"cl_khr_image2d_from_buffer "
"cl_khr_local_int32_base_atomics "
"cl_khr_local_int32_extended_atomics "
"cl_intel_subgroups "
"cl_intel_required_subgroup_size "
"cl_intel_subgroups_short "
"cl_khr_spir "
"cl_intel_accelerator "
"cl_intel_media_block_io "
"cl_intel_driver_diagnostics "
"cl_intel_device_side_avc_motion_estimation ";
const char *builtInKernels = ""; // the "always available" (extension-independent) builtin kernels

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include "runtime/helpers/hw_info.h"
#include "runtime/platform/extensions.h"
namespace OCLRT {
const char *deviceExtensionsList = "cl_khr_3d_image_writes "
"cl_khr_byte_addressable_store "
"cl_khr_fp16 "
"cl_khr_depth_images "
"cl_khr_global_int32_base_atomics "
"cl_khr_global_int32_extended_atomics "
"cl_khr_icd "
"cl_khr_image2d_from_buffer "
"cl_khr_local_int32_base_atomics "
"cl_khr_local_int32_extended_atomics "
"cl_intel_subgroups "
"cl_intel_required_subgroup_size "
"cl_intel_subgroups_short "
"cl_khr_spir "
"cl_intel_accelerator "
"cl_intel_media_block_io "
"cl_intel_driver_diagnostics "
"cl_intel_device_side_avc_motion_estimation ";
std::string getExtensionsList(const HardwareInfo &hwInfo) {
std::string allExtensionsList;
allExtensionsList.reserve(1000);
allExtensionsList.append(deviceExtensionsList);
if (hwInfo.capabilityTable.clVersionSupport >= 21) {
allExtensionsList += "cl_khr_subgroups ";
allExtensionsList += "cl_khr_il_program ";
}
if (hwInfo.capabilityTable.ftrSupportsFP64) {
allExtensionsList += "cl_khr_fp64 ";
}
return allExtensionsList;
}
std::string removeLastSpace(std::string &processedString) {
if (processedString.size() > 0) {
if (*processedString.rbegin() == ' ') {
processedString.pop_back();
}
}
return processedString;
}
std::string convertEnabledExtensionsToCompilerInternalOptions(const char *enabledExtensions) {
std::string extensionsList = enabledExtensions;
extensionsList.reserve(1000);
removeLastSpace(extensionsList);
std::string::size_type pos = 0;
while ((pos = extensionsList.find(" ", pos)) != std::string::npos) {
extensionsList.replace(pos, 1, ",+");
}
extensionsList = "-cl-ext=-all,+" + extensionsList;
return extensionsList;
}
} // namespace OCLRT

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
namespace OCLRT {
extern const char *deviceExtensionsList;
std::string getExtensionsList(const HardwareInfo &hwInfo);
std::string removeLastSpace(std::string &s);
std::string convertEnabledExtensionsToCompilerInternalOptions(const char *deviceExtensions);
} // namespace OCLRT

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -32,6 +32,7 @@
#include "runtime/os_interface/device_factory.h"
#include "runtime/event/async_events_handler.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/platform/extensions.h"
#include "CL/cl_ext.h"
namespace OCLRT {
@ -100,18 +101,7 @@ cl_int Platform::getInfo(cl_platform_info paramName,
return retVal;
}
std::string Platform::getCompilerExtensions(const char *deviceExtensions) {
std::string extensionsList = deviceExtensions;
extensionsList.pop_back();
size_t pos = 0;
while ((pos = extensionsList.find(" ", pos)) != std::string::npos) {
extensionsList.replace(pos, 1, ",+");
}
extensionsList = "-cl-ext=-all,+" + extensionsList;
return extensionsList;
}
std::string Platform::getCompilerExtensions() {
const std::string &Platform::peekCompilerExtensions() const {
return compilerExtensions;
}
@ -158,7 +148,7 @@ bool Platform::initialize(size_t numDevices,
break;
}
compilerExtensions = getCompilerExtensions(pDevice->getDeviceInfo().deviceExtensions);
compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(pDevice->getDeviceInfo().deviceExtensions);
} else {
return false;
}

View File

@ -53,7 +53,7 @@ class Platform : public BaseObject<_cl_platform_id> {
void *paramValue,
size_t *paramValueSizeRet);
std::string getCompilerExtensions();
const std::string &peekCompilerExtensions() const;
bool initialize(size_t numDevices,
const HardwareInfo **devices);
@ -75,7 +75,6 @@ class Platform : public BaseObject<_cl_platform_id> {
StateInited,
};
cl_uint state = StateNone;
std::string getCompilerExtensions(const char *deviceExtensions);
void fillGlobalDispatchTable();
PlatformInfo *platformInfo = nullptr;
@ -85,4 +84,4 @@ class Platform : public BaseObject<_cl_platform_id> {
};
Platform *platform();
}
} // namespace OCLRT

View File

@ -91,7 +91,7 @@ cl_int Program::build(
break;
}
internalOptions.append(platform()->getCompilerExtensions());
internalOptions.append(platform()->peekCompilerExtensions());
inputArgs.pInput = (char *)(sourceCode.c_str());
inputArgs.InputSize = (uint32_t)sourceCode.size();
inputArgs.pOptions = options.c_str();
@ -159,4 +159,4 @@ cl_int Program::build(
return retVal;
}
}
} // namespace OCLRT

View File

@ -150,7 +150,7 @@ cl_int Program::compile(
TranslationArgs inputArgs = {};
// set parameters for compilation
internalOptions.append(platform()->getCompilerExtensions());
internalOptions.append(platform()->peekCompilerExtensions());
inputArgs.pInput = pCompileData;
inputArgs.InputSize = (uint32_t)compileDataSize;
inputArgs.pOptions = options.c_str();

View File

@ -230,7 +230,7 @@ TEST_F(CompilerInterfaceTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsI
gEnvironment->fclPushDebugVars(debugVars);
retVal = pCompilerInterface->build(*pProgram, inputArgs, false);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(platform()->getCompilerExtensions()));
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(platform()->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}
@ -299,7 +299,7 @@ TEST_F(CompilerInterfaceTest, WhenCompileIsInvokedThenFclReceivesListOfExtension
gEnvironment->fclPushDebugVars(fclDebugVars);
retVal = pCompilerInterface->compile(*pProgram, inputArgs);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(platform()->getCompilerExtensions()));
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(platform()->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}

View File

@ -28,6 +28,7 @@
#include "runtime/helpers/file_io.h"
#include "runtime/helpers/options.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "gmock/gmock.h"
#define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0]))
@ -61,6 +62,21 @@ TEST_F(OfflineCompilerTests, GoodArgTest) {
delete pOfflineCompiler;
}
TEST_F(OfflineCompilerTests, TestExtensions) {
const char *argv[] = {
"cloc",
"-file",
"test_files/copybuffer.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
ASSERT_NE(nullptr, mockOfflineCompiler);
mockOfflineCompiler->parseCommandLine(ARRAY_COUNT(argv), argv);
std::string internalOptions = mockOfflineCompiler->getInternalOptions();
EXPECT_THAT(internalOptions, ::testing::HasSubstr(std::string("cl_khr_3d_image_writes")));
}
TEST_F(OfflineCompilerTests, GoodBuildTest) {
const char *argv[] = {
"cloc",

View File

@ -22,6 +22,7 @@
#include "runtime/helpers/options.h"
#include "runtime/device/device.h"
#include "runtime/platform/extensions.h"
#include "runtime/sharings/sharing_factory.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/fixtures/platform_fixture.h"
@ -75,12 +76,12 @@ TEST_F(PlatformTest, getDevices) {
EXPECT_EQ(nullptr, allDevices);
}
TEST_F(PlatformTest, PlatformGetCompilerExtensions) {
std::string compilerExtensions = pPlatform->getCompilerExtensions();
TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
std::string compilerExtensions = pPlatform->peekCompilerExtensions();
EXPECT_EQ(std::string(""), compilerExtensions);
pPlatform->initialize(numPlatformDevices, platformDevices);
compilerExtensions = pPlatform->getCompilerExtensions();
compilerExtensions = pPlatform->peekCompilerExtensions();
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("-cl-ext=-all,+cl")));
if (std::string(pPlatform->getDevice(0)->getDeviceInfo().clVersion).find("OpenCL 2.1") != std::string::npos) {
@ -151,3 +152,51 @@ TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenIn
EXPECT_FALSE(platform->isInitialized());
delete platform;
}
TEST_F(PlatformTest, getAsCompilerEnabledExtensionsString) {
const HardwareInfo *hwInfo;
hwInfo = platformDevices[0];
std::string extensionsList = getExtensionsList(*hwInfo);
EXPECT_THAT(extensionsList, ::testing::HasSubstr(std::string("cl_khr_3d_image_writes")));
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("-cl-ext=-all,+cl")));
if (hwInfo->capabilityTable.clVersionSupport > 20) {
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_subgroups")));
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_il_program")));
}
if (hwInfo->capabilityTable.ftrSupportsFP64) {
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_fp64")));
}
}
TEST_F(PlatformTest, getAsCompilerEnabledExtensionsStringTestNotFP64) {
HardwareInfo TesthwInfo = *platformDevices[0];
TesthwInfo.capabilityTable.ftrSupportsFP64 = false;
TesthwInfo.capabilityTable.clVersionSupport = 10;
std::string extensionsList = getExtensionsList(TesthwInfo);
EXPECT_THAT(extensionsList, ::testing::HasSubstr(std::string("cl_khr_3d_image_writes")));
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("-cl-ext=-all,+cl")));
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_fp64"))));
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_subgroups"))));
}
TEST_F(PlatformTest, testRemoveLastSpace) {
std::string emptyString = "";
removeLastSpace(emptyString);
EXPECT_EQ(std::string(""), emptyString);
std::string xString = "x";
removeLastSpace(xString);
EXPECT_EQ(std::string("x"), xString);
std::string xSpaceString = "x ";
removeLastSpace(xSpaceString);
EXPECT_EQ(std::string("x"), xSpaceString);
}