diff --git a/openmp/libomptarget/test/offloading/target_task_reductions.c b/openmp/libomptarget/test/offloading/target_task_reductions.c new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/test/offloading/target_task_reductions.c @@ -0,0 +1,67 @@ +// RUN: %libomptarget-compile-generic -O3 && %libomptarget-run-generic + +// UNSUPPORTED: amdgcn-amd-amdhsa + +/* + +This test is imported from SOLLVE: 5.0/task/test_task_in_reduction_device.c +SOLLVE page: https://github.com/SOLLVE/sollve_vv + +OpenMP API Version 5.0 Nov 2018 + +This test checks the task directive with the `in_reduction` reduction +participation clause. It performs simple array operations which are added +to a reduction variable in an explcit task with the in_reduction clause. +This test checks the above in a target context. + +*/ + +#include +#include +#include + +#define N 1024 +#define NUM_THREADS_DEVICE 512 + + +int main() { + printf("test_task_in_reduction\n"); + int num_threads = -1; + int y[N]; + int z[N]; + int sum = 0; + int expected_sum = 0; + + for (int i = 0; i < N; i++) { + y[i] = i + 1; + z[i] = 2*(i + 1); + } + +#pragma omp target parallel reduction(task, +: sum) num_threads(NUM_THREADS_DEVICE) shared(y, z, num_threads) map(tofrom: sum, num_threads) map(to: y, z) + { +#pragma omp master + { +#pragma omp task in_reduction(+: sum) + { + for (int i = 0; i < N; i++) { + sum += y[i]*z[i]; + } + } + num_threads = omp_get_num_threads(); + } + } + + for (int i = 0; i < N; i++) { + expected_sum += y[i]*z[i]; + } + + if(num_threads == 1) + printf("Test ran with one thread, so parallelism of taskloop can't be guaranteed."); + if(num_threads < 1) + printf("Test returned an invalid number of threads."); + + if(sum != expected_sum || num_threads < 1) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp b/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp @@ -0,0 +1,86 @@ +// RUN: %libomp-cxx-compile-and-run + +/* + +This test is imported from SOLLVE: 5.0/task/test_task_depend_iterator.cpp +SOLLVE page: https://github.com/SOLLVE/sollve_vv + +OpenMP API Version 5.0 Nov 2020 + +This test is for the iterator modifier when used with the task depend +clause. This modifier should create an iterator that expands to multiple values +inside the clause they appear. In this particular test case the iterator expands into +several values creating several dependencies at the same time. + +*/ + +#include +#include +#include +#include +#include +#include +#include "omp_testsuite.h" + +#define N 1024 +#define FROM 64 +#define LENGTH 128 + +int test_omp_task_depend_iterator() { + int ptr[] = {0, 4, 5, 6, 7, 8, 9, 10, 11}; + int cols[] = {1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8}; + std::vector threadOrder; + bool threadOrderError = false; +#pragma omp parallel num_threads(8) + { +#pragma omp single + { + for (int i = 0; i < 8; ++i) { + int pos = ptr[i], size = ptr[i + 1] - ptr[i]; +#pragma omp task depend(iterator(it = 0 : size), in : ptr[cols[pos + it]]) depend(out : ptr[i]) + { +#pragma omp critical + { + threadOrder.push_back(i); + } // end critical section + } // end task depend + } + } // end single + } // end parallel + + // store the indices of the execution order of generated tasks in idx[] + std::vector::iterator idx[8]; + for (int i = 0; i < 8; ++i) + idx[i] = std::find (threadOrder.begin(), threadOrder.end(), i); + + // verify that dependencies are met in the order + if (idx[0] != threadOrder.begin()) + threadOrderError |= true; + if (idx[1] > idx[5] || idx[2] > idx[5]) + threadOrderError |= true; + if (idx[3] > idx[6] || idx[4] > idx[6]) + threadOrderError |= true; + if (idx[5] > idx[7] || idx[6] > idx[7]) + threadOrderError |= true; + + std::sort(threadOrder.begin(), threadOrder.end()); + for(int i = 0; i < 8; ++i) + threadOrderError = (threadOrder[i] != i) || threadOrderError; + + // FALSE If dependencies between tasks were not enforced in the correct order. + return !threadOrderError; +} + + + +int main() { + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_omp_task_depend_iterator()) { + num_failed++; + } + } + return num_failed; +}