1#!/usr/bin/env python 2 3from __future__ import print_function 4 5import sys 6import os 7import traceback 8 9if len(sys.argv) != 3: 10 print('Usage: "generate_spirv_offline.py <compilation_cache_dir> <cl_device_info_file>"') 11 exit(1) 12 13compilation_cache_dir = sys.argv[1] 14cl_device_info_filename = sys.argv[2] 15 16def generate_spirv(): 17 print("Generating SPIR-V files") 18 build_options = '' 19 20 if os.path.exists(compilation_cache_dir): 21 for root, dirs, files in os.walk(compilation_cache_dir): 22 for file in files: 23 if file.endswith('.cl'): 24 options_file_name = file[:-2] + "options" 25 if os.path.exists(os.path.join(root, options_file_name)): 26 optFile = open (os.path.join(root, options_file_name), 'r') 27 build_options = optFile.readline().strip() 28 print(build_options) 29 source_filename = os.path.join(root, file) 30 output_filename = os.path.join(root, file[:-2]) + "spv" 31 32 command_line = ("cl_offline_compiler" + 33 " --source=" + source_filename + 34 " --output=" + output_filename + 35 " --cl-device-info=" + cl_device_info_filename + 36 " --mode=spir-v -- " + 37 '"' + build_options + '"') 38 print(command_line) 39 os.system(command_line) 40 return 0 41 42def main(): 43 try: 44 generate_spirv() 45 except Exception: 46 traceback.print_exc(file=sys.stdout) 47 sys.exit(0) 48 49if __name__ == "__main__": 50 main() 51 52 53 54