mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-24 15:59:03 +00:00
Reimplement invocation of offline compilation program
This change reimplements offline compiler invocation, using a new command
line interface that allows the passing of relevant CL device information
to the offline compiler. The information that is passed is as follows:
* CL_DEVICE_ADDRESS_BITS
* CL_DEVICE_EXTENSIONS
* CL_DEVICE_IL_VERSION (with --compilation-mode=spir-v only)
* CL_DEVICE_VERSION
The interface for the offline compiler script is as follows:
usage: cl_offline_compiler --source FILE --output FILE
--cl-device-info FILE --mode MODE
-- [BUILD_OPTIONS [BUILD_OPTIONS ...]]
positional arguments:
BUILD_OPTIONS additional options to pass to the compiler
optional arguments:
--source FILE OpenCL C source file to compile
--output FILE SPIR-V or binary file to create
--cl-device-info FILE OpenCL device info file
--mode compilation mode (spir-v or binary)
The OpenCL C version for compilation is now specified in BUILD_OPTIONS,
as normal for online compilation, i.e. with -cl-std=VERSION.
Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
committed by
Kévin Petit
parent
2c43504923
commit
0d96c198ee
@@ -1,7 +0,0 @@
|
||||
# Script parameters:
|
||||
# 1 - input file
|
||||
# 2 - output file
|
||||
# 3 - architecture: 32 or 64
|
||||
# 4 - one of the strings: binary, source, spir_v
|
||||
# 5 - OpenCL version: 12, 20
|
||||
# 6 - build options
|
||||
@@ -1,43 +0,0 @@
|
||||
# Script parameters:
|
||||
# 1 - input file
|
||||
# 2 - output file
|
||||
# 3 - architecture: 32 or 64
|
||||
# 4 - one of the strings: binary, source, spir_v
|
||||
# 5 - OpenCL version: 12, 20
|
||||
# 6 - build options
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if len(sys.argv)<5:
|
||||
print 'Usage: "build_script_spirv.py <input> <output> <arch> <output_type> <opencl_version> [build_options]"'
|
||||
exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
arch = sys.argv[3]
|
||||
output_type = sys.argv[4]
|
||||
ocl_version = sys.argv[5]
|
||||
build_options = ''
|
||||
|
||||
if len(sys.argv) == 5:
|
||||
build_options = sys.argv[6]
|
||||
|
||||
if arch == '32':
|
||||
arch_string = ''
|
||||
spir_arch = '__i386__'
|
||||
else:
|
||||
arch_string = '64'
|
||||
spir_arch = '__x86_64__'
|
||||
|
||||
if ocl_version == '20':
|
||||
oclc_version = '200'
|
||||
spir_version = '2.0'
|
||||
else:
|
||||
oclc_version = '120'
|
||||
spir_version = '1.2'
|
||||
|
||||
command = '%LLVMPATH%\\bin\\clang.exe -cc1 -include headers\\opencl_SPIR-' + spir_version + '.h -cl-std=CL' + spir_version +' -D__OPENCL_C_VERSION__=' + oclc_version + ' -fno-validate-pch -D__OPENCL_VERSION__=' + oclc_version + ' -x cl -cl-kernel-arg-info -O0 -emit-llvm-bc -triple spir' + arch_string + '-unknown-unknown -D' + spir_arch + ' -Dcl_khr_3d_image_writes -Dcl_khr_byte_addressable_store -Dcl_khr_d3d10_sharing -Dcl_khr_d3d11_sharing -Dcl_khr_depth_images -Dcl_khr_dx9_media_sharing -Dcl_khr_fp64 -Dcl_khr_global_int32_base_atomics -Dcl_khr_global_int32_extended_atomics -Dcl_khr_gl_depth_images -Dcl_khr_gl_event -Dcl_khr_gl_msaa_sharing -Dcl_khr_gl_sharing -Dcl_khr_icd -Dcl_khr_image2d_from_buffer -Dcl_khr_local_int32_base_atomics -Dcl_khr_local_int32_extended_atomics -Dcl_khr_mipmap_image -Dcl_khr_mipmap_image_writes -Dcl_khr_fp16 ' + build_options + ' -Dcl_khr_spir ' + input_file + ' -o intermediate.spir'
|
||||
os.system(command)
|
||||
command = '%LLVMPATH%\\bin\\llvm-spirv.exe intermediate.spir -o ' + output_file
|
||||
os.system(command)
|
||||
@@ -4,19 +4,17 @@ from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print('Usage: "generate_spirv_offline.py <compilation_cache_dir> <32|64>"')
|
||||
print('Usage: "generate_spirv_offline.py <compilation_cache_dir> <cl_device_info_file>"')
|
||||
exit(1)
|
||||
|
||||
compilation_cache_dir = sys.argv[1]
|
||||
arch = sys.argv[2]
|
||||
cl_device_info_filename = sys.argv[2]
|
||||
|
||||
def generate_spirv():
|
||||
print("Generating SPIR-V files")
|
||||
ocl_version = '12';
|
||||
build_options = ''
|
||||
|
||||
if os.path.exists(compilation_cache_dir):
|
||||
@@ -24,23 +22,18 @@ def generate_spirv():
|
||||
for file in files:
|
||||
if file.endswith('.cl'):
|
||||
options_file_name = file[:-2] + "options"
|
||||
ocl_version = '12'
|
||||
if os.path.exists(os.path.join(root, options_file_name)):
|
||||
optFile = open (os.path.join(root, options_file_name), 'rU')
|
||||
for line in optFile:
|
||||
if re.search("-cl-std=CL2.0", line):
|
||||
ocl_version = '20'
|
||||
build_options = re.sub("-cl-std=CL2.0", "", line)
|
||||
optFile = open (os.path.join(root, options_file_name), 'r')
|
||||
build_options = optFile.readline().strip()
|
||||
print(build_options)
|
||||
source_filename = os.path.join(root, file)
|
||||
output_filename = os.path.join(root, file[:-2]) + "spv" + arch
|
||||
output_filename = os.path.join(root, file[:-2]) + "spv"
|
||||
|
||||
command_line = (".\\build_script_spirv.py" +
|
||||
" " + source_filename +
|
||||
" " + output_filename +
|
||||
" " + arch +
|
||||
" spir_v" +
|
||||
" " + ocl_version +
|
||||
command_line = ("cl_offline_compiler" +
|
||||
" --source=" + source_filename +
|
||||
" --output=" + output_filename +
|
||||
" --cl-device-info=" + cl_device_info_filename +
|
||||
" --mode=spir-v -- " +
|
||||
'"' + build_options + '"')
|
||||
print(command_line)
|
||||
os.system(command_line)
|
||||
|
||||
Reference in New Issue
Block a user