The patch contains a basic BumpAllocator for (AMD)GPUs to allow us to run more tests. The allocator implements `malloc`, both internally and externally, while we continue to default to the NVIDIA `malloc` when we target NVIDIA GPUs. Once we have smarter or customizable allocators we should consider this choice, for now, this allocator is better than none. It traps if it is out of memory, making it easy to debug. Heap size is configured via `LIBOMPTARGET_HEAP_SIZE` and defaults to 512MB. It allows to track allocation statistics via `LIBOMPTARGET_DEVICE_RTL_DEBUG=8` (together with `-fopenmp-target-debug=8`). Two tests were added, and one was enabled. This is the next step towards fixing https://github.com/llvm/llvm-project/issues/66708
38 lines
999 B
C
38 lines
999 B
C
// RUN: %libomptarget-compile-generic && %libomptarget-run-generic
|
|
// RUN: %libomptarget-compileopt-generic && %libomptarget-run-generic
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main() {
|
|
long unsigned *DP = 0;
|
|
int N = 128;
|
|
int Threads = 128;
|
|
int Teams = 440;
|
|
|
|
// Allocate ~55MB on the device.
|
|
#pragma omp target map(from : DP)
|
|
DP = (long unsigned *)malloc(sizeof(long unsigned) * N * Threads * Teams);
|
|
|
|
#pragma omp target teams distribute parallel for num_teams(Teams) \
|
|
thread_limit(Threads) is_device_ptr(DP)
|
|
for (int i = 0; i < Threads * Teams; ++i) {
|
|
for (int j = 0; j < N; ++j) {
|
|
DP[i * N + j] = i + j;
|
|
}
|
|
}
|
|
|
|
long unsigned s = 0;
|
|
#pragma omp target teams distribute parallel for num_teams(Teams) \
|
|
thread_limit(Threads) reduction(+ : s)
|
|
for (int i = 0; i < Threads * Teams; ++i) {
|
|
for (int j = 0; j < N; ++j) {
|
|
s += DP[i * N + j];
|
|
}
|
|
}
|
|
|
|
// CHECK: Sum: 203458478080
|
|
printf("Sum: %li\n", s);
|
|
return 0;
|
|
}
|