def adjust_cpu_for_compiler(cpu, flag, get_lcd): compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = flag == 'target' and target_compiler_is_prgenv() if isprgenv: cray_cpu = os.environ.get('CRAY_CPU_TARGET', 'none') if cpu and (cpu != 'none' and cpu != 'unknown' and cpu != cray_cpu): stderr.write("Warning: Setting the processor type through " "environment variables is not supported for " "cray-prgenv-*. Please use the appropriate craype-* " "module for your processor type.\n") cpu = cray_cpu if cpu == 'none': stderr.write("Warning: No craype-* processor type module was " "detected, please load the appropriate one if you want " "any specialization to occur.\n") if get_lcd: cpu = get_module_lcd_cpu(platform_val, cpu) if cpu == 'none': stderr.write("Warning: Could not detect the lowest common " "denominator processor type for this platform. " "You may be unable to use the Chapel compiler\n") return cpu elif 'pgi' in compiler_val: return 'none' elif 'cray' in compiler_val: return 'none' elif 'ibm' in compiler_val: return 'none' return cpu
def filter_compile_args(args): compiler = chpl_compiler.get('target') is_prgenv = compiler_utils.target_compiler_is_prgenv(bypass_llvm=True) ret = [ ] if compiler == 'llvm' and is_prgenv: # filter out compile arguments not starting with -D or -I n = len(args) i = 0 while i < n: s = args[i] if s.startswith('-D') or s.startswith('-I'): ret.append(s) if len(s) == 2 and i+1 < n: # if it was just -D or -I, add the next argument too i += 1 ret.append(args[i]) i += 1 return ret else: # otherwise, just return the args the way they were ret = args # subsequently, filter away a few gasnet flags we don't want # an alternative to this filtering would be to only grab # certain flags from the gasnet .pc file more_filtered = [ ] for arg in ret: if arg.startswith('-O') or arg == '-Winline': pass # leave out this flag else: more_filtered.append(arg) return more_filtered
def adjust_cpu_for_compiler(cpu, flag, get_lcd): compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = flag == 'target' and target_compiler_is_prgenv() if isprgenv: cray_cpu = os.environ.get('CRAY_CPU_TARGET', 'none') if cpu and (cpu != 'none' and cpu != 'unknown' and cpu != cray_cpu): stderr.write("Warning: Setting the processor type through " "environment variables is not supported for " "cray-prgenv-*. Please use the appropriate craype-* " "module for your processor type.\n") cpu = cray_cpu if cpu == 'none': stderr.write( "Warning: No craype-* processor type module was " "detected, please load the appropriate one if you want " "any specialization to occur.\n") if get_lcd: cpu = get_module_lcd_cpu(platform_val, cpu) if cpu == 'none': stderr.write("Warning: Could not detect the lowest common " "denominator processor type for this platform. " "You may be unable to use the Chapel compiler\n") return cpu elif 'pgi' in compiler_val: return 'none' elif 'cray' in compiler_val: return 'none' elif 'ibm' in compiler_val: return 'none' return cpu
def adjust_cpu_for_compiler(cpu, flag, get_lcd): compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = flag == 'target' and target_compiler_is_prgenv() if isprgenv: cray_cpu = os.environ.get('CRAY_CPU_TARGET', 'none') has_cpu = cpu and cpu != 'none' and cpu != 'unknown' has_cray_cpu = cray_cpu and cray_cpu != 'none' and cray_cpu != 'unknown' if compiler_val == 'llvm': # if the CPU type is not set, use the cray_cpu, # but allow overriding it with CHPL_TARGET_CPU. if has_cray_cpu and not has_cpu: cpu = cray_cpu else: # for C compilation, CPU needs to be set by cray-prgenv-* # and not by e.g. CHPL_TARGET_CPU. cpu = cray_cpu if has_cpu: warning("Setting the processor type through environment " "variables is not supported for cray-prgenv-*. " "Please use the appropriate craype-* module for your " "processor type.") if not has_cray_cpu: warning("No craype-* processor type module was detected, " "please load the appropriate one if you want any " "specialization to occur.") if get_lcd: cpu = get_module_lcd_cpu(platform_val, cpu) if cpu == 'none': warning("Could not detect the lowest common denominator " "processor type for this platform. You may be unable " "to use the Chapel compiler") return cpu elif 'pgi' in compiler_val: return 'none' elif 'cray' in compiler_val: return 'none' elif 'ibm' in compiler_val: return 'none' return cpu
def verify_cpu(cpu, flag): comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) # Only try to do any architecture verification when: # comm == none -- The inverse means that we are probably cross-compiling. # # linux/dawin/ -- The only platforms that we should try and detect on. # cygwin Crays will be handled through the craype-* modules # check_cpu = False if flag == 'target': if comm_val == 'none': if not target_compiler_is_prgenv(): if ('linux' in platform_val or platform_val == 'darwin' or platform_val.startswith('cygwin')): check_cpu = True if flag == 'host': check_cpu = True if check_cpu and cpu and cpu not in ['none', 'unknown', 'native']: # Print a friendly warning if it's unlikely the user could run # their program. This could be printed in cross-compilation settings. warn = False try: vendor_string, feature_string = get_cpuinfo(platform_val) detected_cpu = feature_sets.find(vendor_string, feature_string) if not feature_sets.subset(cpu, detected_cpu): warn = True except ValueError: stderr.write("Warning: Unknown platform, could not find CPU information\n") if warn: stderr.write("Warning: The supplied processor type does " "not appear to be compatible with the host " "processor type. The resultant binary may " "not run on the current machine.\n")
def verify_cpu(cpu, flag): comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) # Only try to do any architecture verification when: # comm == none -- The inverse means that we are probably cross-compiling. # # linux/dawin/ -- The only platforms that we should try and detect on. # cygwin Crays will be handled through the craype-* modules # check_cpu = False if flag == 'target': if comm_val == 'none': if not target_compiler_is_prgenv(): if ('linux' in platform_val or platform_val == 'darwin' or platform_val.startswith('cygwin')): check_cpu = True if flag == 'host': check_cpu = True if check_cpu and cpu and cpu not in ['none', 'unknown', 'native']: # Print a friendly warning if it's unlikely the user could run # their program. This could be printed in cross-compilation settings. warn = False try: vendor_string, feature_string = get_cpuinfo(platform_val) detected_cpu = feature_sets.find(vendor_string, feature_string) if not feature_sets.subset(cpu, detected_cpu): warn = True except ValueError: stderr.write( "Warning: Unknown platform, could not find CPU information\n") if warn: stderr.write("Warning: The supplied processor type does " "not appear to be compatible with the host " "processor type. The resultant binary may " "not run on the current machine.\n")
def get(flag, map_to_compiler=False, get_lcd=False): cpu_tuple = collections.namedtuple('cpu_tuple', ['flag', 'cpu']) if not flag or flag == 'host': cpu = overrides.get('CHPL_HOST_CPU', '') elif flag == 'target': cpu = overrides.get('CHPL_TARGET_CPU', '') else: raise InvalidLocationError(flag) # fast path out for when the user has set arch=none if cpu == 'none' or (flag == 'host' and not cpu): return cpu_tuple('none', 'none') # Handle backwards compatability - CHPL_TARGET_ARCH might be # set instead of the currently preferred CHPL_TARGET_CPU. if not cpu: oldarch = None if not flag or flag == 'host': oldarch = overrides.get('CHPL_HOST_ARCH', '') elif flag == 'target': oldarch = overrides.get('CHPL_TARGET_ARCH', '') else: raise InvalidLocationError(flag) # If the oldarch indicates a CPU, use it if arch_for_cpu(oldarch, flag): cpu = oldarch # Adjust arch for compiler (not all compilers support all arch # settings; PrgEnv might override arch, etc) cpu = adjust_cpu_for_compiler (cpu, flag, get_lcd) # Now, if is not yet set, we should set the default. if not cpu: cpu = default_cpu(flag) verify_cpu(cpu, flag) compiler_val = chpl_compiler.get(flag) isprgenv = flag == 'target' and target_compiler_is_prgenv(not map_to_compiler) if map_to_compiler and not isprgenv: # Map cpu to compiler argument # Don't do this for PrgEnv compiles since the compiler driver # handles specialization. version = get_compiler_version(compiler_val) cpu = argument_map.find(cpu, compiler_val, version) argname = None if cpu and cpu != 'none' and cpu != 'unknown': # x86 uses -march= where the others use -mcpu= if is_x86_variant(get_native_machine()): argname = 'arch' else: argname = 'cpu' else: argname = 'none' return cpu_tuple(argname or 'none', cpu or 'unknown')
def get(flag, map_to_compiler=False, get_lcd=False): cpu_tuple = collections.namedtuple('cpu_tuple', ['flag', 'cpu']) if not flag or flag == 'host': cpu = overrides.get('CHPL_HOST_CPU', '') elif flag == 'target': cpu = overrides.get('CHPL_TARGET_CPU', '') else: raise InvalidLocationError(flag) # fast path out for when the user has set arch=none if cpu == 'none' or (flag == 'host' and not cpu): return cpu_tuple('none', 'none') # Handle backwards compatability - CHPL_TARGET_ARCH might be # set instead of the currently preferred CHPL_TARGET_CPU. if not cpu: oldarch = None if not flag or flag == 'host': oldarch = overrides.get('CHPL_HOST_ARCH', '') elif flag == 'target': oldarch = overrides.get('CHPL_TARGET_ARCH', '') else: raise InvalidLocationError(flag) # If the oldarch indicates a CPU, use it if arch_for_cpu(oldarch, flag): cpu = oldarch # Adjust arch for compiler (not all compilers support all arch # settings; PrgEnv might override arch, etc) cpu = adjust_cpu_for_compiler(cpu, flag, get_lcd) # Now, if is not yet set, we should set the default. if not cpu: cpu = default_cpu(flag) verify_cpu(cpu, flag) compiler_val = chpl_compiler.get(flag) isprgenv = flag == 'target' and target_compiler_is_prgenv( not map_to_compiler) if map_to_compiler and not isprgenv: # Map cpu to compiler argument # Don't do this for PrgEnv compiles since the compiler driver # handles specialization. version = get_compiler_version(compiler_val) cpu = argument_map.find(cpu, compiler_val, version) argname = None if cpu and cpu != 'none' and cpu != 'unknown': # x86 uses -march= where the others use -mcpu= if is_x86_variant(get_native_machine()): argname = 'arch' else: argname = 'cpu' else: argname = 'none' return cpu_tuple(argname or 'none', cpu or 'unknown')