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:
Stuart Brady
2019-07-01 17:21:27 +01:00
committed by Kévin Petit
parent 2c43504923
commit 0d96c198ee
9 changed files with 210 additions and 135 deletions

View File

@@ -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)