github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/sycl/crosstool/trisycl.tpl (about) 1 #!/usr/bin/env python 2 3 import os 4 import sys 5 import tempfile 6 from subprocess import call 7 8 CPU_CXX_COMPILER = ('%{host_cxx_compiler}') 9 CPU_C_COMPILER = ('%{host_c_compiler}') 10 11 CURRENT_DIR = os.path.dirname(sys.argv[0]) 12 TRISYCL_INCLUDE_DIR = CURRENT_DIR + '/../sycl/include' 13 14 15 def main(): 16 compiler_flags = [] 17 18 remove_flags = ('-Wl,--no-undefined', '-Wno-unused-but-set-variable', 19 '-Wignored-attributes', '-fno-exceptions') 20 # remove -fsamotoze-coverage from string with g++ 21 if 'g++' in CPU_CXX_COMPILER: 22 remove_flags += ('-fsanitize-coverage',) 23 compiler_flags += ['-fopenmp'] 24 else: 25 compiler_flags += ['-fopenmp=libomp'] 26 27 compiler_flags += [ 28 flag for flag in sys.argv[1:] if not flag.startswith(remove_flags) 29 ] 30 31 output_file_index = compiler_flags.index('-o') + 1 32 output_file_name = compiler_flags[output_file_index] 33 34 if (output_file_index == 1): 35 # we are linking 36 return call([CPU_CXX_COMPILER] + compiler_flags + ['-Wl,--no-undefined']) 37 38 # find what we compile 39 compiling_cpp = 0 40 if ('-c' in compiler_flags): 41 compiled_file_index = compiler_flags.index('-c') + 1 42 compiled_file_name = compiler_flags[compiled_file_index] 43 if (compiled_file_name.endswith(('.cc', '.c++', '.cpp', '.CPP', '.C', 44 '.cxx'))): 45 compiling_cpp = 1 46 47 debug_flags = [ 48 '-DTRISYCL_DEBUG', '-DBOOST_LOG_DYN_LINK', '-DTRISYCL_TRACE_KERNEL', 49 '-lpthread', '-lboost_log', '-g', '-rdynamic' 50 ] 51 52 opt_flags = ['-DNDEBUG', '-DBOOST_DISABLE_ASSERTS', '-O3'] 53 54 compiler_flags = compiler_flags + [ 55 '-DEIGEN_USE_SYCL=1', '-DEIGEN_HAS_C99_MATH', 56 '-DEIGEN_MAX_ALIGN_BYTES=16', '-DTENSORFLOW_USE_SYCL' 57 ] + opt_flags 58 59 if (compiling_cpp == 1): 60 # create a blacklist of folders that will be skipped when compiling 61 # with triSYCL 62 skip_extensions = ['.cu.cc'] 63 skip_folders = [ 64 'tensorflow/compiler', 'tensorflow/docs_src', 'tensorflow/tensorboard', 65 'third_party', 'external', 'hexagon' 66 ] 67 skip_folders = [(folder + '/') for folder in skip_folders] 68 # if compiling external project skip triSYCL 69 if any( 70 compiled_file_name.endswith(_ext) for _ext in skip_extensions) or any( 71 _folder in output_file_name for _folder in skip_folders): 72 return call([CPU_CXX_COMPILER] + compiler_flags) 73 74 host_compiler_flags = [ 75 '-xc++', '-Wno-unused-variable', '-I', TRISYCL_INCLUDE_DIR 76 ] + compiler_flags 77 x = call([CPU_CXX_COMPILER] + host_compiler_flags) 78 return x 79 else: 80 # compile for C 81 return call([CPU_C_COMPILER] + compiler_flags) 82 83 84 if __name__ == '__main__': 85 sys.exit(main())