41dbbb3789
contrib/ * gcc_update (files_and_dependencies): Update rules for new libgomp/plugin/Makefrag.am and libgomp/plugin/configfrag.ac files. gcc/ * builtin-types.def (BT_FN_VOID_INT_INT_VAR) (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR_INT_INT_VAR) (BT_FN_VOID_INT_OMPFN_PTR_SIZE_PTR_PTR_PTR_INT_INT_INT_INT_INT_VAR): New function types. * builtins.c: Include "gomp-constants.h". (expand_builtin_acc_on_device): New function. (expand_builtin, is_inexpensive_builtin): Handle BUILT_IN_ACC_ON_DEVICE. * builtins.def (DEF_GOACC_BUILTIN, DEF_GOACC_BUILTIN_COMPILER): New macros. * cgraph.c (cgraph_node::create): Consider flag_openacc next to flag_openmp. * config.gcc <nvptx-*> (tm_file): Add nvptx/offload.h. <*-intelmic-* | *-intelmicemul-*> (tm_file): Add i386/intelmic-offload.h. * gcc.c (LINK_COMMAND_SPEC, GOMP_SELF_SPECS): For -fopenacc, link to libgomp and its dependencies. * config/arc/arc.h (LINK_COMMAND_SPEC): Likewise. * config/darwin.h (LINK_COMMAND_SPEC_A): Likewise. * config/i386/mingw32.h (GOMP_SELF_SPECS): Likewise. * config/ia64/hpux.h (LIB_SPEC): Likewise. * config/pa/pa-hpux11.h (LIB_SPEC): Likewise. * config/pa/pa64-hpux.h (LIB_SPEC): Likewise. * doc/generic.texi: Update for OpenACC changes. * doc/gimple.texi: Likewise. * doc/invoke.texi: Likewise. * doc/sourcebuild.texi: Likewise. * gimple-pretty-print.c (dump_gimple_omp_for): Handle GF_OMP_FOR_KIND_OACC_LOOP. (dump_gimple_omp_target): Handle GF_OMP_TARGET_KIND_OACC_KERNELS, GF_OMP_TARGET_KIND_OACC_PARALLEL, GF_OMP_TARGET_KIND_OACC_DATA, GF_OMP_TARGET_KIND_OACC_UPDATE, GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA. Dump more data. * gimple.c: Update comments for OpenACC changes. * gimple.def: Likewise. * gimple.h: Likewise. (enum gf_mask): Add GF_OMP_FOR_KIND_OACC_LOOP, GF_OMP_TARGET_KIND_OACC_PARALLEL, GF_OMP_TARGET_KIND_OACC_KERNELS, GF_OMP_TARGET_KIND_OACC_DATA, GF_OMP_TARGET_KIND_OACC_UPDATE, GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA. (gimple_omp_for_cond, gimple_omp_for_set_cond): Sort in the appropriate place. (is_gimple_omp_oacc, is_gimple_omp_offloaded): New functions. * gimplify.c: Include "gomp-constants.h". Update comments for OpenACC changes. (is_gimple_stmt): Handle OACC_PARALLEL, OACC_KERNELS, OACC_DATA, OACC_HOST_DATA, OACC_DECLARE, OACC_UPDATE, OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_CACHE, OACC_LOOP. (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses): Handle OMP_CLAUSE__CACHE_, OMP_CLAUSE_ASYNC, OMP_CLAUSE_WAIT, OMP_CLAUSE_NUM_GANGS, OMP_CLAUSE_NUM_WORKERS, OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_GANG, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR, OMP_CLAUSE_DEVICE_RESIDENT, OMP_CLAUSE_USE_DEVICE, OMP_CLAUSE_INDEPENDENT, OMP_CLAUSE_AUTO, OMP_CLAUSE_SEQ. (gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses): Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (gimplify_oacc_cache): New function. (gimplify_omp_for): Handle OACC_LOOP. (gimplify_omp_workshare): Handle OACC_KERNELS, OACC_PARALLEL, OACC_DATA. (gimplify_omp_target_update): Handle OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_UPDATE. (gimplify_expr): Handle OACC_LOOP, OACC_CACHE, OACC_HOST_DATA, OACC_DECLARE, OACC_KERNELS, OACC_PARALLEL, OACC_DATA, OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_UPDATE. (gimplify_body): Consider flag_openacc next to flag_openmp. * lto-streamer-out.c: Include "gomp-constants.h". * omp-builtins.def (BUILT_IN_ACC_GET_DEVICE_TYPE) (BUILT_IN_GOACC_DATA_START, BUILT_IN_GOACC_DATA_END) (BUILT_IN_GOACC_ENTER_EXIT_DATA, BUILT_IN_GOACC_PARALLEL) (BUILT_IN_GOACC_UPDATE, BUILT_IN_GOACC_WAIT) (BUILT_IN_GOACC_GET_THREAD_NUM, BUILT_IN_GOACC_GET_NUM_THREADS) (BUILT_IN_ACC_ON_DEVICE): New builtins. * omp-low.c: Include "gomp-constants.h". Update comments for OpenACC changes. (struct omp_context): Add reduction_map, gwv_below, gwv_this members. (extract_omp_for_data, use_pointer_for_field, install_var_field) (new_omp_context, delete_omp_context, scan_sharing_clauses) (create_omp_child_function, scan_omp_for, scan_omp_target) (check_omp_nesting_restrictions, lower_reduction_clauses) (build_omp_regions_1, diagnose_sb_0, make_gimple_omp_edges): Update for OpenACC changes. (scan_sharing_clauses): Handle OMP_CLAUSE_NUM_GANGS: OMP_CLAUSE_NUM_WORKERS: OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_ASYNC, OMP_CLAUSE_WAIT, OMP_CLAUSE_GANG, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR, OMP_CLAUSE_DEVICE_RESIDENT, OMP_CLAUSE_USE_DEVICE, OMP_CLAUSE__CACHE_, OMP_CLAUSE_INDEPENDENT, OMP_CLAUSE_AUTO, OMP_CLAUSE_SEQ. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. (expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Handle GF_OMP_FOR_KIND_OACC_LOOP. (expand_omp_target, lower_omp_target): Handle GF_OMP_TARGET_KIND_OACC_PARALLEL, GF_OMP_TARGET_KIND_OACC_KERNELS, GF_OMP_TARGET_KIND_OACC_UPDATE, GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA, GF_OMP_TARGET_KIND_OACC_DATA. (pass_expand_omp::execute, execute_lower_omp) (pass_diagnose_omp_blocks::gate): Consider flag_openacc next to flag_openmp. (offload_symbol_decl): New variable. (oacc_get_reduction_array_id, oacc_max_threads) (get_offload_symbol_decl, get_base_type, lookup_oacc_reduction) (maybe_lookup_oacc_reduction, enclosing_target_ctx) (oacc_loop_or_target_p, oacc_lower_reduction_var_helper) (oacc_gimple_assign, oacc_initialize_reduction_data) (oacc_finalize_reduction_data, oacc_process_reduction_data): New functions. (is_targetreg_ctx): Remove function. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE__CACHE_, OMP_CLAUSE_DEVICE_RESIDENT, OMP_CLAUSE_USE_DEVICE, OMP_CLAUSE_GANG, OMP_CLAUSE_ASYNC, OMP_CLAUSE_WAIT, OMP_CLAUSE_AUTO, OMP_CLAUSE_SEQ, OMP_CLAUSE_INDEPENDENT, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR, OMP_CLAUSE_NUM_GANGS, OMP_CLAUSE_NUM_WORKERS, OMP_CLAUSE_VECTOR_LENGTH. * tree.c (omp_clause_code_name, walk_tree_1): Update accordingly. * tree.h (OMP_CLAUSE_GANG_EXPR, OMP_CLAUSE_GANG_STATIC_EXPR) (OMP_CLAUSE_ASYNC_EXPR, OMP_CLAUSE_WAIT_EXPR) (OMP_CLAUSE_VECTOR_EXPR, OMP_CLAUSE_WORKER_EXPR) (OMP_CLAUSE_NUM_GANGS_EXPR, OMP_CLAUSE_NUM_WORKERS_EXPR) (OMP_CLAUSE_VECTOR_LENGTH_EXPR): New macros. * tree-core.h: Update comments for OpenACC changes. (enum omp_clause_map_kind): Remove. (struct tree_omp_clause): Change type of map_kind member from enum omp_clause_map_kind to unsigned char. * tree-inline.c: Update comments for OpenACC changes. * tree-nested.c: Likewise. Include "gomp-constants.h". (convert_nonlocal_reference_stmt, convert_local_reference_stmt) (convert_tramp_reference_stmt, convert_gimple_call): Update for OpenACC changes. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. * tree-pretty-print.c: Include "gomp-constants.h". (dump_omp_clause): Handle OMP_CLAUSE_DEVICE_RESIDENT, OMP_CLAUSE_USE_DEVICE, OMP_CLAUSE__CACHE_, OMP_CLAUSE_GANG, OMP_CLAUSE_ASYNC, OMP_CLAUSE_AUTO, OMP_CLAUSE_SEQ, OMP_CLAUSE_WAIT, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR, OMP_CLAUSE_NUM_GANGS, OMP_CLAUSE_NUM_WORKERS, OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_INDEPENDENT. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. (dump_generic_node): Handle OACC_PARALLEL, OACC_KERNELS, OACC_DATA, OACC_HOST_DATA, OACC_DECLARE, OACC_UPDATE, OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_CACHE, OACC_LOOP. * tree-streamer-in.c: Include "gomp-constants.h". (unpack_ts_omp_clause_value_fields) Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. * tree-streamer-out.c: Include "gomp-constants.h". (pack_ts_omp_clause_value_fields): Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. * tree.def (OACC_PARALLEL, OACC_KERNELS, OACC_DATA) (OACC_HOST_DATA, OACC_LOOP, OACC_CACHE, OACC_DECLARE) (OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_UPDATE): New tree codes. * tree.c (omp_clause_num_ops): Update accordingly. * tree.h (OMP_BODY, OMP_CLAUSES, OMP_LOOP_CHECK, OMP_CLAUSE_SIZE): Likewise. (OACC_PARALLEL_BODY, OACC_PARALLEL_CLAUSES, OACC_KERNELS_BODY) (OACC_KERNELS_CLAUSES, OACC_DATA_BODY, OACC_DATA_CLAUSES) (OACC_HOST_DATA_BODY, OACC_HOST_DATA_CLAUSES, OACC_CACHE_CLAUSES) (OACC_DECLARE_CLAUSES, OACC_ENTER_DATA_CLAUSES) (OACC_EXIT_DATA_CLAUSES, OACC_UPDATE_CLAUSES) (OACC_KERNELS_COMBINED, OACC_PARALLEL_COMBINED): New macros. * tree.h (OMP_CLAUSE_MAP_KIND): Cast it to enum gomp_map_kind. (OMP_CLAUSE_SET_MAP_KIND): New macro. * varpool.c (varpool_node::get_create): Consider flag_openacc next to flag_openmp. * config/i386/intelmic-offload.h: New file. * config/nvptx/offload.h: Likewise. gcc/ada/ * gcc-interface/utils.c (DEF_FUNCTION_TYPE_VAR_8) (DEF_FUNCTION_TYPE_VAR_12): New macros. gcc/c-family/ * c.opt (fopenacc): New option. * c-cppbuiltin.c (c_cpp_builtins): Conditionally define _OPENACC. * c-common.c (DEF_FUNCTION_TYPE_VAR_8, DEF_FUNCTION_TYPE_VAR_12): New macros. * c-common.h (c_finish_oacc_wait): New prototype. * c-omp.c: Include "omp-low.h" and "gomp-constants.h". (c_finish_oacc_wait): New function. * c-pragma.c (oacc_pragmas): New variable. (c_pp_lookup_pragma, init_pragma): Handle it. * c-pragma.h (enum pragma_kind): Add PRAGMA_OACC_CACHE, PRAGMA_OACC_DATA, PRAGMA_OACC_ENTER_DATA, PRAGMA_OACC_EXIT_DATA, PRAGMA_OACC_KERNELS, PRAGMA_OACC_LOOP, PRAGMA_OACC_PARALLEL, PRAGMA_OACC_UPDATE, PRAGMA_OACC_WAIT. (enum pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_ASYNC, PRAGMA_OACC_CLAUSE_AUTO, PRAGMA_OACC_CLAUSE_COLLAPSE, PRAGMA_OACC_CLAUSE_COPY, PRAGMA_OACC_CLAUSE_COPYIN, PRAGMA_OACC_CLAUSE_COPYOUT, PRAGMA_OACC_CLAUSE_CREATE, PRAGMA_OACC_CLAUSE_DELETE, PRAGMA_OACC_CLAUSE_DEVICE, PRAGMA_OACC_CLAUSE_DEVICEPTR, PRAGMA_OACC_CLAUSE_FIRSTPRIVATE, PRAGMA_OACC_CLAUSE_GANG, PRAGMA_OACC_CLAUSE_HOST, PRAGMA_OACC_CLAUSE_IF, PRAGMA_OACC_CLAUSE_NUM_GANGS, PRAGMA_OACC_CLAUSE_NUM_WORKERS, PRAGMA_OACC_CLAUSE_PRESENT, PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY, PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN, PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT, PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE, PRAGMA_OACC_CLAUSE_PRIVATE, PRAGMA_OACC_CLAUSE_REDUCTION, PRAGMA_OACC_CLAUSE_SELF, PRAGMA_OACC_CLAUSE_SEQ, PRAGMA_OACC_CLAUSE_VECTOR, PRAGMA_OACC_CLAUSE_VECTOR_LENGTH, PRAGMA_OACC_CLAUSE_WAIT, PRAGMA_OACC_CLAUSE_WORKER. gcc/c/ * c-parser.c: Include "gomp-constants.h". (c_parser_omp_clause_map): Use enum gomp_map_kind instead of enum omp_clause_map_kind. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (c_parser_pragma): Handle PRAGMA_OACC_ENTER_DATA, PRAGMA_OACC_EXIT_DATA, PRAGMA_OACC_UPDATE. (c_parser_omp_construct): Handle PRAGMA_OACC_CACHE, PRAGMA_OACC_DATA, PRAGMA_OACC_KERNELS, PRAGMA_OACC_LOOP, PRAGMA_OACC_PARALLEL, PRAGMA_OACC_WAIT. (c_parser_omp_clause_name): Handle "auto", "async", "copy", "copyout", "create", "delete", "deviceptr", "gang", "host", "num_gangs", "num_workers", "present", "present_or_copy", "pcopy", "present_or_copyin", "pcopyin", "present_or_copyout", "pcopyout", "present_or_create", "pcreate", "seq", "self", "vector", "vector_length", "wait", "worker". (OACC_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK) (OACC_ENTER_DATA_CLAUSE_MASK, OACC_EXIT_DATA_CLAUSE_MASK) (OACC_LOOP_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK) (OACC_UPDATE_CLAUSE_MASK, OACC_WAIT_CLAUSE_MASK): New macros. (c_parser_omp_variable_list): Handle OMP_CLAUSE__CACHE_. (c_parser_oacc_wait_list, c_parser_oacc_data_clause) (c_parser_oacc_data_clause_deviceptr) (c_parser_omp_clause_num_gangs, c_parser_omp_clause_num_workers) (c_parser_oacc_clause_async, c_parser_oacc_clause_wait) (c_parser_omp_clause_vector_length, c_parser_oacc_all_clauses) (c_parser_oacc_cache, c_parser_oacc_data, c_parser_oacc_kernels) (c_parser_oacc_enter_exit_data, c_parser_oacc_loop) (c_parser_oacc_parallel, c_parser_oacc_update) (c_parser_oacc_wait): New functions. * c-tree.h (c_finish_oacc_parallel, c_finish_oacc_kernels) (c_finish_oacc_data): New prototypes. * c-typeck.c: Include "gomp-constants.h". (handle_omp_array_sections): Handle GOMP_MAP_FORCE_DEVICEPTR. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (c_finish_oacc_parallel, c_finish_oacc_kernels) (c_finish_oacc_data): New functions. (c_finish_omp_clauses): Handle OMP_CLAUSE__CACHE_, OMP_CLAUSE_NUM_GANGS, OMP_CLAUSE_NUM_WORKERS, OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_ASYNC, OMP_CLAUSE_WAIT, OMP_CLAUSE_AUTO, OMP_CLAUSE_SEQ, OMP_CLAUSE_GANG, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR, and OMP_CLAUSE_MAP's GOMP_MAP_FORCE_DEVICEPTR. gcc/cp/ * parser.c: Include "gomp-constants.h". (cp_parser_omp_clause_map): Use enum gomp_map_kind instead of enum omp_clause_map_kind. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (cp_parser_omp_construct, cp_parser_pragma): Handle PRAGMA_OACC_CACHE, PRAGMA_OACC_DATA, PRAGMA_OACC_ENTER_DATA, PRAGMA_OACC_EXIT_DATA, PRAGMA_OACC_KERNELS, PRAGMA_OACC_PARALLEL, PRAGMA_OACC_LOOP, PRAGMA_OACC_UPDATE, PRAGMA_OACC_WAIT. (cp_parser_omp_clause_name): Handle "async", "copy", "copyout", "create", "delete", "deviceptr", "host", "num_gangs", "num_workers", "present", "present_or_copy", "pcopy", "present_or_copyin", "pcopyin", "present_or_copyout", "pcopyout", "present_or_create", "pcreate", "vector_length", "wait". (OACC_DATA_CLAUSE_MASK, OACC_ENTER_DATA_CLAUSE_MASK) (OACC_EXIT_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK) (OACC_LOOP_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK) (OACC_UPDATE_CLAUSE_MASK, OACC_WAIT_CLAUSE_MASK): New macros. (cp_parser_omp_var_list_no_open): Handle OMP_CLAUSE__CACHE_. (cp_parser_oacc_data_clause, cp_parser_oacc_data_clause_deviceptr) (cp_parser_oacc_clause_vector_length, cp_parser_oacc_wait_list) (cp_parser_oacc_clause_wait, cp_parser_omp_clause_num_gangs) (cp_parser_omp_clause_num_workers, cp_parser_oacc_clause_async) (cp_parser_oacc_all_clauses, cp_parser_oacc_cache) (cp_parser_oacc_data, cp_parser_oacc_enter_exit_data) (cp_parser_oacc_kernels, cp_parser_oacc_loop) (cp_parser_oacc_parallel, cp_parser_oacc_update) (cp_parser_oacc_wait): New functions. * cp-tree.h (finish_oacc_data, finish_oacc_kernels) (finish_oacc_parallel): New prototypes. * semantics.c: Include "gomp-constants.h". (handle_omp_array_sections): Handle GOMP_MAP_FORCE_DEVICEPTR. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (finish_omp_clauses): Handle OMP_CLAUSE_ASYNC, OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_WAIT, OMP_CLAUSE__CACHE_. Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. (finish_oacc_data, finish_oacc_kernels, finish_oacc_parallel): New functions. gcc/fortran/ * lang.opt (fopenacc): New option. * cpp.c (cpp_define_builtins): Conditionally define _OPENACC. * dump-parse-tree.c (show_omp_node): Split part of it into... (show_omp_clauses): ... this new function. (show_omp_node, show_code_node): Handle EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS_LOOP, EXEC_OACC_KERNELS, EXEC_OACC_DATA, EXEC_OACC_HOST_DATA, EXEC_OACC_LOOP, EXEC_OACC_UPDATE, EXEC_OACC_WAIT, EXEC_OACC_CACHE, EXEC_OACC_ENTER_DATA, EXEC_OACC_EXIT_DATA. (show_namespace): Update for OpenACC. * f95-lang.c (DEF_FUNCTION_TYPE_VAR_2, DEF_FUNCTION_TYPE_VAR_8) (DEF_FUNCTION_TYPE_VAR_12, DEF_GOACC_BUILTIN) (DEF_GOACC_BUILTIN_COMPILER): New macros. * types.def (BT_FN_VOID_INT_INT_VAR) (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR_INT_INT_VAR) (BT_FN_VOID_INT_OMPFN_PTR_SIZE_PTR_PTR_PTR_INT_INT_INT_INT_INT_VAR): New function types. * gfortran.h (gfc_statement): Add ST_OACC_PARALLEL_LOOP, ST_OACC_END_PARALLEL_LOOP, ST_OACC_PARALLEL, ST_OACC_END_PARALLEL, ST_OACC_KERNELS, ST_OACC_END_KERNELS, ST_OACC_DATA, ST_OACC_END_DATA, ST_OACC_HOST_DATA, ST_OACC_END_HOST_DATA, ST_OACC_LOOP, ST_OACC_END_LOOP, ST_OACC_DECLARE, ST_OACC_UPDATE, ST_OACC_WAIT, ST_OACC_CACHE, ST_OACC_KERNELS_LOOP, ST_OACC_END_KERNELS_LOOP, ST_OACC_ENTER_DATA, ST_OACC_EXIT_DATA, ST_OACC_ROUTINE. (struct gfc_expr_list): New data type. (gfc_get_expr_list): New macro. (gfc_omp_map_op): Add OMP_MAP_FORCE_ALLOC, OMP_MAP_FORCE_DEALLOC, OMP_MAP_FORCE_TO, OMP_MAP_FORCE_FROM, OMP_MAP_FORCE_TOFROM, OMP_MAP_FORCE_PRESENT, OMP_MAP_FORCE_DEVICEPTR. (OMP_LIST_FIRST, OMP_LIST_DEVICE_RESIDENT, OMP_LIST_USE_DEVICE) (OMP_LIST_CACHE): New enumerators. (struct gfc_omp_clauses): Add async_expr, gang_expr, worker_expr, vector_expr, num_gangs_expr, num_workers_expr, vector_length_expr, wait_list, tile_list, async, gang, worker, vector, seq, independent, wait, par_auto, gang_static, and loc members. (struct gfc_namespace): Add oacc_declare_clauses member. (gfc_exec_op): Add EXEC_OACC_KERNELS_LOOP, EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS, EXEC_OACC_DATA, EXEC_OACC_HOST_DATA, EXEC_OACC_LOOP, EXEC_OACC_UPDATE, EXEC_OACC_WAIT, EXEC_OACC_CACHE, EXEC_OACC_ENTER_DATA, EXEC_OACC_EXIT_DATA. (gfc_free_expr_list, gfc_resolve_oacc_directive) (gfc_resolve_oacc_declare, gfc_resolve_oacc_parallel_loop_blocks) (gfc_resolve_oacc_blocks): New prototypes. * match.c (match_exit_cycle): Handle EXEC_OACC_LOOP and EXEC_OACC_PARALLEL_LOOP. * match.h (gfc_match_oacc_cache, gfc_match_oacc_wait) (gfc_match_oacc_update, gfc_match_oacc_declare) (gfc_match_oacc_loop, gfc_match_oacc_host_data) (gfc_match_oacc_data, gfc_match_oacc_kernels) (gfc_match_oacc_kernels_loop, gfc_match_oacc_parallel) (gfc_match_oacc_parallel_loop, gfc_match_oacc_enter_data) (gfc_match_oacc_exit_data, gfc_match_oacc_routine): New prototypes. * openmp.c: Include "diagnostic.h" and "gomp-constants.h". (gfc_free_omp_clauses): Update for members added to struct gfc_omp_clauses. (gfc_match_omp_clauses): Change mask paramter to uint64_t. Add openacc parameter. (resolve_omp_clauses): Add openacc parameter. Update for OpenACC. (struct fortran_omp_context): Add is_openmp member. (gfc_resolve_omp_parallel_blocks): Initialize it. (gfc_resolve_do_iterator): Update for OpenACC. (gfc_resolve_omp_directive): Call resolve_omp_directive_inside_oacc_region. (OMP_CLAUSE_PRIVATE, OMP_CLAUSE_FIRSTPRIVATE) (OMP_CLAUSE_LASTPRIVATE, OMP_CLAUSE_COPYPRIVATE) (OMP_CLAUSE_SHARED, OMP_CLAUSE_COPYIN, OMP_CLAUSE_REDUCTION) (OMP_CLAUSE_IF, OMP_CLAUSE_NUM_THREADS, OMP_CLAUSE_SCHEDULE) (OMP_CLAUSE_DEFAULT, OMP_CLAUSE_ORDERED, OMP_CLAUSE_COLLAPSE) (OMP_CLAUSE_UNTIED, OMP_CLAUSE_FINAL, OMP_CLAUSE_MERGEABLE) (OMP_CLAUSE_ALIGNED, OMP_CLAUSE_DEPEND, OMP_CLAUSE_INBRANCH) (OMP_CLAUSE_LINEAR, OMP_CLAUSE_NOTINBRANCH, OMP_CLAUSE_PROC_BIND) (OMP_CLAUSE_SAFELEN, OMP_CLAUSE_SIMDLEN, OMP_CLAUSE_UNIFORM) (OMP_CLAUSE_DEVICE, OMP_CLAUSE_MAP, OMP_CLAUSE_TO) (OMP_CLAUSE_FROM, OMP_CLAUSE_NUM_TEAMS, OMP_CLAUSE_THREAD_LIMIT) (OMP_CLAUSE_DIST_SCHEDULE): Use uint64_t. (OMP_CLAUSE_ASYNC, OMP_CLAUSE_NUM_GANGS, OMP_CLAUSE_NUM_WORKERS) (OMP_CLAUSE_VECTOR_LENGTH, OMP_CLAUSE_COPY, OMP_CLAUSE_COPYOUT) (OMP_CLAUSE_CREATE, OMP_CLAUSE_PRESENT) (OMP_CLAUSE_PRESENT_OR_COPY, OMP_CLAUSE_PRESENT_OR_COPYIN) (OMP_CLAUSE_PRESENT_OR_COPYOUT, OMP_CLAUSE_PRESENT_OR_CREATE) (OMP_CLAUSE_DEVICEPTR, OMP_CLAUSE_GANG, OMP_CLAUSE_WORKER) (OMP_CLAUSE_VECTOR, OMP_CLAUSE_SEQ, OMP_CLAUSE_INDEPENDENT) (OMP_CLAUSE_USE_DEVICE, OMP_CLAUSE_DEVICE_RESIDENT) (OMP_CLAUSE_HOST_SELF, OMP_CLAUSE_OACC_DEVICE, OMP_CLAUSE_WAIT) (OMP_CLAUSE_DELETE, OMP_CLAUSE_AUTO, OMP_CLAUSE_TILE): New macros. (gfc_match_omp_clauses): Handle those. (OACC_PARALLEL_CLAUSES, OACC_KERNELS_CLAUSES, OACC_DATA_CLAUSES) (OACC_LOOP_CLAUSES, OACC_PARALLEL_LOOP_CLAUSES) (OACC_KERNELS_LOOP_CLAUSES, OACC_HOST_DATA_CLAUSES) (OACC_DECLARE_CLAUSES, OACC_UPDATE_CLAUSES) (OACC_ENTER_DATA_CLAUSES, OACC_EXIT_DATA_CLAUSES) (OACC_WAIT_CLAUSES): New macros. (gfc_free_expr_list, match_oacc_expr_list, match_oacc_clause_gang) (gfc_match_omp_map_clause, gfc_match_oacc_parallel_loop) (gfc_match_oacc_parallel, gfc_match_oacc_kernels_loop) (gfc_match_oacc_kernels, gfc_match_oacc_data) (gfc_match_oacc_host_data, gfc_match_oacc_loop) (gfc_match_oacc_declare, gfc_match_oacc_update) (gfc_match_oacc_enter_data, gfc_match_oacc_exit_data) (gfc_match_oacc_wait, gfc_match_oacc_cache) (gfc_match_oacc_routine, oacc_is_loop) (resolve_oacc_scalar_int_expr, resolve_oacc_positive_int_expr) (check_symbol_not_pointer, check_array_not_assumed) (resolve_oacc_data_clauses, resolve_oacc_deviceptr_clause) (oacc_compatible_clauses, oacc_is_parallel, oacc_is_kernels) (omp_code_to_statement, oacc_code_to_statement) (resolve_oacc_directive_inside_omp_region) (resolve_omp_directive_inside_oacc_region) (resolve_oacc_nested_loops, resolve_oacc_params_in_parallel) (resolve_oacc_loop_blocks, gfc_resolve_oacc_blocks) (resolve_oacc_loop, resolve_oacc_cache, gfc_resolve_oacc_declare) (gfc_resolve_oacc_directive): New functions. * parse.c (next_free): Update for OpenACC. Move some code into... (verify_token_free): ... this new function. (next_fixed): Update for OpenACC. Move some code into... (verify_token_fixed): ... this new function. (case_executable): Add ST_OACC_UPDATE, ST_OACC_WAIT, ST_OACC_CACHE, ST_OACC_ENTER_DATA, and ST_OACC_EXIT_DATA. (case_exec_markers): Add ST_OACC_PARALLEL_LOOP, ST_OACC_PARALLEL, ST_OACC_KERNELS, ST_OACC_DATA, ST_OACC_HOST_DATA, ST_OACC_LOOP, ST_OACC_KERNELS_LOOP. (case_decl): Add ST_OACC_ROUTINE. (push_state, parse_critical_block, parse_progunit): Update for OpenACC. (gfc_ascii_statement): Handle ST_OACC_PARALLEL_LOOP, ST_OACC_END_PARALLEL_LOOP, ST_OACC_PARALLEL, ST_OACC_END_PARALLEL, ST_OACC_KERNELS, ST_OACC_END_KERNELS, ST_OACC_KERNELS_LOOP, ST_OACC_END_KERNELS_LOOP, ST_OACC_DATA, ST_OACC_END_DATA, ST_OACC_HOST_DATA, ST_OACC_END_HOST_DATA, ST_OACC_LOOP, ST_OACC_END_LOOP, ST_OACC_DECLARE, ST_OACC_UPDATE, ST_OACC_WAIT, ST_OACC_CACHE, ST_OACC_ENTER_DATA, ST_OACC_EXIT_DATA, ST_OACC_ROUTINE. (verify_st_order, parse_spec): Handle ST_OACC_DECLARE. (parse_executable): Handle ST_OACC_PARALLEL_LOOP, ST_OACC_KERNELS_LOOP, ST_OACC_LOOP, ST_OACC_PARALLEL, ST_OACC_KERNELS, ST_OACC_DATA, ST_OACC_HOST_DATA. (decode_oacc_directive, parse_oacc_structured_block) (parse_oacc_loop, is_oacc): New functions. * parse.h (struct gfc_state_data): Add oacc_declare_clauses member. (is_oacc): New prototype. * resolve.c (gfc_resolve_blocks, gfc_resolve_code): Handle EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS_LOOP, EXEC_OACC_KERNELS, EXEC_OACC_DATA, EXEC_OACC_HOST_DATA, EXEC_OACC_LOOP, EXEC_OACC_UPDATE, EXEC_OACC_WAIT, EXEC_OACC_CACHE, EXEC_OACC_ENTER_DATA, EXEC_OACC_EXIT_DATA. (resolve_codes): Call gfc_resolve_oacc_declare. * scanner.c (openacc_flag, openacc_locus): New variables. (skip_free_comments): Update for OpenACC. Move some code into... (skip_omp_attribute): ... this new function. (skip_oacc_attribute): New function. (skip_fixed_comments, gfc_next_char_literal): Update for OpenACC. * st.c (gfc_free_statement): Handle EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS_LOOP, EXEC_OACC_KERNELS, EXEC_OACC_DATA, EXEC_OACC_HOST_DATA, EXEC_OACC_LOOP, EXEC_OACC_UPDATE, EXEC_OACC_WAIT, EXEC_OACC_CACHE, EXEC_OACC_ENTER_DATA, EXEC_OACC_EXIT_DATA. * trans-decl.c (gfc_generate_function_code): Update for OpenACC. * trans-openmp.c: Include "gomp-constants.h". (gfc_omp_finish_clause, gfc_trans_omp_clauses): Use GOMP_MAP_* instead of OMP_CLAUSE_MAP_*. Use OMP_CLAUSE_SET_MAP_KIND. (gfc_trans_omp_clauses): Handle OMP_LIST_USE_DEVICE, OMP_LIST_DEVICE_RESIDENT, OMP_LIST_CACHE, and OMP_MAP_FORCE_ALLOC, OMP_MAP_FORCE_DEALLOC, OMP_MAP_FORCE_TO, OMP_MAP_FORCE_FROM, OMP_MAP_FORCE_TOFROM, OMP_MAP_FORCE_PRESENT, OMP_MAP_FORCE_DEVICEPTR, and gfc_omp_clauses' async, seq, independent, wait_list, num_gangs_expr, num_workers_expr, vector_length_expr, vector, vector_expr, worker, worker_expr, gang, gang_expr members. (gfc_trans_omp_do): Handle EXEC_OACC_LOOP. (gfc_convert_expr_to_tree, gfc_trans_oacc_construct) (gfc_trans_oacc_executable_directive) (gfc_trans_oacc_wait_directive, gfc_trans_oacc_combined_directive) (gfc_trans_oacc_declare, gfc_trans_oacc_directive): New functions. * trans-stmt.c (gfc_trans_block_construct): Update for OpenACC. * trans-stmt.h (gfc_trans_oacc_directive, gfc_trans_oacc_declare): New prototypes. * trans.c (tranc_code): Handle EXEC_OACC_CACHE, EXEC_OACC_WAIT, EXEC_OACC_UPDATE, EXEC_OACC_LOOP, EXEC_OACC_HOST_DATA, EXEC_OACC_DATA, EXEC_OACC_KERNELS, EXEC_OACC_KERNELS_LOOP, EXEC_OACC_PARALLEL, EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_ENTER_DATA, EXEC_OACC_EXIT_DATA. * gfortran.texi: Update for OpenACC. * intrinsic.texi: Likewise. * invoke.texi: Likewise. gcc/lto/ * lto-lang.c (DEF_FUNCTION_TYPE_VAR_8, DEF_FUNCTION_TYPE_VAR_12): New macros. * lto.c: Include "gomp-constants.h". gcc/testsuite/ * lib/target-supports.exp (check_effective_target_fopenacc): New procedure. * g++.dg/goacc-gomp/goacc-gomp.exp: New file. * g++.dg/goacc/goacc.exp: Likewise. * gcc.dg/goacc-gomp/goacc-gomp.exp: Likewise. * gcc.dg/goacc/goacc.exp: Likewise. * gfortran.dg/goacc/goacc.exp: Likewise. * c-c++-common/cpp/openacc-define-1.c: New file. * c-c++-common/cpp/openacc-define-2.c: Likewise. * c-c++-common/cpp/openacc-define-3.c: Likewise. * c-c++-common/goacc-gomp/nesting-1.c: Likewise. * c-c++-common/goacc-gomp/nesting-fail-1.c: Likewise. * c-c++-common/goacc/acc_on_device-2-off.c: Likewise. * c-c++-common/goacc/acc_on_device-2.c: Likewise. * c-c++-common/goacc/asyncwait-1.c: Likewise. * c-c++-common/goacc/cache-1.c: Likewise. * c-c++-common/goacc/clauses-fail.c: Likewise. * c-c++-common/goacc/collapse-1.c: Likewise. * c-c++-common/goacc/data-1.c: Likewise. * c-c++-common/goacc/data-2.c: Likewise. * c-c++-common/goacc/data-clause-duplicate-1.c: Likewise. * c-c++-common/goacc/deviceptr-1.c: Likewise. * c-c++-common/goacc/deviceptr-2.c: Likewise. * c-c++-common/goacc/deviceptr-3.c: Likewise. * c-c++-common/goacc/if-clause-1.c: Likewise. * c-c++-common/goacc/if-clause-2.c: Likewise. * c-c++-common/goacc/kernels-1.c: Likewise. * c-c++-common/goacc/loop-1.c: Likewise. * c-c++-common/goacc/loop-private-1.c: Likewise. * c-c++-common/goacc/nesting-1.c: Likewise. * c-c++-common/goacc/nesting-data-1.c: Likewise. * c-c++-common/goacc/nesting-fail-1.c: Likewise. * c-c++-common/goacc/parallel-1.c: Likewise. * c-c++-common/goacc/pcopy.c: Likewise. * c-c++-common/goacc/pcopyin.c: Likewise. * c-c++-common/goacc/pcopyout.c: Likewise. * c-c++-common/goacc/pcreate.c: Likewise. * c-c++-common/goacc/pragma_context.c: Likewise. * c-c++-common/goacc/present-1.c: Likewise. * c-c++-common/goacc/reduction-1.c: Likewise. * c-c++-common/goacc/reduction-2.c: Likewise. * c-c++-common/goacc/reduction-3.c: Likewise. * c-c++-common/goacc/reduction-4.c: Likewise. * c-c++-common/goacc/sb-1.c: Likewise. * c-c++-common/goacc/sb-2.c: Likewise. * c-c++-common/goacc/sb-3.c: Likewise. * c-c++-common/goacc/update-1.c: Likewise. * gcc.dg/goacc/acc_on_device-1.c: Likewise. * gfortran.dg/goacc/acc_on_device-1.f95: Likewise. * gfortran.dg/goacc/acc_on_device-2-off.f95: Likewise. * gfortran.dg/goacc/acc_on_device-2.f95: Likewise. * gfortran.dg/goacc/assumed.f95: Likewise. * gfortran.dg/goacc/asyncwait-1.f95: Likewise. * gfortran.dg/goacc/asyncwait-2.f95: Likewise. * gfortran.dg/goacc/asyncwait-3.f95: Likewise. * gfortran.dg/goacc/asyncwait-4.f95: Likewise. * gfortran.dg/goacc/branch.f95: Likewise. * gfortran.dg/goacc/cache-1.f95: Likewise. * gfortran.dg/goacc/coarray.f95: Likewise. * gfortran.dg/goacc/continuation-free-form.f95: Likewise. * gfortran.dg/goacc/cray.f95: Likewise. * gfortran.dg/goacc/critical.f95: Likewise. * gfortran.dg/goacc/data-clauses.f95: Likewise. * gfortran.dg/goacc/data-tree.f95: Likewise. * gfortran.dg/goacc/declare-1.f95: Likewise. * gfortran.dg/goacc/enter-exit-data.f95: Likewise. * gfortran.dg/goacc/fixed-1.f: Likewise. * gfortran.dg/goacc/fixed-2.f: Likewise. * gfortran.dg/goacc/fixed-3.f: Likewise. * gfortran.dg/goacc/fixed-4.f: Likewise. * gfortran.dg/goacc/host_data-tree.f95: Likewise. * gfortran.dg/goacc/if.f95: Likewise. * gfortran.dg/goacc/kernels-tree.f95: Likewise. * gfortran.dg/goacc/list.f95: Likewise. * gfortran.dg/goacc/literal.f95: Likewise. * gfortran.dg/goacc/loop-1.f95: Likewise. * gfortran.dg/goacc/loop-2.f95: Likewise. * gfortran.dg/goacc/loop-3.f95: Likewise. * gfortran.dg/goacc/loop-tree-1.f90: Likewise. * gfortran.dg/goacc/omp.f95: Likewise. * gfortran.dg/goacc/parallel-kernels-clauses.f95: Likewise. * gfortran.dg/goacc/parallel-kernels-regions.f95: Likewise. * gfortran.dg/goacc/parallel-tree.f95: Likewise. * gfortran.dg/goacc/parameter.f95: Likewise. * gfortran.dg/goacc/private-1.f95: Likewise. * gfortran.dg/goacc/private-2.f95: Likewise. * gfortran.dg/goacc/private-3.f95: Likewise. * gfortran.dg/goacc/pure-elemental-procedures.f95: Likewise. * gfortran.dg/goacc/reduction-2.f95: Likewise. * gfortran.dg/goacc/reduction.f95: Likewise. * gfortran.dg/goacc/routine-1.f90: Likewise. * gfortran.dg/goacc/routine-2.f90: Likewise. * gfortran.dg/goacc/sentinel-free-form.f95: Likewise. * gfortran.dg/goacc/several-directives.f95: Likewise. * gfortran.dg/goacc/sie.f95: Likewise. * gfortran.dg/goacc/subarrays.f95: Likewise. * gfortran.dg/gomp/map-1.f90: Likewise. * gfortran.dg/openacc-define-1.f90: Likewise. * gfortran.dg/openacc-define-2.f90: Likewise. * gfortran.dg/openacc-define-3.f90: Likewise. * g++.dg/gomp/block-1.C: Update for changed compiler output. * g++.dg/gomp/block-2.C: Likewise. * g++.dg/gomp/block-3.C: Likewise. * g++.dg/gomp/block-5.C: Likewise. * g++.dg/gomp/target-1.C: Likewise. * g++.dg/gomp/target-2.C: Likewise. * g++.dg/gomp/taskgroup-1.C: Likewise. * g++.dg/gomp/teams-1.C: Likewise. * gcc.dg/cilk-plus/jump-openmp.c: Likewise. * gcc.dg/cilk-plus/jump.c: Likewise. * gcc.dg/gomp/block-1.c: Likewise. * gcc.dg/gomp/block-10.c: Likewise. * gcc.dg/gomp/block-2.c: Likewise. * gcc.dg/gomp/block-3.c: Likewise. * gcc.dg/gomp/block-4.c: Likewise. * gcc.dg/gomp/block-5.c: Likewise. * gcc.dg/gomp/block-6.c: Likewise. * gcc.dg/gomp/block-7.c: Likewise. * gcc.dg/gomp/block-8.c: Likewise. * gcc.dg/gomp/block-9.c: Likewise. * gcc.dg/gomp/target-1.c: Likewise. * gcc.dg/gomp/target-2.c: Likewise. * gcc.dg/gomp/taskgroup-1.c: Likewise. * gcc.dg/gomp/teams-1.c: Likewise. include/ * gomp-constants.h: New file. libgomp/ * Makefile.am (search_path): Add $(top_srcdir)/../include. (libgomp_la_SOURCES): Add splay-tree.c, libgomp-plugin.c, oacc-parallel.c, oacc-host.c, oacc-init.c, oacc-mem.c, oacc-async.c, oacc-plugin.c, oacc-cuda.c. [USE_FORTRAN] (libgomp_la_SOURCES): Add openacc.f90. Include $(top_srcdir)/plugin/Makefrag.am. (nodist_libsubinclude_HEADERS): Add openacc.h. [USE_FORTRAN] (nodist_finclude_HEADERS): Add openacc_lib.h, openacc.f90, openacc.mod, openacc_kinds.mod. (omp_lib.mod): Generalize into... (%.mod): ... this new rule. (openacc_kinds.mod, openacc.mod): New rules. * plugin/configfrag.ac: New file. * configure.ac: Move plugin/offloading support into it. Include it. Instantiate testsuite/libgomp-test-support.pt.exp. * plugin/Makefrag.am: New file. * testsuite/Makefile.am (OFFLOAD_TARGETS) (OFFLOAD_ADDITIONAL_OPTIONS, OFFLOAD_ADDITIONAL_LIB_PATHS): Don't export. (libgomp-test-support.exp): New rule. (all-local): Depend on it. * Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * config.h.in: Likewise. * configure: Likewise. * configure.tgt: Harden shell syntax. * env.c: Include "oacc-int.h". (parse_acc_device_type): New function. (gomp_debug_var, goacc_device_type, goacc_device_num): New variables. (initialize_env): Initialize those. Call goacc_runtime_initialize. * error.c (gomp_vdebug, gomp_debug, gomp_vfatal): New functions. (gomp_fatal): Call gomp_vfatal. * libgomp.h: Include "libgomp-plugin.h" and <stdarg.h>. (gomp_debug_var, goacc_device_type, goacc_device_num, gomp_vdebug) (gomp_debug, gomp_verror, gomp_vfatal, gomp_init_targets_once) (splay_tree_node, splay_tree, splay_tree_key) (struct target_mem_desc, struct splay_tree_key_s) (struct gomp_memory_mapping, struct acc_dispatch_t) (struct gomp_device_descr, gomp_acc_insert_pointer) (gomp_acc_remove_pointer, target_mem_desc, gomp_copy_from_async) (gomp_unmap_vars, gomp_init_device, gomp_init_tables) (gomp_free_memmap, gomp_fini_device): New declarations. (gomp_vdebug, gomp_debug): New macros. Include "splay-tree.h". * libgomp.map (OACC_2.0): New symbol version. Use for acc_get_num_devices, acc_get_num_devices_h_, acc_set_device_type, acc_set_device_type_h_, acc_get_device_type, acc_get_device_type_h_, acc_set_device_num, acc_set_device_num_h_, acc_get_device_num, acc_get_device_num_h_, acc_async_test, acc_async_test_h_, acc_async_test_all, acc_async_test_all_h_, acc_wait, acc_wait_h_, acc_wait_async, acc_wait_async_h_, acc_wait_all, acc_wait_all_h_, acc_wait_all_async, acc_wait_all_async_h_, acc_init, acc_init_h_, acc_shutdown, acc_shutdown_h_, acc_on_device, acc_on_device_h_, acc_malloc, acc_free, acc_copyin, acc_copyin_32_h_, acc_copyin_64_h_, acc_copyin_array_h_, acc_present_or_copyin, acc_present_or_copyin_32_h_, acc_present_or_copyin_64_h_, acc_present_or_copyin_array_h_, acc_create, acc_create_32_h_, acc_create_64_h_, acc_create_array_h_, acc_present_or_create, acc_present_or_create_32_h_, acc_present_or_create_64_h_, acc_present_or_create_array_h_, acc_copyout, acc_copyout_32_h_, acc_copyout_64_h_, acc_copyout_array_h_, acc_delete, acc_delete_32_h_, acc_delete_64_h_, acc_delete_array_h_, acc_update_device, acc_update_device_32_h_, acc_update_device_64_h_, acc_update_device_array_h_, acc_update_self, acc_update_self_32_h_, acc_update_self_64_h_, acc_update_self_array_h_, acc_map_data, acc_unmap_data, acc_deviceptr, acc_hostptr, acc_is_present, acc_is_present_32_h_, acc_is_present_64_h_, acc_is_present_array_h_, acc_memcpy_to_device, acc_memcpy_from_device, acc_get_current_cuda_device, acc_get_current_cuda_context, acc_get_cuda_stream, acc_set_cuda_stream. (GOACC_2.0): New symbol version. Use for GOACC_data_end, GOACC_data_start, GOACC_enter_exit_data, GOACC_parallel, GOACC_update, GOACC_wait, GOACC_get_thread_num, GOACC_get_num_threads. (GOMP_PLUGIN_1.0): New symbol version. Use for GOMP_PLUGIN_malloc, GOMP_PLUGIN_malloc_cleared, GOMP_PLUGIN_realloc, GOMP_PLUGIN_debug, GOMP_PLUGIN_error, GOMP_PLUGIN_fatal, GOMP_PLUGIN_async_unmap_vars, GOMP_PLUGIN_acc_thread. * libgomp.texi: Update for OpenACC changes, and GOMP_DEBUG environment variable. * libgomp_g.h (GOACC_data_start, GOACC_data_end) (GOACC_enter_exit_data, GOACC_parallel, GOACC_update, GOACC_wait) (GOACC_get_num_threads, GOACC_get_thread_num): New declarations. * splay-tree.h (splay_tree_lookup, splay_tree_insert) (splay_tree_remove): New declarations. (rotate_left, rotate_right, splay_tree_splay, splay_tree_insert) (splay_tree_remove, splay_tree_lookup): Move into... * splay-tree.c: ... this new file. * target.c: Include "oacc-plugin.h", "oacc-int.h", <assert.h>. (splay_tree_node, splay_tree, splay_tree_key) (struct target_mem_desc, struct splay_tree_key_s) (struct gomp_device_descr): Don't declare. (num_devices_openmp): New variable. (gomp_get_num_devices ): Use it. (gomp_init_targets_once): New function. (gomp_get_num_devices ): Use it. (get_kind, gomp_copy_from_async, gomp_free_memmap) (gomp_fini_device, gomp_register_image_for_device): New functions. (gomp_map_vars): Add devaddrs parameter. (gomp_update): Add mm parameter. (gomp_init_device): Move most of it into... (gomp_init_tables): ... this new function. (gomp_register_images_for_device): Remove function. (splay_compare, gomp_map_vars, gomp_unmap_vars, gomp_init_device): Make them hidden instead of static. (gomp_map_vars_existing, gomp_map_vars, gomp_unmap_vars) (gomp_update, gomp_init_device, GOMP_target, GOMP_target_data) (GOMP_target_end_data, GOMP_target_update) (gomp_load_plugin_for_device, gomp_target_init): Update for OpenACC changes. * oacc-async.c: New file. * oacc-cuda.c: Likewise. * oacc-host.c: Likewise. * oacc-init.c: Likewise. * oacc-int.h: Likewise. * oacc-mem.c: Likewise. * oacc-parallel.c: Likewise. * oacc-plugin.c: Likewise. * oacc-plugin.h: Likewise. * oacc-ptx.h: Likewise. * openacc.f90: Likewise. * openacc.h: Likewise. * openacc_lib.h: Likewise. * plugin/plugin-host.c: Likewise. * plugin/plugin-nvptx.c: Likewise. * libgomp-plugin.c: Likewise. * libgomp-plugin.h: Likewise. * libgomp_target.h: Remove file after merging content into the former file. Update all users. * testsuite/lib/libgomp.exp: Load libgomp-test-support.exp. (offload_targets_s, offload_targets_s_openacc): New variables. (check_effective_target_openacc_nvidia_accel_present) (check_effective_target_openacc_nvidia_accel_selected): New procedures. (libgomp_init): Update for OpenACC changes. * testsuite/libgomp-test-support.exp.in: New file. * testsuite/libgomp.oacc-c++/c++.exp: Likewise. * testsuite/libgomp.oacc-c/c.exp: Likewise. * testsuite/libgomp.oacc-fortran/fortran.exp: Likewise. * testsuite/libgomp.oacc-c-c++-common/abort-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/abort-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/abort-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/abort-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/acc_on_device-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/cache-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/clauses-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/clauses-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/collapse-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/collapse-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/collapse-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/collapse-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/context-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/context-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/context-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/context-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-5.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-6.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-7.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/data-already-8.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deviceptr-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/if-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/kernels-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/kernels-empty.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-10.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-11.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-12.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-13.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-14.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-15.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-16.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-17.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-18.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-19.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-20.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-21.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-22.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-23.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-24.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-25.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-26.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-27.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-28.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-29.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-30.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-31.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-32.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-33.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-34.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-35.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-36.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-37.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-38.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-39.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-40.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-41.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-42.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-43.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-44.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-45.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-46.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-47.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-48.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-49.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-5.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-50.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-51.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-52.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-53.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-54.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-55.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-56.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-57.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-58.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-59.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-6.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-60.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-61.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-62.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-63.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-64.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-65.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-66.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-67.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-68.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-69.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-7.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-70.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-71.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-72.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-73.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-74.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-75.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-76.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-77.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-78.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-79.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-80.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-81.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-83.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-84.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-85.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-86.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-87.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-88.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-89.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-9.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-90.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-91.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-92.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/nested-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/nested-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/offset-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/parallel-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/parallel-empty.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/pointer-align-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/present-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/present-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-5.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-initial-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/subr.h: Likewise. * testsuite/libgomp.oacc-c-c++-common/subr.ptx: Likewise. * testsuite/libgomp.oacc-c-c++-common/timer.h: Likewise. * testsuite/libgomp.oacc-c-c++-common/update-1-2.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/update-1.c: Likewise. * testsuite/libgomp.oacc-fortran/abort-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/abort-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/acc_on_device-1-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/acc_on_device-1-2.f: Likewise. * testsuite/libgomp.oacc-fortran/acc_on_device-1-3.f: Likewise. * testsuite/libgomp.oacc-fortran/asyncwait-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/asyncwait-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/asyncwait-3.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-3.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-4.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-5.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-6.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-7.f90: Likewise. * testsuite/libgomp.oacc-fortran/collapse-8.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-3.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-4-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-4.f90: Likewise. * testsuite/libgomp.oacc-fortran/data-already-1.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-2.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-3.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-4.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-5.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-6.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-7.f: Likewise. * testsuite/libgomp.oacc-fortran/data-already-8.f: Likewise. * testsuite/libgomp.oacc-fortran/lib-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-10.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-2.f: Likewise. * testsuite/libgomp.oacc-fortran/lib-3.f: Likewise. * testsuite/libgomp.oacc-fortran/lib-4.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-5.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-6.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-7.f90: Likewise. * testsuite/libgomp.oacc-fortran/lib-8.f90: Likewise. * testsuite/libgomp.oacc-fortran/map-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/openacc_version-1.f: Likewise. * testsuite/libgomp.oacc-fortran/openacc_version-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/pointer-align-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/pset-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-3.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-4.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-5.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-6.f90: Likewise. * testsuite/libgomp.oacc-fortran/routine-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/routine-2.f90: Likewise. * testsuite/libgomp.oacc-fortran/routine-3.f90: Likewise. * testsuite/libgomp.oacc-fortran/routine-4.f90: Likewise. * testsuite/libgomp.oacc-fortran/subarrays-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/subarrays-2.f90: Likewise. liboffloadmic/ * plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_get_name) (GOMP_OFFLOAD_get_caps, GOMP_OFFLOAD_fini_device): New functions. Co-Authored-By: Bernd Schmidt <bernds@codesourcery.com> Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com> Co-Authored-By: Dmitry Bocharnikov <dmitry.b@samsung.com> Co-Authored-By: Evgeny Gavrin <e.gavrin@samsung.com> Co-Authored-By: Ilmir Usmanov <i.usmanov@samsung.com> Co-Authored-By: Jakub Jelinek <jakub@redhat.com> Co-Authored-By: James Norris <jnorris@codesourcery.com> Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Nathan Sidwell <nathan@codesourcery.com> Co-Authored-By: Tobias Burnus <burnus@net-b.de> Co-Authored-By: Tom de Vries <tom@codesourcery.com> From-SVN: r219682
1472 lines
32 KiB
C
1472 lines
32 KiB
C
/* Copyright (C) 2005-2015 Free Software Foundation, Inc.
|
||
Contributed by Richard Henderson <rth@redhat.com>.
|
||
|
||
This file is part of the GNU Offloading and Multi Processing Library
|
||
(libgomp).
|
||
|
||
Libgomp is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 3, or (at your option)
|
||
any later version.
|
||
|
||
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
|
||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||
more details.
|
||
|
||
Under Section 7 of GPL version 3, you are granted additional
|
||
permissions described in the GCC Runtime Library Exception, version
|
||
3.1, as published by the Free Software Foundation.
|
||
|
||
You should have received a copy of the GNU General Public License and
|
||
a copy of the GCC Runtime Library Exception along with this program;
|
||
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
||
<http://www.gnu.org/licenses/>. */
|
||
|
||
/* This file defines the OpenMP internal control variables, and arranges
|
||
for them to be initialized from environment variables at startup. */
|
||
|
||
#include "libgomp.h"
|
||
#include "libgomp_f.h"
|
||
#include "oacc-int.h"
|
||
#include <ctype.h>
|
||
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#ifdef HAVE_INTTYPES_H
|
||
# include <inttypes.h> /* For PRIu64. */
|
||
#endif
|
||
#ifdef STRING_WITH_STRINGS
|
||
# include <string.h>
|
||
# include <strings.h>
|
||
#else
|
||
# ifdef HAVE_STRING_H
|
||
# include <string.h>
|
||
# else
|
||
# ifdef HAVE_STRINGS_H
|
||
# include <strings.h>
|
||
# endif
|
||
# endif
|
||
#endif
|
||
#include <limits.h>
|
||
#include <errno.h>
|
||
|
||
#ifndef HAVE_STRTOULL
|
||
# define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
|
||
#endif
|
||
|
||
struct gomp_task_icv gomp_global_icv = {
|
||
.nthreads_var = 1,
|
||
.thread_limit_var = UINT_MAX,
|
||
.run_sched_var = GFS_DYNAMIC,
|
||
.run_sched_modifier = 1,
|
||
.default_device_var = 0,
|
||
.dyn_var = false,
|
||
.nest_var = false,
|
||
.bind_var = omp_proc_bind_false,
|
||
.target_data = NULL
|
||
};
|
||
|
||
unsigned long gomp_max_active_levels_var = INT_MAX;
|
||
bool gomp_cancel_var = false;
|
||
#ifndef HAVE_SYNC_BUILTINS
|
||
gomp_mutex_t gomp_managed_threads_lock;
|
||
#endif
|
||
unsigned long gomp_available_cpus = 1, gomp_managed_threads = 1;
|
||
unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
|
||
unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
|
||
char *gomp_bind_var_list;
|
||
unsigned long gomp_bind_var_list_len;
|
||
void **gomp_places_list;
|
||
unsigned long gomp_places_list_len;
|
||
int gomp_debug_var;
|
||
char *goacc_device_type;
|
||
int goacc_device_num;
|
||
|
||
/* Parse the OMP_SCHEDULE environment variable. */
|
||
|
||
static void
|
||
parse_schedule (void)
|
||
{
|
||
char *env, *end;
|
||
unsigned long value;
|
||
|
||
env = getenv ("OMP_SCHEDULE");
|
||
if (env == NULL)
|
||
return;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (strncasecmp (env, "static", 6) == 0)
|
||
{
|
||
gomp_global_icv.run_sched_var = GFS_STATIC;
|
||
env += 6;
|
||
}
|
||
else if (strncasecmp (env, "dynamic", 7) == 0)
|
||
{
|
||
gomp_global_icv.run_sched_var = GFS_DYNAMIC;
|
||
env += 7;
|
||
}
|
||
else if (strncasecmp (env, "guided", 6) == 0)
|
||
{
|
||
gomp_global_icv.run_sched_var = GFS_GUIDED;
|
||
env += 6;
|
||
}
|
||
else if (strncasecmp (env, "auto", 4) == 0)
|
||
{
|
||
gomp_global_icv.run_sched_var = GFS_AUTO;
|
||
env += 4;
|
||
}
|
||
else
|
||
goto unknown;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
{
|
||
gomp_global_icv.run_sched_modifier
|
||
= gomp_global_icv.run_sched_var != GFS_STATIC;
|
||
return;
|
||
}
|
||
if (*env++ != ',')
|
||
goto unknown;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
errno = 0;
|
||
value = strtoul (env, &end, 10);
|
||
if (errno)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
goto invalid;
|
||
|
||
if ((int)value != value)
|
||
goto invalid;
|
||
|
||
if (value == 0 && gomp_global_icv.run_sched_var != GFS_STATIC)
|
||
value = 1;
|
||
gomp_global_icv.run_sched_modifier = value;
|
||
return;
|
||
|
||
unknown:
|
||
gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
|
||
return;
|
||
|
||
invalid:
|
||
gomp_error ("Invalid value for chunk size in "
|
||
"environment variable OMP_SCHEDULE");
|
||
return;
|
||
}
|
||
|
||
/* Parse an unsigned long environment variable. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
|
||
{
|
||
char *env, *end;
|
||
unsigned long value;
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
errno = 0;
|
||
value = strtoul (env, &end, 10);
|
||
if (errno || (long) value <= 0 - allow_zero)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
goto invalid;
|
||
|
||
*pvalue = value;
|
||
return true;
|
||
|
||
invalid:
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
/* Parse a positive int environment variable. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_int (const char *name, int *pvalue, bool allow_zero)
|
||
{
|
||
unsigned long value;
|
||
if (!parse_unsigned_long (name, &value, allow_zero))
|
||
return false;
|
||
if (value > INT_MAX)
|
||
{
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
*pvalue = (int) value;
|
||
return true;
|
||
}
|
||
|
||
/* Parse an unsigned long list environment variable. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_unsigned_long_list (const char *name, unsigned long *p1stvalue,
|
||
unsigned long **pvalues,
|
||
unsigned long *pnvalues)
|
||
{
|
||
char *env, *end;
|
||
unsigned long value, *values = NULL;
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
errno = 0;
|
||
value = strtoul (env, &end, 10);
|
||
if (errno || (long) value <= 0)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
{
|
||
if (*end == ',')
|
||
{
|
||
unsigned long nvalues = 0, nalloced = 0;
|
||
|
||
do
|
||
{
|
||
env = end + 1;
|
||
if (nvalues == nalloced)
|
||
{
|
||
unsigned long *n;
|
||
nalloced = nalloced ? nalloced * 2 : 16;
|
||
n = realloc (values, nalloced * sizeof (unsigned long));
|
||
if (n == NULL)
|
||
{
|
||
free (values);
|
||
gomp_error ("Out of memory while trying to parse"
|
||
" environment variable %s", name);
|
||
return false;
|
||
}
|
||
values = n;
|
||
if (nvalues == 0)
|
||
values[nvalues++] = value;
|
||
}
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
errno = 0;
|
||
value = strtoul (env, &end, 10);
|
||
if (errno || (long) value <= 0)
|
||
goto invalid;
|
||
|
||
values[nvalues++] = value;
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end == '\0')
|
||
break;
|
||
if (*end != ',')
|
||
goto invalid;
|
||
}
|
||
while (1);
|
||
*p1stvalue = values[0];
|
||
*pvalues = values;
|
||
*pnvalues = nvalues;
|
||
return true;
|
||
}
|
||
goto invalid;
|
||
}
|
||
|
||
*p1stvalue = value;
|
||
return true;
|
||
|
||
invalid:
|
||
free (values);
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
/* Parse environment variable set to a boolean or list of omp_proc_bind_t
|
||
enum values. Return true if one was present and it was successfully
|
||
parsed. */
|
||
|
||
static bool
|
||
parse_bind_var (const char *name, char *p1stvalue,
|
||
char **pvalues, unsigned long *pnvalues)
|
||
{
|
||
char *env;
|
||
char value = omp_proc_bind_false, *values = NULL;
|
||
int i;
|
||
static struct proc_bind_kinds
|
||
{
|
||
const char name[7];
|
||
const char len;
|
||
omp_proc_bind_t kind;
|
||
} kinds[] =
|
||
{
|
||
{ "false", 5, omp_proc_bind_false },
|
||
{ "true", 4, omp_proc_bind_true },
|
||
{ "master", 6, omp_proc_bind_master },
|
||
{ "close", 5, omp_proc_bind_close },
|
||
{ "spread", 6, omp_proc_bind_spread }
|
||
};
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
for (i = 0; i < 5; i++)
|
||
if (strncasecmp (env, kinds[i].name, kinds[i].len) == 0)
|
||
{
|
||
value = kinds[i].kind;
|
||
env += kinds[i].len;
|
||
break;
|
||
}
|
||
if (i == 5)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != '\0')
|
||
{
|
||
if (*env == ',')
|
||
{
|
||
unsigned long nvalues = 0, nalloced = 0;
|
||
|
||
if (value == omp_proc_bind_false
|
||
|| value == omp_proc_bind_true)
|
||
goto invalid;
|
||
|
||
do
|
||
{
|
||
env++;
|
||
if (nvalues == nalloced)
|
||
{
|
||
char *n;
|
||
nalloced = nalloced ? nalloced * 2 : 16;
|
||
n = realloc (values, nalloced);
|
||
if (n == NULL)
|
||
{
|
||
free (values);
|
||
gomp_error ("Out of memory while trying to parse"
|
||
" environment variable %s", name);
|
||
return false;
|
||
}
|
||
values = n;
|
||
if (nvalues == 0)
|
||
values[nvalues++] = value;
|
||
}
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
for (i = 2; i < 5; i++)
|
||
if (strncasecmp (env, kinds[i].name, kinds[i].len) == 0)
|
||
{
|
||
value = kinds[i].kind;
|
||
env += kinds[i].len;
|
||
break;
|
||
}
|
||
if (i == 5)
|
||
goto invalid;
|
||
|
||
values[nvalues++] = value;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
break;
|
||
if (*env != ',')
|
||
goto invalid;
|
||
}
|
||
while (1);
|
||
*p1stvalue = values[0];
|
||
*pvalues = values;
|
||
*pnvalues = nvalues;
|
||
return true;
|
||
}
|
||
goto invalid;
|
||
}
|
||
|
||
*p1stvalue = value;
|
||
return true;
|
||
|
||
invalid:
|
||
free (values);
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
static bool
|
||
parse_one_place (char **envp, bool *negatep, unsigned long *lenp,
|
||
long *stridep)
|
||
{
|
||
char *env = *envp, *start;
|
||
void *p = gomp_places_list ? gomp_places_list[gomp_places_list_len] : NULL;
|
||
unsigned long len = 1;
|
||
long stride = 1;
|
||
int pass;
|
||
bool any_negate = false;
|
||
*negatep = false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '!')
|
||
{
|
||
*negatep = true;
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
}
|
||
if (*env != '{')
|
||
return false;
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
start = env;
|
||
for (pass = 0; pass < (any_negate ? 2 : 1); pass++)
|
||
{
|
||
env = start;
|
||
do
|
||
{
|
||
unsigned long this_num, this_len = 1;
|
||
long this_stride = 1;
|
||
bool this_negate = (*env == '!');
|
||
if (this_negate)
|
||
{
|
||
if (gomp_places_list)
|
||
any_negate = true;
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
}
|
||
|
||
errno = 0;
|
||
this_num = strtoul (env, &env, 10);
|
||
if (errno)
|
||
return false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == ':')
|
||
{
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
errno = 0;
|
||
this_len = strtoul (env, &env, 10);
|
||
if (errno || this_len == 0)
|
||
return false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == ':')
|
||
{
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
errno = 0;
|
||
this_stride = strtol (env, &env, 10);
|
||
if (errno)
|
||
return false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
}
|
||
}
|
||
if (this_negate && this_len != 1)
|
||
return false;
|
||
if (gomp_places_list && pass == this_negate)
|
||
{
|
||
if (this_negate)
|
||
{
|
||
if (!gomp_affinity_remove_cpu (p, this_num))
|
||
return false;
|
||
}
|
||
else if (!gomp_affinity_add_cpus (p, this_num, this_len,
|
||
this_stride, false))
|
||
return false;
|
||
}
|
||
if (*env == '}')
|
||
break;
|
||
if (*env != ',')
|
||
return false;
|
||
++env;
|
||
}
|
||
while (1);
|
||
}
|
||
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == ':')
|
||
{
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
errno = 0;
|
||
len = strtoul (env, &env, 10);
|
||
if (errno || len == 0 || len >= 65536)
|
||
return false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == ':')
|
||
{
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
errno = 0;
|
||
stride = strtol (env, &env, 10);
|
||
if (errno)
|
||
return false;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
}
|
||
}
|
||
if (*negatep && len != 1)
|
||
return false;
|
||
*envp = env;
|
||
*lenp = len;
|
||
*stridep = stride;
|
||
return true;
|
||
}
|
||
|
||
static bool
|
||
parse_places_var (const char *name, bool ignore)
|
||
{
|
||
char *env = getenv (name), *end;
|
||
bool any_negate = false;
|
||
int level = 0;
|
||
unsigned long count = 0;
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
if (strncasecmp (env, "threads", 7) == 0)
|
||
{
|
||
env += 7;
|
||
level = 1;
|
||
}
|
||
else if (strncasecmp (env, "cores", 5) == 0)
|
||
{
|
||
env += 5;
|
||
level = 2;
|
||
}
|
||
else if (strncasecmp (env, "sockets", 7) == 0)
|
||
{
|
||
env += 7;
|
||
level = 3;
|
||
}
|
||
if (level)
|
||
{
|
||
count = ULONG_MAX;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != '\0')
|
||
{
|
||
if (*env++ != '(')
|
||
goto invalid;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
|
||
errno = 0;
|
||
count = strtoul (env, &end, 10);
|
||
if (errno)
|
||
goto invalid;
|
||
env = end;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != ')')
|
||
goto invalid;
|
||
++env;
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != '\0')
|
||
goto invalid;
|
||
}
|
||
|
||
if (ignore)
|
||
return false;
|
||
|
||
return gomp_affinity_init_level (level, count, false);
|
||
}
|
||
|
||
count = 0;
|
||
end = env;
|
||
do
|
||
{
|
||
bool negate;
|
||
unsigned long len;
|
||
long stride;
|
||
if (!parse_one_place (&end, &negate, &len, &stride))
|
||
goto invalid;
|
||
if (negate)
|
||
{
|
||
if (!any_negate)
|
||
count++;
|
||
any_negate = true;
|
||
}
|
||
else
|
||
count += len;
|
||
if (count > 65536)
|
||
goto invalid;
|
||
if (*end == '\0')
|
||
break;
|
||
if (*end != ',')
|
||
goto invalid;
|
||
end++;
|
||
}
|
||
while (1);
|
||
|
||
if (ignore)
|
||
return false;
|
||
|
||
gomp_places_list_len = 0;
|
||
gomp_places_list = gomp_affinity_alloc (count, false);
|
||
if (gomp_places_list == NULL)
|
||
return false;
|
||
|
||
do
|
||
{
|
||
bool negate;
|
||
unsigned long len;
|
||
long stride;
|
||
gomp_affinity_init_place (gomp_places_list[gomp_places_list_len]);
|
||
if (!parse_one_place (&env, &negate, &len, &stride))
|
||
goto invalid;
|
||
if (negate)
|
||
{
|
||
void *p;
|
||
for (count = 0; count < gomp_places_list_len; count++)
|
||
if (gomp_affinity_same_place
|
||
(gomp_places_list[count],
|
||
gomp_places_list[gomp_places_list_len]))
|
||
break;
|
||
if (count == gomp_places_list_len)
|
||
{
|
||
gomp_error ("Trying to remove a non-existing place from list "
|
||
"of places");
|
||
goto invalid;
|
||
}
|
||
p = gomp_places_list[count];
|
||
memmove (&gomp_places_list[count],
|
||
&gomp_places_list[count + 1],
|
||
(gomp_places_list_len - count - 1) * sizeof (void *));
|
||
--gomp_places_list_len;
|
||
gomp_places_list[gomp_places_list_len] = p;
|
||
}
|
||
else if (len == 1)
|
||
++gomp_places_list_len;
|
||
else
|
||
{
|
||
for (count = 0; count < len - 1; count++)
|
||
if (!gomp_affinity_copy_place
|
||
(gomp_places_list[gomp_places_list_len + count + 1],
|
||
gomp_places_list[gomp_places_list_len + count],
|
||
stride))
|
||
goto invalid;
|
||
gomp_places_list_len += len;
|
||
}
|
||
if (*env == '\0')
|
||
break;
|
||
env++;
|
||
}
|
||
while (1);
|
||
|
||
if (gomp_places_list_len == 0)
|
||
{
|
||
gomp_error ("All places have been removed");
|
||
goto invalid;
|
||
}
|
||
if (!gomp_affinity_finalize_place_list (false))
|
||
goto invalid;
|
||
return true;
|
||
|
||
invalid:
|
||
free (gomp_places_list);
|
||
gomp_places_list = NULL;
|
||
gomp_places_list_len = 0;
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
/* Parse the OMP_STACKSIZE environment varible. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_stacksize (const char *name, unsigned long *pvalue)
|
||
{
|
||
char *env, *end;
|
||
unsigned long value, shift = 10;
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
errno = 0;
|
||
value = strtoul (env, &end, 10);
|
||
if (errno)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
{
|
||
switch (tolower ((unsigned char) *end))
|
||
{
|
||
case 'b':
|
||
shift = 0;
|
||
break;
|
||
case 'k':
|
||
break;
|
||
case 'm':
|
||
shift = 20;
|
||
break;
|
||
case 'g':
|
||
shift = 30;
|
||
break;
|
||
default:
|
||
goto invalid;
|
||
}
|
||
++end;
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
goto invalid;
|
||
}
|
||
|
||
if (((value << shift) >> shift) != value)
|
||
goto invalid;
|
||
|
||
*pvalue = value << shift;
|
||
return true;
|
||
|
||
invalid:
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
/* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_spincount (const char *name, unsigned long long *pvalue)
|
||
{
|
||
char *env, *end;
|
||
unsigned long long value, mult = 1;
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
goto invalid;
|
||
|
||
if (strncasecmp (env, "infinite", 8) == 0
|
||
|| strncasecmp (env, "infinity", 8) == 0)
|
||
{
|
||
value = ~0ULL;
|
||
end = env + 8;
|
||
goto check_tail;
|
||
}
|
||
|
||
errno = 0;
|
||
value = strtoull (env, &end, 10);
|
||
if (errno)
|
||
goto invalid;
|
||
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
{
|
||
switch (tolower ((unsigned char) *end))
|
||
{
|
||
case 'k':
|
||
mult = 1000LL;
|
||
break;
|
||
case 'm':
|
||
mult = 1000LL * 1000LL;
|
||
break;
|
||
case 'g':
|
||
mult = 1000LL * 1000LL * 1000LL;
|
||
break;
|
||
case 't':
|
||
mult = 1000LL * 1000LL * 1000LL * 1000LL;
|
||
break;
|
||
default:
|
||
goto invalid;
|
||
}
|
||
++end;
|
||
check_tail:
|
||
while (isspace ((unsigned char) *end))
|
||
++end;
|
||
if (*end != '\0')
|
||
goto invalid;
|
||
}
|
||
|
||
if (value > ~0ULL / mult)
|
||
value = ~0ULL;
|
||
else
|
||
value *= mult;
|
||
|
||
*pvalue = value;
|
||
return true;
|
||
|
||
invalid:
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
return false;
|
||
}
|
||
|
||
/* Parse a boolean value for environment variable NAME and store the
|
||
result in VALUE. */
|
||
|
||
static void
|
||
parse_boolean (const char *name, bool *value)
|
||
{
|
||
const char *env;
|
||
|
||
env = getenv (name);
|
||
if (env == NULL)
|
||
return;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (strncasecmp (env, "true", 4) == 0)
|
||
{
|
||
*value = true;
|
||
env += 4;
|
||
}
|
||
else if (strncasecmp (env, "false", 5) == 0)
|
||
{
|
||
*value = false;
|
||
env += 5;
|
||
}
|
||
else
|
||
env = "X";
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != '\0')
|
||
gomp_error ("Invalid value for environment variable %s", name);
|
||
}
|
||
|
||
/* Parse the OMP_WAIT_POLICY environment variable and store the
|
||
result in gomp_active_wait_policy. */
|
||
|
||
static int
|
||
parse_wait_policy (void)
|
||
{
|
||
const char *env;
|
||
int ret = -1;
|
||
|
||
env = getenv ("OMP_WAIT_POLICY");
|
||
if (env == NULL)
|
||
return -1;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (strncasecmp (env, "active", 6) == 0)
|
||
{
|
||
ret = 1;
|
||
env += 6;
|
||
}
|
||
else if (strncasecmp (env, "passive", 7) == 0)
|
||
{
|
||
ret = 0;
|
||
env += 7;
|
||
}
|
||
else
|
||
env = "X";
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env == '\0')
|
||
return ret;
|
||
gomp_error ("Invalid value for environment variable OMP_WAIT_POLICY");
|
||
return -1;
|
||
}
|
||
|
||
/* Parse the GOMP_CPU_AFFINITY environment varible. Return true if one was
|
||
present and it was successfully parsed. */
|
||
|
||
static bool
|
||
parse_affinity (bool ignore)
|
||
{
|
||
char *env, *end, *start;
|
||
int pass;
|
||
unsigned long cpu_beg, cpu_end, cpu_stride;
|
||
size_t count = 0, needed;
|
||
|
||
env = getenv ("GOMP_CPU_AFFINITY");
|
||
if (env == NULL)
|
||
return false;
|
||
|
||
start = env;
|
||
for (pass = 0; pass < 2; pass++)
|
||
{
|
||
env = start;
|
||
if (pass == 1)
|
||
{
|
||
if (ignore)
|
||
return false;
|
||
|
||
gomp_places_list_len = 0;
|
||
gomp_places_list = gomp_affinity_alloc (count, true);
|
||
if (gomp_places_list == NULL)
|
||
return false;
|
||
}
|
||
do
|
||
{
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
|
||
errno = 0;
|
||
cpu_beg = strtoul (env, &end, 0);
|
||
if (errno || cpu_beg >= 65536)
|
||
goto invalid;
|
||
cpu_end = cpu_beg;
|
||
cpu_stride = 1;
|
||
|
||
env = end;
|
||
if (*env == '-')
|
||
{
|
||
errno = 0;
|
||
cpu_end = strtoul (++env, &end, 0);
|
||
if (errno || cpu_end >= 65536 || cpu_end < cpu_beg)
|
||
goto invalid;
|
||
|
||
env = end;
|
||
if (*env == ':')
|
||
{
|
||
errno = 0;
|
||
cpu_stride = strtoul (++env, &end, 0);
|
||
if (errno || cpu_stride == 0 || cpu_stride >= 65536)
|
||
goto invalid;
|
||
|
||
env = end;
|
||
}
|
||
}
|
||
|
||
needed = (cpu_end - cpu_beg) / cpu_stride + 1;
|
||
if (pass == 0)
|
||
count += needed;
|
||
else
|
||
{
|
||
while (needed--)
|
||
{
|
||
void *p = gomp_places_list[gomp_places_list_len];
|
||
gomp_affinity_init_place (p);
|
||
if (gomp_affinity_add_cpus (p, cpu_beg, 1, 0, true))
|
||
++gomp_places_list_len;
|
||
cpu_beg += cpu_stride;
|
||
}
|
||
}
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
|
||
if (*env == ',')
|
||
env++;
|
||
else if (*env == '\0')
|
||
break;
|
||
}
|
||
while (1);
|
||
}
|
||
|
||
if (gomp_places_list_len == 0)
|
||
{
|
||
free (gomp_places_list);
|
||
gomp_places_list = NULL;
|
||
return false;
|
||
}
|
||
return true;
|
||
|
||
invalid:
|
||
gomp_error ("Invalid value for enviroment variable GOMP_CPU_AFFINITY");
|
||
return false;
|
||
}
|
||
|
||
static void
|
||
parse_acc_device_type (void)
|
||
{
|
||
const char *env = getenv ("ACC_DEVICE_TYPE");
|
||
|
||
if (env && *env != '\0')
|
||
goacc_device_type = strdup (env);
|
||
else
|
||
goacc_device_type = NULL;
|
||
}
|
||
|
||
static void
|
||
handle_omp_display_env (unsigned long stacksize, int wait_policy)
|
||
{
|
||
const char *env;
|
||
bool display = false;
|
||
bool verbose = false;
|
||
int i;
|
||
|
||
env = getenv ("OMP_DISPLAY_ENV");
|
||
if (env == NULL)
|
||
return;
|
||
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (strncasecmp (env, "true", 4) == 0)
|
||
{
|
||
display = true;
|
||
env += 4;
|
||
}
|
||
else if (strncasecmp (env, "false", 5) == 0)
|
||
{
|
||
display = false;
|
||
env += 5;
|
||
}
|
||
else if (strncasecmp (env, "verbose", 7) == 0)
|
||
{
|
||
display = true;
|
||
verbose = true;
|
||
env += 7;
|
||
}
|
||
else
|
||
env = "X";
|
||
while (isspace ((unsigned char) *env))
|
||
++env;
|
||
if (*env != '\0')
|
||
gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
|
||
|
||
if (!display)
|
||
return;
|
||
|
||
fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
|
||
|
||
fputs (" _OPENMP = '201307'\n", stderr);
|
||
fprintf (stderr, " OMP_DYNAMIC = '%s'\n",
|
||
gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
|
||
fprintf (stderr, " OMP_NESTED = '%s'\n",
|
||
gomp_global_icv.nest_var ? "TRUE" : "FALSE");
|
||
|
||
fprintf (stderr, " OMP_NUM_THREADS = '%lu", gomp_global_icv.nthreads_var);
|
||
for (i = 1; i < gomp_nthreads_var_list_len; i++)
|
||
fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
|
||
fputs ("'\n", stderr);
|
||
|
||
fprintf (stderr, " OMP_SCHEDULE = '");
|
||
switch (gomp_global_icv.run_sched_var)
|
||
{
|
||
case GFS_RUNTIME:
|
||
fputs ("RUNTIME", stderr);
|
||
break;
|
||
case GFS_STATIC:
|
||
fputs ("STATIC", stderr);
|
||
break;
|
||
case GFS_DYNAMIC:
|
||
fputs ("DYNAMIC", stderr);
|
||
break;
|
||
case GFS_GUIDED:
|
||
fputs ("GUIDED", stderr);
|
||
break;
|
||
case GFS_AUTO:
|
||
fputs ("AUTO", stderr);
|
||
break;
|
||
}
|
||
fputs ("'\n", stderr);
|
||
|
||
fputs (" OMP_PROC_BIND = '", stderr);
|
||
switch (gomp_global_icv.bind_var)
|
||
{
|
||
case omp_proc_bind_false:
|
||
fputs ("FALSE", stderr);
|
||
break;
|
||
case omp_proc_bind_true:
|
||
fputs ("TRUE", stderr);
|
||
break;
|
||
case omp_proc_bind_master:
|
||
fputs ("MASTER", stderr);
|
||
break;
|
||
case omp_proc_bind_close:
|
||
fputs ("CLOSE", stderr);
|
||
break;
|
||
case omp_proc_bind_spread:
|
||
fputs ("SPREAD", stderr);
|
||
break;
|
||
}
|
||
for (i = 1; i < gomp_bind_var_list_len; i++)
|
||
switch (gomp_bind_var_list[i])
|
||
{
|
||
case omp_proc_bind_master:
|
||
fputs (",MASTER", stderr);
|
||
break;
|
||
case omp_proc_bind_close:
|
||
fputs (",CLOSE", stderr);
|
||
break;
|
||
case omp_proc_bind_spread:
|
||
fputs (",SPREAD", stderr);
|
||
break;
|
||
}
|
||
fputs ("'\n", stderr);
|
||
fputs (" OMP_PLACES = '", stderr);
|
||
for (i = 0; i < gomp_places_list_len; i++)
|
||
{
|
||
fputs ("{", stderr);
|
||
gomp_affinity_print_place (gomp_places_list[i]);
|
||
fputs (i + 1 == gomp_places_list_len ? "}" : "},", stderr);
|
||
}
|
||
fputs ("'\n", stderr);
|
||
|
||
fprintf (stderr, " OMP_STACKSIZE = '%lu'\n", stacksize);
|
||
|
||
/* GOMP's default value is actually neither active nor passive. */
|
||
fprintf (stderr, " OMP_WAIT_POLICY = '%s'\n",
|
||
wait_policy > 0 ? "ACTIVE" : "PASSIVE");
|
||
fprintf (stderr, " OMP_THREAD_LIMIT = '%u'\n",
|
||
gomp_global_icv.thread_limit_var);
|
||
fprintf (stderr, " OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
|
||
gomp_max_active_levels_var);
|
||
|
||
fprintf (stderr, " OMP_CANCELLATION = '%s'\n",
|
||
gomp_cancel_var ? "TRUE" : "FALSE");
|
||
fprintf (stderr, " OMP_DEFAULT_DEVICE = '%d'\n",
|
||
gomp_global_icv.default_device_var);
|
||
|
||
if (verbose)
|
||
{
|
||
fputs (" GOMP_CPU_AFFINITY = ''\n", stderr);
|
||
fprintf (stderr, " GOMP_STACKSIZE = '%lu'\n", stacksize);
|
||
#ifdef HAVE_INTTYPES_H
|
||
fprintf (stderr, " GOMP_SPINCOUNT = '%"PRIu64"'\n",
|
||
(uint64_t) gomp_spin_count_var);
|
||
#else
|
||
fprintf (stderr, " GOMP_SPINCOUNT = '%lu'\n",
|
||
(unsigned long) gomp_spin_count_var);
|
||
#endif
|
||
}
|
||
|
||
fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
|
||
}
|
||
|
||
|
||
static void __attribute__((constructor))
|
||
initialize_env (void)
|
||
{
|
||
unsigned long thread_limit_var, stacksize;
|
||
int wait_policy;
|
||
|
||
/* Do a compile time check that mkomp_h.pl did good job. */
|
||
omp_check_defines ();
|
||
|
||
parse_schedule ();
|
||
parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var);
|
||
parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var);
|
||
parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var);
|
||
parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv.default_device_var, true);
|
||
parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var,
|
||
true);
|
||
if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var, false))
|
||
{
|
||
gomp_global_icv.thread_limit_var
|
||
= thread_limit_var > INT_MAX ? UINT_MAX : thread_limit_var;
|
||
}
|
||
parse_int ("GOMP_DEBUG", &gomp_debug_var, true);
|
||
#ifndef HAVE_SYNC_BUILTINS
|
||
gomp_mutex_init (&gomp_managed_threads_lock);
|
||
#endif
|
||
gomp_init_num_threads ();
|
||
gomp_available_cpus = gomp_global_icv.nthreads_var;
|
||
if (!parse_unsigned_long_list ("OMP_NUM_THREADS",
|
||
&gomp_global_icv.nthreads_var,
|
||
&gomp_nthreads_var_list,
|
||
&gomp_nthreads_var_list_len))
|
||
gomp_global_icv.nthreads_var = gomp_available_cpus;
|
||
bool ignore = false;
|
||
if (parse_bind_var ("OMP_PROC_BIND",
|
||
&gomp_global_icv.bind_var,
|
||
&gomp_bind_var_list,
|
||
&gomp_bind_var_list_len)
|
||
&& gomp_global_icv.bind_var == omp_proc_bind_false)
|
||
ignore = true;
|
||
/* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always
|
||
parsed if present in the environment. If OMP_PROC_BIND was set
|
||
explictly to false, don't populate places list though. If places
|
||
list was successfully set from OMP_PLACES, only parse but don't process
|
||
GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment,
|
||
default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY
|
||
was successfully parsed into a places list, otherwise to
|
||
OMP_PROC_BIND=false. */
|
||
if (parse_places_var ("OMP_PLACES", ignore))
|
||
{
|
||
if (gomp_global_icv.bind_var == omp_proc_bind_false)
|
||
gomp_global_icv.bind_var = true;
|
||
ignore = true;
|
||
}
|
||
if (parse_affinity (ignore))
|
||
{
|
||
if (gomp_global_icv.bind_var == omp_proc_bind_false)
|
||
gomp_global_icv.bind_var = true;
|
||
ignore = true;
|
||
}
|
||
if (gomp_global_icv.bind_var != omp_proc_bind_false)
|
||
gomp_init_affinity ();
|
||
wait_policy = parse_wait_policy ();
|
||
if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var))
|
||
{
|
||
/* Using a rough estimation of 100000 spins per msec,
|
||
use 5 min blocking for OMP_WAIT_POLICY=active,
|
||
3 msec blocking when OMP_WAIT_POLICY is not specificed
|
||
and 0 when OMP_WAIT_POLICY=passive.
|
||
Depending on the CPU speed, this can be e.g. 5 times longer
|
||
or 5 times shorter. */
|
||
if (wait_policy > 0)
|
||
gomp_spin_count_var = 30000000000LL;
|
||
else if (wait_policy < 0)
|
||
gomp_spin_count_var = 300000LL;
|
||
}
|
||
/* gomp_throttled_spin_count_var is used when there are more libgomp
|
||
managed threads than available CPUs. Use very short spinning. */
|
||
if (wait_policy > 0)
|
||
gomp_throttled_spin_count_var = 1000LL;
|
||
else if (wait_policy < 0)
|
||
gomp_throttled_spin_count_var = 100LL;
|
||
if (gomp_throttled_spin_count_var > gomp_spin_count_var)
|
||
gomp_throttled_spin_count_var = gomp_spin_count_var;
|
||
|
||
/* Not strictly environment related, but ordering constructors is tricky. */
|
||
pthread_attr_init (&gomp_thread_attr);
|
||
pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED);
|
||
|
||
if (parse_stacksize ("OMP_STACKSIZE", &stacksize)
|
||
|| parse_stacksize ("GOMP_STACKSIZE", &stacksize))
|
||
{
|
||
int err;
|
||
|
||
err = pthread_attr_setstacksize (&gomp_thread_attr, stacksize);
|
||
|
||
#ifdef PTHREAD_STACK_MIN
|
||
if (err == EINVAL)
|
||
{
|
||
if (stacksize < PTHREAD_STACK_MIN)
|
||
gomp_error ("Stack size less than minimum of %luk",
|
||
PTHREAD_STACK_MIN / 1024ul
|
||
+ (PTHREAD_STACK_MIN % 1024 != 0));
|
||
else
|
||
gomp_error ("Stack size larger than system limit");
|
||
}
|
||
else
|
||
#endif
|
||
if (err != 0)
|
||
gomp_error ("Stack size change failed: %s", strerror (err));
|
||
}
|
||
|
||
handle_omp_display_env (stacksize, wait_policy);
|
||
|
||
/* OpenACC. */
|
||
|
||
if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num, true))
|
||
goacc_device_num = 0;
|
||
|
||
parse_acc_device_type ();
|
||
|
||
goacc_runtime_initialize ();
|
||
}
|
||
|
||
|
||
/* The public OpenMP API routines that access these variables. */
|
||
|
||
void
|
||
omp_set_num_threads (int n)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (true);
|
||
icv->nthreads_var = (n > 0 ? n : 1);
|
||
}
|
||
|
||
void
|
||
omp_set_dynamic (int val)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (true);
|
||
icv->dyn_var = val;
|
||
}
|
||
|
||
int
|
||
omp_get_dynamic (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->dyn_var;
|
||
}
|
||
|
||
void
|
||
omp_set_nested (int val)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (true);
|
||
icv->nest_var = val;
|
||
}
|
||
|
||
int
|
||
omp_get_nested (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->nest_var;
|
||
}
|
||
|
||
void
|
||
omp_set_schedule (omp_sched_t kind, int modifier)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (true);
|
||
switch (kind)
|
||
{
|
||
case omp_sched_static:
|
||
if (modifier < 1)
|
||
modifier = 0;
|
||
icv->run_sched_modifier = modifier;
|
||
break;
|
||
case omp_sched_dynamic:
|
||
case omp_sched_guided:
|
||
if (modifier < 1)
|
||
modifier = 1;
|
||
icv->run_sched_modifier = modifier;
|
||
break;
|
||
case omp_sched_auto:
|
||
break;
|
||
default:
|
||
return;
|
||
}
|
||
icv->run_sched_var = kind;
|
||
}
|
||
|
||
void
|
||
omp_get_schedule (omp_sched_t *kind, int *modifier)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
*kind = icv->run_sched_var;
|
||
*modifier = icv->run_sched_modifier;
|
||
}
|
||
|
||
int
|
||
omp_get_max_threads (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->nthreads_var;
|
||
}
|
||
|
||
int
|
||
omp_get_thread_limit (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
|
||
}
|
||
|
||
void
|
||
omp_set_max_active_levels (int max_levels)
|
||
{
|
||
if (max_levels >= 0)
|
||
gomp_max_active_levels_var = max_levels;
|
||
}
|
||
|
||
int
|
||
omp_get_max_active_levels (void)
|
||
{
|
||
return gomp_max_active_levels_var;
|
||
}
|
||
|
||
int
|
||
omp_get_cancellation (void)
|
||
{
|
||
return gomp_cancel_var;
|
||
}
|
||
|
||
omp_proc_bind_t
|
||
omp_get_proc_bind (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->bind_var;
|
||
}
|
||
|
||
void
|
||
omp_set_default_device (int device_num)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (true);
|
||
icv->default_device_var = device_num >= 0 ? device_num : 0;
|
||
}
|
||
|
||
int
|
||
omp_get_default_device (void)
|
||
{
|
||
struct gomp_task_icv *icv = gomp_icv (false);
|
||
return icv->default_device_var;
|
||
}
|
||
|
||
int
|
||
omp_get_num_devices (void)
|
||
{
|
||
return gomp_get_num_devices ();
|
||
}
|
||
|
||
int
|
||
omp_get_num_teams (void)
|
||
{
|
||
/* Hardcoded to 1 on host, MIC, HSAIL? Maybe variable on PTX. */
|
||
return 1;
|
||
}
|
||
|
||
int
|
||
omp_get_team_num (void)
|
||
{
|
||
/* Hardcoded to 0 on host, MIC, HSAIL? Maybe variable on PTX. */
|
||
return 0;
|
||
}
|
||
|
||
int
|
||
omp_is_initial_device (void)
|
||
{
|
||
/* Hardcoded to 1 on host, should be 0 on MIC, HSAIL, PTX. */
|
||
return 1;
|
||
}
|
||
|
||
ialias (omp_set_dynamic)
|
||
ialias (omp_set_nested)
|
||
ialias (omp_set_num_threads)
|
||
ialias (omp_get_dynamic)
|
||
ialias (omp_get_nested)
|
||
ialias (omp_set_schedule)
|
||
ialias (omp_get_schedule)
|
||
ialias (omp_get_max_threads)
|
||
ialias (omp_get_thread_limit)
|
||
ialias (omp_set_max_active_levels)
|
||
ialias (omp_get_max_active_levels)
|
||
ialias (omp_get_cancellation)
|
||
ialias (omp_get_proc_bind)
|
||
ialias (omp_set_default_device)
|
||
ialias (omp_get_default_device)
|
||
ialias (omp_get_num_devices)
|
||
ialias (omp_get_num_teams)
|
||
ialias (omp_get_team_num)
|
||
ialias (omp_is_initial_device)
|