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 = compiler_is_prgenv(compiler_val) 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) if cpu and cpu != 'none' and cpu != 'unknown': # x86 uses -march= where the others use -mcpu= if is_x86_variant(get_native_machine()): flag = 'arch' else: flag = 'cpu' else: flag = 'none' return cpu_tuple(flag or 'none', cpu or 'unknown')
def get_link_args(): link_args = third_party_utils.default_get_link_args( "qthread", ucp=get_uniq_cfg_path(), libs=["libqthread_chpl.la", "-lchpl", "libqthread.la"] ) compiler_val = chpl_compiler.get("target") if compiler_val == "cray-prgenv-cray" or (compiler_is_prgenv(compiler_val) and chpl_llvm.get() != "none"): link_args.append("-lrt") return link_args
def get_link_args(): link_args = \ third_party_utils.default_get_link_args('qthread', ucp=get_uniq_cfg_path(), libs=['libqthread_chpl.la', '-lchpl', 'libqthread.la']) compiler_val = chpl_compiler.get('target') if ( compiler_val == 'cray-prgenv-cray' or (compiler_is_prgenv(compiler_val) and chpl_llvm.get() != 'none' )): link_args.append('-lrt') return link_args
def adjust_architecture_for_compiler(arch, flag, get_lcd): compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = compiler_is_prgenv(compiler_val) if compiler_val == 'clang-included': isprgenv = compiler_is_prgenv(chpl_compiler.get(flag, llvm_mode="orig")) if isprgenv: cray_arch = os.environ.get('CRAY_CPU_TARGET', 'none') if arch and (arch != 'none' and arch != 'unknown' and arch != cray_arch): 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") arch = cray_arch if arch == '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: arch = get_module_lcd_arch(platform_val, arch) if arch == '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 arch elif 'pgi' in compiler_val: return 'none' elif 'cray' in compiler_val: return 'none' elif 'ibm' in compiler_val: return 'none' return arch
def adjust_cpu_for_compiler(cpu, flag, get_lcd): compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = compiler_is_prgenv(compiler_val) if compiler_val == 'clang-included': isprgenv = compiler_is_prgenv(chpl_compiler.get(flag, llvm_mode="orig")) 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 verify_arch(arch, flag): comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = compiler_is_prgenv(compiler_val) # 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_arch = False if not isprgenv: if flag == 'target': if comm_val == 'none': if ('linux' in platform_val or platform_val == 'darwin' or platform_val.startswith('cygwin')): check_arch = True if flag == 'host': check_arch = True if check_arch and arch and arch 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. machine = machine_for_arch(arch) cur_machine = get_native_machine() warn = (machine != cur_machine) try: vendor_string, feature_string = get_cpuinfo(platform_val) detected_arch = feature_sets.find(vendor_string, feature_string) if not feature_sets.subset(arch, detected_arch): 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): arch_tuple = collections.namedtuple('arch_tuple', ['flag', 'arch']) if not flag or flag == 'host': arch = overrides.get('CHPL_HOST_ARCH', '') elif flag == 'target': arch = overrides.get('CHPL_TARGET_ARCH', '') else: raise InvalidLocationError(flag) # fast path out for when the user has set arch=none if arch == 'none' or (flag == 'host' and not arch): return arch_tuple('none', 'none') # Adjust arch for compiler (not all compilers support all arch # settings; PrgEnv might override arch, etc) arch = adjust_architecture_for_compiler(arch, flag, get_lcd) # Now, if is not yet set, we should set the default. if not arch: arch = default_arch(flag) verify_arch(arch, flag) compiler_val = chpl_compiler.get(flag) isprgenv = compiler_is_prgenv(compiler_val) if map_to_compiler and not isprgenv: # Map flag/arch to compiler flag/argument # Don't do this for PrgEnv compiles since the compiler driver # handles specialization. version = get_compiler_version(compiler_val) (flag, arch) = argument_map.find(arch, compiler_val, version) elif arch and arch != 'none' and arch != 'unknown': if is_known_arm(arch): flag = 'cpu' else: flag = 'arch' else: flag = 'none' return arch_tuple(flag or 'none', arch or 'unknown')
def verify_cpu(cpu, flag): comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(flag) platform_val = chpl_platform.get(flag) isprgenv = compiler_is_prgenv(compiler_val) # 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 not isprgenv: if flag == 'target': if comm_val == 'none': 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(location, map_to_compiler=False, get_lcd=False): arch_tuple = collections.namedtuple('arch_tuple', ['flag', 'arch']) if not location or location == "host": arch = overrides.get('CHPL_HOST_ARCH', '') elif location == 'target': arch = overrides.get('CHPL_TARGET_ARCH', '') else: raise InvalidLocationError(location) # fast path out for when the user has set arch=none if arch == 'none': return arch_tuple('none', arch) comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(location) platform_val = chpl_platform.get(location) isprgenv = compiler_is_prgenv(compiler_val) if compiler_val == 'clang-included': isprgenv = compiler_is_prgenv( chpl_compiler.get(location, llvm_mode="orig")) if isprgenv: cray_arch = os.environ.get('CRAY_CPU_TARGET', 'none') if arch and (arch != 'none' and arch != 'unknown' and arch != cray_arch): 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") arch = cray_arch if arch == '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: arch = get_module_lcd_arch(platform_val, arch) if arch == '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") if is_known_arm(arch): return arch_tuple('cpu', arch) else: return arch_tuple('arch', arch) elif 'pgi' in compiler_val: return arch_tuple('none', 'none') elif 'cray' in compiler_val: return arch_tuple('none', 'none') elif 'ibm' in compiler_val: return arch_tuple('none', 'none') # Only try to do any auto-detection or 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 # if comm_val == 'none' and ('linux' in platform_val or platform_val == 'darwin' or platform_val.startswith('cygwin')): if arch and arch not in ['none', 'unknown', 'native']: if location == 'host': # when a user supplies an architecture, and it seems reasonable # to double check their choice we do so. This will only # generate a warning that the user may not be able to run # whatever they compile. # # This only runs when location is 'host' since we # conservatively assume that a setting for 'target' could be in # a cross-compilation setting try: vendor_string, feature_string = get_cpuinfo(platform_val) detected_arch = feature_sets.find(vendor_string, feature_string) if not feature_sets.subset(arch, detected_arch): 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") except ValueError: stderr.write( "Warning: Unknown platform, could not find CPU information\n" ) else: # Clang cannot detect the architecture for aarch64. Otherwise, # let the backend compiler do the actual feature set detection. We # could be more aggressive in setting a precise architecture using # the double checking code above, but it seems like a waste of time # to not use the work the backend compilers have already done if compiler_val in ['clang', 'clang-included']: if get_native_machine() == 'aarch64': arch = 'unknown' else: arch = 'native' else: arch = 'native' if map_to_compiler: version = get_compiler_version(compiler_val) (flag, arch) = argument_map.find(arch, compiler_val, version) elif arch and arch != 'none' and arch != 'unknown': if is_known_arm(arch): flag = 'cpu' else: flag = 'arch' else: flag = 'none' return arch_tuple(flag or 'none', arch or 'unknown')
def get(location, map_to_compiler=False, get_lcd=False): arch_tuple = collections.namedtuple('arch_tuple', ['flag', 'arch']) if not location or location == "host": arch = overrides.get('CHPL_HOST_ARCH', '') elif location == 'target': arch = overrides.get('CHPL_TARGET_ARCH', '') else: raise InvalidLocationError(location) # fast path out for when the user has set arch=none if arch == 'none': return arch_tuple('none', arch) comm_val = chpl_comm.get() compiler_val = chpl_compiler.get(location) platform_val = chpl_platform.get(location) isprgenv = compiler_is_prgenv(compiler_val) if compiler_val == 'clang-included': isprgenv = compiler_is_prgenv(chpl_compiler.get(location, llvm_mode="orig")) if isprgenv: cray_arch = os.environ.get('CRAY_CPU_TARGET', 'none') if arch and (arch != 'none' and arch != 'unknown' and arch != cray_arch): 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") arch = cray_arch if arch == '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: arch = get_module_lcd_arch(platform_val, arch) if arch == '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") if is_known_arm(arch): return arch_tuple('cpu', arch) else: return arch_tuple('arch', arch) elif 'pgi' in compiler_val: return arch_tuple('none', 'none') elif 'cray' in compiler_val: return arch_tuple('none', 'none') elif 'ibm' in compiler_val: return arch_tuple('none', 'none') # Only try to do any auto-detection or 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 # if comm_val == 'none' and ('linux' in platform_val or platform_val == 'darwin' or platform_val.startswith('cygwin')): if arch and arch not in ['none', 'unknown', 'native']: if location == 'host': # when a user supplies an architecture, and it seems reasonable # to double check their choice we do so. This will only # generate a warning that the user may not be able to run # whatever they compile. # # This only runs when location is 'host' since we # conservatively assume that a setting for 'target' could be in # a cross-compilation setting try: vendor_string, feature_string = get_cpuinfo(platform_val) detected_arch = feature_sets.find(vendor_string, feature_string) if not feature_sets.subset(arch, detected_arch): 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") except ValueError: stderr.write("Warning: Unknown platform, could not find CPU information\n") else: # Clang cannot detect the architecture for aarch64. Otherwise, # let the backend compiler do the actual feature set detection. We # could be more aggressive in setting a precise architecture using # the double checking code above, but it seems like a waste of time # to not use the work the backend compilers have already done if compiler_val in ['clang', 'clang-included']: if get_native_machine() == 'aarch64': arch = 'unknown' else: arch = 'native' else: arch = 'native' if map_to_compiler: version = get_compiler_version(compiler_val) (flag, arch) = argument_map.find(arch, compiler_val, version) elif arch and arch != 'none' and arch != 'unknown': if is_known_arm(arch): flag = 'cpu' else: flag = 'arch' else: flag = 'none' return arch_tuple(flag or 'none', arch or 'unknown')