Files
Alex Duran 56a012b96a [offload][omp] Move strict threads & groups computation to libomptarget (#222607)
Move all computation related to strict threads and strict groups to
libomptarget as it's specific to OpenMP. This also removes all refrences
to ExecutionModes from the Plugin Interface.

With this, the data from the OpenMP kernel environment being used is
ReductionDataSize used to create the KLE, and maxNumThreads used by
RecordReplay. They're are purposely left for a future PR.

Assisted by Claude.
2026-10-02 07:28:39 +02:00

154 lines
6.1 KiB
C

// RUN: %libomptarget-compile-generic
// RUN: env LIBOMPTARGET_INFO=63 %libomptarget-run-generic 2>&1 | \
// RUN: %fcheck-generic
//
// REQUIRES: gpu
#include <ompx.h>
#include <stdio.h>
void get_gridsizes(int *nblocks, int *nthreads) {
if (ompx_block_id_x() == 0 && ompx_thread_id_x() == 0 &&
ompx_block_id_y() == 0 && ompx_thread_id_y() == 0 &&
ompx_block_id_z() == 0 && ompx_thread_id_z() == 0) {
nblocks[0] = ompx_grid_dim_x();
nblocks[1] = ompx_grid_dim_y();
nblocks[2] = ompx_grid_dim_z();
nthreads[0] = ompx_block_dim_x();
nthreads[1] = ompx_block_dim_y();
nthreads[2] = ompx_block_dim_z();
}
}
int main(int argc, char *argv[]) {
int nblocks[3], nthreads[3];
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,1,1] blocks and [32,1,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64) thread_limit(32) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 1 1, nthreads: 32 1 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,1,1] blocks and [32,4,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64) thread_limit(32, 4) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 1 1, nthreads: 32 4 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,1,1] blocks and [32,4,2]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64) thread_limit(32, 4, 2) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 1 1, nthreads: 32 4 2
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,1] blocks and [32,1,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 1) thread_limit(32) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 1, nthreads: 32 1 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,1] blocks and [32,4,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 1) thread_limit(32, 4) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 1, nthreads: 32 4 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,1] blocks and [32,4,2]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 1) thread_limit(32, 4, 2) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 1, nthreads: 32 4 2
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,8] blocks and [32,1,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 8) thread_limit(32) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 8, nthreads: 32 1 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,8] blocks and [32,4,1]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 8) thread_limit(32, 4) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 8, nthreads: 32 4 1
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
// CHECK: omptarget device 0 info: Launching kernel
// CHECK-SAME: __omp_offloading_{{.*}} with [64,16,8] blocks and [32,4,2]
// CHECK-SAME: threads in BARE mode
nblocks[0] = nblocks[1] = nblocks[2] = nthreads[0] = nthreads[1] =
nthreads[2] = 0;
#pragma omp target teams ompx_bare num_teams(64, 16, 8) thread_limit(32, 4, 2) \
map(tofrom : nblocks, nthreads)
{
get_gridsizes(nblocks, nthreads);
}
// CHECK: nblocks: 64 16 8, nthreads: 32 4 2
fprintf(stderr, "nblocks: %d %d %d, nthreads: %d %d %d\n", nblocks[0],
nblocks[1], nblocks[2], nthreads[0], nthreads[1], nthreads[2]);
return 0;
}