mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Align offline compilation with cl21_trunk (#400)
Add a special case for the Khronos compiler and always use it for OpenCL C++, otherwise use the same logic as on the cl21_trunk branch. The CMake option to pass the path to the khronos compiler has been renamed to KHRONOS_OFFLINE_COMPILER_OPTIONS and is no longer mandatory. Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
@@ -24,7 +24,6 @@ script:
|
|||||||
- cmake -DCL_INCLUDE_DIR=${TOP}/OpenCL-Headers
|
- cmake -DCL_INCLUDE_DIR=${TOP}/OpenCL-Headers
|
||||||
-DCL_LIB_DIR=${TOP}/OpenCL-ICD-Loader/build
|
-DCL_LIB_DIR=${TOP}/OpenCL-ICD-Loader/build
|
||||||
-DCL_LIBCLCXX_DIR=${TOP}/libclcxx
|
-DCL_LIBCLCXX_DIR=${TOP}/libclcxx
|
||||||
-DCL_OFFLINE_COMPILER=/dummy/path/to/compiler
|
|
||||||
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=./bin
|
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=./bin
|
||||||
-DOPENCL_LIBRARIES="-lOpenCL -lpthread"
|
-DOPENCL_LIBRARIES="-lOpenCL -lpthread"
|
||||||
..
|
..
|
||||||
|
|||||||
@@ -92,18 +92,18 @@ endif(CLPP_DEVELOPMENT_OPTIONS)
|
|||||||
# Path to offline OpenCL C/C++ compiler provided by Khronos.
|
# Path to offline OpenCL C/C++ compiler provided by Khronos.
|
||||||
# See https://github.com/KhronosGroup/SPIR/ (spirv-1.1 branch or newer SPIR-V-ready
|
# See https://github.com/KhronosGroup/SPIR/ (spirv-1.1 branch or newer SPIR-V-ready
|
||||||
# branch should be used).
|
# branch should be used).
|
||||||
if(CL_OFFLINE_COMPILER)
|
if(KHRONOS_OFFLINE_COMPILER)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCL_OFFLINE_COMPILER=${CL_OFFLINE_COMPILER}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DKHRONOS_OFFLINE_COMPILER=${KHRONOS_OFFLINE_COMPILER}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCL_OFFLINE_COMPILER=${CL_OFFLINE_COMPILER}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKHRONOS_OFFLINE_COMPILER=${KHRONOS_OFFLINE_COMPILER}")
|
||||||
# Additional OpenCL C/C++ compiler option.
|
# Additional OpenCL C/C++ compiler option.
|
||||||
if(CL_OFFLINE_COMPILER_OPTIONS)
|
if(KHRONOS_OFFLINE_COMPILER_OPTIONS)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCL_OFFLINE_COMPILER_OPTIONS=${CL_OFFLINE_COMPILER_OPTIONS}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DKHRONOS_OFFLINE_COMPILER_OPTIONS=${KHRONOS_OFFLINE_COMPILER_OPTIONS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCL_OFFLINE_COMPILER_OPTIONS=${CL_OFFLINE_COMPILER_OPTIONS}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKHRONOS_OFFLINE_COMPILER_OPTIONS=${KHRONOS_OFFLINE_COMPILER_OPTIONS}")
|
||||||
endif(CL_OFFLINE_COMPILER_OPTIONS)
|
endif(KHRONOS_OFFLINE_COMPILER_OPTIONS)
|
||||||
else(CL_OFFLINE_COMPILER)
|
else(KHRONOS_OFFLINE_COMPILER)
|
||||||
message(STATUS "OpenCL C/C++ compiler hasn't been found!")
|
message(WARNING "KHRONOS_OFFLINE_COMPILER is not defined!")
|
||||||
message(FATAL_ERROR "Pass path to OpenCL C/C++ compiler in CL_OFFLINE_COMPILER")
|
message(WARNING "Running CL C++ tests will not be possible.")
|
||||||
endif(CL_OFFLINE_COMPILER)
|
endif(KHRONOS_OFFLINE_COMPILER)
|
||||||
|
|
||||||
# CL_LIBCLCXX_DIR - path to dir with OpenCL C++ STL (libclcxx)
|
# CL_LIBCLCXX_DIR - path to dir with OpenCL C++ STL (libclcxx)
|
||||||
# CL_INCLUDE_DIR - path to dir with OpenCL headers
|
# CL_INCLUDE_DIR - path to dir with OpenCL headers
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
mkdir -p build_lnx
|
mkdir -p build_lnx
|
||||||
cd build_lnx
|
cd build_lnx
|
||||||
cmake -g "Unix Makefiles" ../ -DCL_OFFLINE_COMPILER=<TO_SET> -DCL_LIBCLCXX_DIR=<TO_SET> -DCL_INCLUDE_DIR=<TO_SET> -DCL_LIB_DIR=<TO_SET> -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=. -DOPENCL_LIBRARIES=OpenCL
|
cmake -g "Unix Makefiles" ../ -DKHRONOS_OFFLINE_COMPILER=<TO_SET> -DCL_LIBCLCXX_DIR=<TO_SET> -DCL_INCLUDE_DIR=<TO_SET> -DCL_LIB_DIR=<TO_SET> -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=. -DOPENCL_LIBRARIES=OpenCL
|
||||||
make --jobs 8
|
make --jobs 8
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ mkdir build_win
|
|||||||
pushd build_win
|
pushd build_win
|
||||||
IF NOT EXIST CLConform.sln (
|
IF NOT EXIST CLConform.sln (
|
||||||
echo "Solution file not found, running Cmake"
|
echo "Solution file not found, running Cmake"
|
||||||
cmake -G "Visual Studio 14 2015 Win64" ..\. -DCL_OFFLINE_COMPILER=<TO_SET> -DCL_LIBCLCXX_DIR=<TO_SET> -DCL_INCLUDE_DIR=<TO_SET> -DCL_LIB_DIR=<TO_SET> -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=. -DOPENCL_LIBRARIES=OpenCL
|
cmake -G "Visual Studio 14 2015 Win64" ..\. -DKHRONOS_OFFLINE_COMPILER=<TO_SET> -DCL_LIBCLCXX_DIR=<TO_SET> -DCL_INCLUDE_DIR=<TO_SET> -DCL_LIB_DIR=<TO_SET> -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=. -DOPENCL_LIBRARIES=OpenCL
|
||||||
) else (
|
) else (
|
||||||
echo "Solution file found CLConform.sln "
|
echo "Solution file found CLConform.sln "
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ static std::string get_offline_compilation_file_type_str(const CompilationMode c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string get_offline_compilation_command(const cl_uint device_address_space_size,
|
static std::string get_khronos_compiler_command(const cl_uint device_address_space_size,
|
||||||
const bool openclCXX,
|
const bool openclCXX,
|
||||||
const std::string &bOptions,
|
const std::string &bOptions,
|
||||||
const std::string &sourceFilename,
|
const std::string &sourceFilename,
|
||||||
@@ -261,8 +261,8 @@ static std::string get_offline_compilation_command(const cl_uint device_address_
|
|||||||
compilerOptions += " -include opencl.h";
|
compilerOptions += " -include opencl.h";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CL_OFFLINE_COMPILER_OPTIONS
|
#ifdef KHRONOS_OFFLINE_COMPILER_OPTIONS
|
||||||
compilerOptions += STRINGIFY_VALUE(CL_OFFLINE_COMPILER_OPTIONS);
|
compilerOptions += STRINGIFY_VALUE(KHRONOS_OFFLINE_COMPILER_OPTIONS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Add build options passed to this function
|
// Add build options passed to this function
|
||||||
@@ -270,21 +270,113 @@ static std::string get_offline_compilation_command(const cl_uint device_address_
|
|||||||
compilerOptions +=
|
compilerOptions +=
|
||||||
" " + sourceFilename +
|
" " + sourceFilename +
|
||||||
" -o " + outputFilename;
|
" -o " + outputFilename;
|
||||||
std::string runString = STRINGIFY_VALUE(CL_OFFLINE_COMPILER) + compilerOptions;
|
std::string runString = STRINGIFY_VALUE(KHRONOS_OFFLINE_COMPILER) + compilerOptions;
|
||||||
|
|
||||||
return runString;
|
return runString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int invoke_offline_compiler(cl_context context,
|
static std::string get_offline_compilation_command(const cl_uint device_address_space_size,
|
||||||
const cl_uint device_address_space_size,
|
const CompilationMode compilationMode,
|
||||||
const bool openclCXX,
|
|
||||||
const std::string &bOptions,
|
const std::string &bOptions,
|
||||||
const std::string &sourceFilename,
|
const std::string &sourceFilename,
|
||||||
const std::string &outputFilename)
|
const std::string &outputFilename)
|
||||||
{
|
{
|
||||||
std::string runString =
|
std::ostringstream size_t_width_stream;
|
||||||
get_offline_compilation_command(device_address_space_size, openclCXX, bOptions,
|
size_t_width_stream << device_address_space_size;
|
||||||
|
std::string size_t_width_str = size_t_width_stream.str();
|
||||||
|
|
||||||
|
// set output type and default script
|
||||||
|
std::string outputTypeStr;
|
||||||
|
std::string defaultScript;
|
||||||
|
if (compilationMode == kBinary)
|
||||||
|
{
|
||||||
|
outputTypeStr = "binary";
|
||||||
|
#if defined(_WIN32)
|
||||||
|
defaultScript = "..\\build_script_binary.py ";
|
||||||
|
#else
|
||||||
|
defaultScript = "../build_script_binary.py ";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (compilationMode == kSpir_v)
|
||||||
|
{
|
||||||
|
outputTypeStr = "spir_v";
|
||||||
|
#if defined(_WIN32)
|
||||||
|
defaultScript = "..\\build_script_spirv.py ";
|
||||||
|
#else
|
||||||
|
defaultScript = "../build_script_spirv.py ";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// set script arguments
|
||||||
|
std::string scriptArgs = sourceFilename + " " + outputFilename + " " + size_t_width_str + " " + outputTypeStr;
|
||||||
|
|
||||||
|
if (!bOptions.empty())
|
||||||
|
{
|
||||||
|
//search for 2.0 build options
|
||||||
|
std::string oclVersion;
|
||||||
|
std::string buildOptions20 = "-cl-std=CL2.0";
|
||||||
|
std::size_t found = bOptions.find(buildOptions20);
|
||||||
|
|
||||||
|
if (found != std::string::npos)
|
||||||
|
oclVersion = "20";
|
||||||
|
else
|
||||||
|
oclVersion = "12";
|
||||||
|
|
||||||
|
std::string bOptionsWRemovedStd20 = bOptions;
|
||||||
|
|
||||||
|
std::string::size_type i = bOptions.find(buildOptions20);
|
||||||
|
|
||||||
|
if (i != std::string::npos)
|
||||||
|
bOptionsWRemovedStd20.erase(i, buildOptions20.length());
|
||||||
|
|
||||||
|
//remove space before -cl-std=CL2.0 if it was first build option
|
||||||
|
size_t spacePos = bOptionsWRemovedStd20.find_last_of(" \t\r\n", i);
|
||||||
|
if (spacePos != std::string::npos && i == 0)
|
||||||
|
bOptionsWRemovedStd20.erase(spacePos, sizeof(char));
|
||||||
|
|
||||||
|
//remove space after -cl-std=CL2.0
|
||||||
|
spacePos = bOptionsWRemovedStd20.find_first_of(" \t\r\n", i - 1);
|
||||||
|
if (spacePos != std::string::npos)
|
||||||
|
bOptionsWRemovedStd20.erase(spacePos, sizeof(char));
|
||||||
|
|
||||||
|
if (!bOptionsWRemovedStd20.empty())
|
||||||
|
scriptArgs += " " + oclVersion + " \"" + bOptionsWRemovedStd20 + "\"";
|
||||||
|
else
|
||||||
|
scriptArgs += " " + oclVersion;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
scriptArgs += " 12";
|
||||||
|
|
||||||
|
// set script command line
|
||||||
|
std::string scriptToRunString = defaultScript + scriptArgs;
|
||||||
|
|
||||||
|
return scriptToRunString;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int invoke_offline_compiler(cl_context context,
|
||||||
|
const cl_uint device_address_space_size,
|
||||||
|
const CompilationMode compilationMode,
|
||||||
|
const std::string &bOptions,
|
||||||
|
const std::string &sourceFilename,
|
||||||
|
const std::string &outputFilename,
|
||||||
|
const bool openclCXX)
|
||||||
|
{
|
||||||
|
std::string runString;
|
||||||
|
if (openclCXX)
|
||||||
|
{
|
||||||
|
#ifndef KHRONOS_OFFLINE_COMPILER
|
||||||
|
log_error("CL C++ compilation is not possible: KHRONOS_OFFLINE_COMPILER was not defined.\n");
|
||||||
|
return CL_INVALID_OPERATION;
|
||||||
|
#else
|
||||||
|
runString = get_khronos_compiler_command(device_address_space_size, openclCXX, bOptions,
|
||||||
sourceFilename, outputFilename);
|
sourceFilename, outputFilename);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runString = get_offline_compilation_command(device_address_space_size, compilationMode, bOptions,
|
||||||
|
sourceFilename, outputFilename);
|
||||||
|
}
|
||||||
|
|
||||||
// execute script
|
// execute script
|
||||||
log_info("Executing command: %s\n", runString.c_str());
|
log_info("Executing command: %s\n", runString.c_str());
|
||||||
@@ -395,8 +487,8 @@ static int get_offline_compiler_output(std::ifstream &ifs,
|
|||||||
ofs.write(kernel.c_str(), kernel.size());
|
ofs.write(kernel.c_str(), kernel.size());
|
||||||
ofs.close();
|
ofs.close();
|
||||||
|
|
||||||
error = invoke_offline_compiler(context, device_address_space_size, openclCXX,
|
error = invoke_offline_compiler(context, device_address_space_size, compilationMode,
|
||||||
bOptions, sourceFilename, outputFilename);
|
bOptions, sourceFilename, outputFilename, openclCXX);
|
||||||
if (error != CL_SUCCESS)
|
if (error != CL_SUCCESS)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -520,13 +612,9 @@ static int create_single_kernel_helper_create_program(cl_context context,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef CL_OFFLINE_COMPILER
|
|
||||||
return create_single_kernel_helper_create_program_offline(context, outProgram, numKernelLines,
|
return create_single_kernel_helper_create_program_offline(context, outProgram, numKernelLines,
|
||||||
kernelProgram, buildOptions,
|
kernelProgram, buildOptions,
|
||||||
openclCXX, compilationMode);
|
openclCXX, compilationMode);
|
||||||
#endif
|
|
||||||
log_error("Offline compilation is not possible: CL_OFFLINE_COMPILER was not defined.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user