https://gcc.gnu.org/g:839397e2483e73957313405c8a9e516858c64fe5
commit 839397e2483e73957313405c8a9e516858c64fe5 Author: Andrew Stubbs <[email protected]> Date: Wed Nov 4 12:57:14 2026 +0000 amdgcn: enable full-SIMT mode Switch the --param=offload-gpu-mode=simt so that it is no longer a synonym for "simt-directed", and pass the mode information to all the places that will need to know, at compile time and runtime. In "directed" mode there are 16 waves of 64 threads, controlled by the "omp simd" directive. In the full-SIMT mode there will be a notional 1024 threads (although the low-level still requires managing wavefronts, of course.) The implementation will follow in rest of this patch series. gcc/ChangeLog: * config/gcn/gcn.cc (gcn_simt_vf): Return 1 in "simt" mode. (gcn_hsa_declare_function_name): Emit a SIMT-MODE comment for mkoffload. * config/gcn/mkoffload.cc (process_asm): Read the SIMT-MODE comments, and add a simt_mode field to the gcn_kernels table. * omp-general.cc (omp_max_vf): Use the amdgcn vector width only in "simd" and "auto" modes. (omp_max_simt_vf): Return 0 in "simt" mode. * opts.cc (finish_options): Use "simt-directed" mode instead of "simt" mode for OpenACC. Diff: --- gcc/config/gcn/gcn.cc | 14 ++++++++++++-- gcc/config/gcn/mkoffload.cc | 26 +++++++++++++++++++++++--- gcc/omp-general.cc | 9 +++++++-- gcc/opts.cc | 7 +++++++ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index 662195f01ec2..05a839eb0f1e 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -6299,8 +6299,10 @@ gcn_simt_vf (void) case OFFLOAD_GPU_MODE_SIMD: return 1; case OFFLOAD_GPU_MODE_SIMT_DIRECTED: - case OFFLOAD_GPU_MODE_SIMT: return 64; + case OFFLOAD_GPU_MODE_SIMT: + /* Disable SIMT transformations in the middle-end. */ + return 1; } return 1; } @@ -7558,12 +7560,20 @@ gcn_hsa_declare_function_name (FILE *file, const char *name, fputs (",@function\n", file); ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); - /* This comment is read by mkoffload. */ + /* These comments are read by mkoffload. */ if (flag_openacc) fprintf (file, "\t;; OPENACC-DIMS: %d, %d, %d : %s\n", oacc_get_fn_dim_size (cfun->decl, GOMP_DIM_GANG), oacc_get_fn_dim_size (cfun->decl, GOMP_DIM_WORKER), oacc_get_fn_dim_size (cfun->decl, GOMP_DIM_VECTOR), name); + if (flag_simt_mode) + fprintf (file, "\t;; SIMT-MODE: %s\n", + (param_offload_gpu_mode == OFFLOAD_GPU_MODE_SIMT_DIRECTED + ? "simt-directed" + : (param_offload_gpu_mode == OFFLOAD_GPU_MODE_SIMT + /*|| param_offload_gpu_mode == OFFLOAD_GPU_MODE_AUTO*/) + ? "simt" + : "unknown")); } /* Implement TARGET_ASM_INIT_SECTIONS. */ diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 30e1b44635c1..d8cbbee7c08c 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -468,6 +468,12 @@ process_asm (FILE *in, FILE *out, FILE *cfile, uint32_t omp_requires) char *kernel_name; } regcount = { -1, -1, NULL }; + enum { + SIMD_MODE, + SIMT_DIRECTED_MODE, + SIMT_MODE + } simt_mode = SIMD_MODE; + /* Always add _init_array and _fini_array as kernels. */ obstack_ptr_grow (&fns_os, xstrdup ("_init_array")); obstack_ptr_grow (&fns_os, xstrdup ("_fini_array")); @@ -488,13 +494,26 @@ process_asm (FILE *in, FILE *out, FILE *cfile, uint32_t omp_requires) { case IN_CODE: { + char *s; if (sscanf (buf, " ;; OPENACC-DIMS: %d, %d, %d : %ms\n", &dim.d[0], &dim.d[1], &dim.d[2], &dim.name) == 4) { obstack_grow (&dims_os, &dim, sizeof (dim)); dims_count++; } - + else if (sscanf (buf, " ;; SIMT-MODE: %ms\n", + &s) == 1) + { + int saved_mode = simt_mode; + if (strcmp (s, "simt-directed") == 0) + simt_mode = SIMT_DIRECTED_MODE; + else if (strcmp (s, "simt") == 0) + simt_mode = SIMT_MODE; + else + gcc_unreachable (); + if (saved_mode && saved_mode != simt_mode) + sorry ("Mixed SIMT/SIMT-DIRECTED is not yet supported."); + } break; } case IN_METADATA: @@ -651,6 +670,7 @@ process_asm (FILE *in, FILE *out, FILE *cfile, uint32_t omp_requires) " int oacc_dims[3];\n" " int sgpr_count;\n" " int vgpr_count;\n" + " int simt_mode;\n" "} gcn_kernels[] = {\n "); dim.d[0] = dim.d[1] = dim.d[2] = 0; const char *comma; @@ -675,8 +695,8 @@ process_asm (FILE *in, FILE *out, FILE *cfile, uint32_t omp_requires) break; } - fprintf (cfile, "%s{\"%s\", {%d, %d, %d}, %d, %d}", comma, - fns[i], d[0], d[1], d[2], sgpr_count, vgpr_count); + fprintf (cfile, "%s{\"%s\", {%d, %d, %d}, %d, %d, %d}", comma, + fns[i], d[0], d[1], d[2], sgpr_count, vgpr_count, simt_mode); free (fns[i]); } diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index e10b6e23061a..4e7393f2369f 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1024,7 +1024,9 @@ omp_max_vf (bool offload) { for (const char *c = getenv ("OFFLOAD_TARGET_NAMES"); c;) { - if (startswith (c, "amdgcn")) + if (startswith (c, "amdgcn") + && (param_offload_gpu_mode == OFFLOAD_GPU_MODE_SIMD + || param_offload_gpu_mode == OFFLOAD_GPU_MODE_AUTO)) return ordered_max (poly_uint64 (64), omp_max_vf (false)); else if ((c = strchr (c, ':'))) c++; @@ -1066,9 +1068,12 @@ omp_max_simt_vf (void) { switch (param_offload_gpu_mode) { - case OFFLOAD_GPU_MODE_SIMT: /* For now. */ case OFFLOAD_GPU_MODE_SIMT_DIRECTED: return 64; + case OFFLOAD_GPU_MODE_SIMT: + /* Do not emit SIMT IR here; the backend and libgomp + will change mode to do SIMT for OMP threads. */ + return 0; case OFFLOAD_GPU_MODE_AUTO: case OFFLOAD_GPU_MODE_SIMD: return 0; diff --git a/gcc/opts.cc b/gcc/opts.cc index cb2c05492a01..4a3d40244312 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -1546,6 +1546,13 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, error ("%<-fopenmp-target=%> requires %<-fopenmp%> setting"); } + /* The "simt" offload mode makes each SIMT lane an OpenMP thread. OpenACC + has the "vector" level for that, so is the same as in "simt-directed" + mode. */ + if (opts->x_flag_openacc + && opts->x_param_offload_gpu_mode == OFFLOAD_GPU_MODE_SIMT) + opts->x_param_offload_gpu_mode = OFFLOAD_GPU_MODE_SIMT_DIRECTED; + diagnose_options (opts, opts_set, loc); }
