From f660be6303cb92013c6ecd57ff8c67ecb600c40f Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 25 Sep 2025 10:41:07 -0700 Subject: [PATCH 01/19] Adding rough test --- .../test_declare_target_local.c | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/6.0/declare_target/test_declare_target_local.c diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c new file mode 100644 index 000000000..06613f389 --- /dev/null +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -0,0 +1,88 @@ +//--------------- test_declare_target_local.c -----------------------------------------// +// OpenMP API Version 6.0 November 2024 +///////////// +// Pg. 902, line 4 +// *********** +// DIRECTIVE:target +// CLAUSE:data +// The target_data directive is being used in three scenaries of various task +// configurations for the same functional task. Because target_data is a +// task-generating composite construct, it will have expected effects that are +// being tested in each scenario. If the work_function executes correctly, then +// the value of a should expectedly change to 1. +//-------------------------------------------------------------------------------------// + +#include "ompvv.h" +#include + +#define N 100 + +// int work_function(int var) { return var + 1; } +// void check_function(int var, int *errors) { +// OMPVV_ERROR_IF(var != 1, "Expected %i, received %i", 1, var); +// OMPVV_TEST_AND_SET(*errors, var != 1); +// return; +// } + int sum; + int x[100]; + + #pragma omp declare_target local(sum, x) + #pragma omp begin declare_target + void init_x(int dev_id) { + for (int j = 0; j < 100; ++j) { + x[j] = j + dev_id; + } + } + void foo(void) { + int i; + #pragma omp for reduction(+:sum) + for (i = 0; i < 100; i++) { + sum += x[i]; + } + } + #pragma omp end declare target + + +int test_declare_target_local() { + int errors = 0; + + int TotGpus = omp_get_num_devices(); + OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were found. \n This test will be skipped.\n"); + if (TotGpus < 1) { + return OMPVV_SKIPPED_EXIT_CODE; + } + + for (int i = 0; i < ndev; i++) { + #pragma omp target device(i) + { + init_x(i); + sum = 0; + } + } + + for (int i = 0; i < ndev; i++) { + #pragma omp target parallel device(i) nowait + foo(); + } + #pragma omp taskwait + + for (int i = 0; i < ndev; i++) { + #pragma omp target device(i) + { + printf("sum: %d, device: %d\n", sum, i); + } + } + + return errors; +} + +int main() { + int errors = 0; + OMPVV_TEST_OFFLOADING; + + if(test_exit_code == OMPVV_SKIPPED_EXIT_CODE) + { OMPVV_REPORT_AND_RETURN(test_exit_code) } + + OMPVV_TEST_AND_SET(errors, test_declare_target_local() != 0); + OMPVV_REPORT_AND_RETURN(errors); +} From 2187c887983a5e97f467c8df89785d97703ffae1 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 9 Oct 2025 10:12:53 -0700 Subject: [PATCH 02/19] Adding new changes --- ... => test_declare_target_directive_local.c} | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) rename tests/6.0/declare_target/{test_declare_target_local.c => test_declare_target_directive_local.c} (59%) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c similarity index 59% rename from tests/6.0/declare_target/test_declare_target_local.c rename to tests/6.0/declare_target/test_declare_target_directive_local.c index 06613f389..a0858faf3 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -1,4 +1,5 @@ -//--------------- test_declare_target_local.c -----------------------------------------// +//--------------- test_declare_target_local.c +//-----------------------------------------// // OpenMP API Version 6.0 November 2024 ///////////// // Pg. 902, line 4 @@ -23,65 +24,66 @@ // OMPVV_TEST_AND_SET(*errors, var != 1); // return; // } - int sum; - int x[100]; +int sum; +int x[N]; - #pragma omp declare_target local(sum, x) - #pragma omp begin declare_target - void init_x(int dev_id) { - for (int j = 0; j < 100; ++j) { - x[j] = j + dev_id; - } +#pragma omp declare_target to(sum, x) // local(sum, x) +#pragma omp begin declare_target +void init_x(int dev_id) { + for (int j = 0; j < N; ++j) { + x[j] = j + dev_id; } - void foo(void) { - int i; - #pragma omp for reduction(+:sum) - for (i = 0; i < 100; i++) { - sum += x[i]; - } +} +void foo(void) { + int i; +#pragma omp for reduction(+ : sum) + for (i = 0; i < N; i++) { + sum += x[i]; } - #pragma omp end declare target - +} +#pragma omp end declare target int test_declare_target_local() { int errors = 0; int TotGpus = omp_get_num_devices(); - OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were found. \n This test will be skipped.\n"); + OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were " + "found. \n This test will be skipped.\n"); if (TotGpus < 1) { return OMPVV_SKIPPED_EXIT_CODE; } - for (int i = 0; i < ndev; i++) { - #pragma omp target device(i) - { + for (int i = 0; i < TotGpus; i++) { +#pragma omp target device(i) + { init_x(i); sum = 0; - } + } } - for (int i = 0; i < ndev; i++) { - #pragma omp target parallel device(i) nowait - foo(); + for (int i = 0; i < TotGpus; i++) { +#pragma omp target parallel device(i) nowait + foo(); } - #pragma omp taskwait +#pragma omp taskwait - for (int i = 0; i < ndev; i++) { - #pragma omp target device(i) - { + for (int i = 0; i < TotGpus; i++) { +#pragma omp target device(i) + { printf("sum: %d, device: %d\n", sum, i); - } + } } return errors; } int main() { - int errors = 0; + int errors = 0, test_exit_code = 0; OMPVV_TEST_OFFLOADING; - if(test_exit_code == OMPVV_SKIPPED_EXIT_CODE) - { OMPVV_REPORT_AND_RETURN(test_exit_code) } + if (test_exit_code == OMPVV_SKIPPED_EXIT_CODE) { + OMPVV_REPORT_AND_RETURN(test_exit_code) + } OMPVV_TEST_AND_SET(errors, test_declare_target_local() != 0); OMPVV_REPORT_AND_RETURN(errors); From 8de5952149e989abf5c1ac9c20d9a574ec8b3599 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 9 Oct 2025 10:17:48 -0700 Subject: [PATCH 03/19] Adding checking --- .../test_declare_target_directive_local.c | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index a0858faf3..4576d6fa3 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -1,5 +1,4 @@ -//--------------- test_declare_target_local.c -//-----------------------------------------// +//--------------- test_declare_target_local.c -----------------------------------------// // OpenMP API Version 6.0 November 2024 ///////////// // Pg. 902, line 4 @@ -24,55 +23,58 @@ // OMPVV_TEST_AND_SET(*errors, var != 1); // return; // } -int sum; -int x[N]; + int sum; + int x[N]; -#pragma omp declare_target to(sum, x) // local(sum, x) -#pragma omp begin declare_target -void init_x(int dev_id) { - for (int j = 0; j < N; ++j) { - x[j] = j + dev_id; + #pragma omp declare_target to(sum, x)//local(sum, x) + #pragma omp begin declare_target + void init_x(int dev_id) { + for (int j = 0; j < N; ++j) { + x[j] = j + dev_id; + } } -} -void foo(void) { - int i; -#pragma omp for reduction(+ : sum) - for (i = 0; i < N; i++) { - sum += x[i]; + void foo(void) { + int i; + #pragma omp for reduction(+:sum) + for (i = 0; i < N; i++) { + sum += x[i]; + } } -} -#pragma omp end declare target + #pragma omp end declare target + int test_declare_target_local() { int errors = 0; int TotGpus = omp_get_num_devices(); - OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were " - "found. \n This test will be skipped.\n"); + OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were found. \n This test will be skipped.\n"); if (TotGpus < 1) { return OMPVV_SKIPPED_EXIT_CODE; } for (int i = 0; i < TotGpus; i++) { -#pragma omp target device(i) - { + #pragma omp target device(i) + { init_x(i); sum = 0; - } + } } for (int i = 0; i < TotGpus; i++) { -#pragma omp target parallel device(i) nowait - foo(); + #pragma omp target parallel device(i) nowait + foo(); } -#pragma omp taskwait + #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { -#pragma omp target device(i) - { - printf("sum: %d, device: %d\n", sum, i); - } + #pragma omp target map(tofrom: errors) device(i) + { + + if ((N)(N-1)/2 + (N)*i != sum) + ++errors; + } } + OMPVV_TEST_AND_SET(errors, errors != 0); return errors; } @@ -81,9 +83,8 @@ int main() { int errors = 0, test_exit_code = 0; OMPVV_TEST_OFFLOADING; - if (test_exit_code == OMPVV_SKIPPED_EXIT_CODE) { - OMPVV_REPORT_AND_RETURN(test_exit_code) - } + if(test_exit_code == OMPVV_SKIPPED_EXIT_CODE) + { OMPVV_REPORT_AND_RETURN(test_exit_code) } OMPVV_TEST_AND_SET(errors, test_declare_target_local() != 0); OMPVV_REPORT_AND_RETURN(errors); From 1ed43229399501bb46923ef9b47e27851b476558 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 9 Oct 2025 10:18:35 -0700 Subject: [PATCH 04/19] Adding checking --- tests/6.0/declare_target/test_declare_target_directive_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index 4576d6fa3..aa0374c76 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -70,7 +70,7 @@ int test_declare_target_local() { #pragma omp target map(tofrom: errors) device(i) { - if ((N)(N-1)/2 + (N)*i != sum) + if ((N)*(N-1)/2 + (N)*i != sum) ++errors; } } From 6a360c7d7df10112383706cd9651a443412f43f4 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 16 Oct 2025 10:37:53 -0700 Subject: [PATCH 05/19] Adding the target directive test --- .../test_declare_target_directive_local.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index aa0374c76..16cfa4349 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -1,4 +1,4 @@ -//--------------- test_declare_target_local.c -----------------------------------------// +//--------------- test_declare_target_directive_local.c -------------------------------// // OpenMP API Version 6.0 November 2024 ///////////// // Pg. 902, line 4 @@ -53,7 +53,7 @@ int test_declare_target_local() { } for (int i = 0; i < TotGpus; i++) { - #pragma omp target device(i) + #pragma omp target device(i) //map(tofrom: sum) { init_x(i); sum = 0; @@ -61,18 +61,28 @@ int test_declare_target_local() { } for (int i = 0; i < TotGpus; i++) { - #pragma omp target parallel device(i) nowait + #pragma omp target parallel device(i) nowait//parallel device(i) nowait //map(tofrom: sum) + { foo(); + } } #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { - #pragma omp target map(tofrom: errors) device(i) + #pragma omp target map(tofrom: errors) device(i) //map(tofrom: sum) { + //printf("sum: %d, expected: %d\n", sum, (N)*(N-1)/2 + (N)*i); - if ((N)*(N-1)/2 + (N)*i != sum) + if ((N)*(N-1)/2 + (N)*i != sum){ ++errors; } + /* + for (int j=0; j < N; ++j){ + printf("index %d, value %d\n", j, x[j]); + } + */ + } + } OMPVV_TEST_AND_SET(errors, errors != 0); From 6a7210c2b53aa5fba2f44b94ffc0dc9e70bec271 Mon Sep 17 00:00:00 2001 From: Swaroop Pophale Date: Thu, 16 Oct 2025 14:12:39 -0400 Subject: [PATCH 06/19] Update and rename test_declare_target_directive_local.c to test_declare_target_local.c --- ...are_target_directive_local.c => test_declare_target_local.c} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/6.0/declare_target/{test_declare_target_directive_local.c => test_declare_target_local.c} (96%) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_local.c similarity index 96% rename from tests/6.0/declare_target/test_declare_target_directive_local.c rename to tests/6.0/declare_target/test_declare_target_local.c index 16cfa4349..3fa1f9430 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -1,4 +1,4 @@ -//--------------- test_declare_target_directive_local.c -------------------------------// +//--------------- test_declare_target_local.c -------------------------------// // OpenMP API Version 6.0 November 2024 ///////////// // Pg. 902, line 4 From 5b86436f71fefe402af4da361117d3d7583eac7b Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:24:13 -0400 Subject: [PATCH 07/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index 3fa1f9430..7986f54dd 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -3,7 +3,7 @@ ///////////// // Pg. 902, line 4 // *********** -// DIRECTIVE:target +// DIRECTIVE: declare_target // CLAUSE:data // The target_data directive is being used in three scenaries of various task // configurations for the same functional task. Because target_data is a From 84ef3a8bd9eb38b2b37d32bd4d8726d42805089a Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:24:22 -0400 Subject: [PATCH 08/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index 7986f54dd..c85987dd7 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -4,7 +4,7 @@ // Pg. 902, line 4 // *********** // DIRECTIVE: declare_target -// CLAUSE:data +// CLAUSE: local // The target_data directive is being used in three scenaries of various task // configurations for the same functional task. Because target_data is a // task-generating composite construct, it will have expected effects that are From 39e31a1dc4b9f3d2c50e80dff0237b9e6aa92de2 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:24:36 -0400 Subject: [PATCH 09/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index c85987dd7..d1dedb5da 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -52,6 +52,7 @@ int test_declare_target_local() { return OMPVV_SKIPPED_EXIT_CODE; } +int errors_arr[TotGpus] = {0}; for (int i = 0; i < TotGpus; i++) { #pragma omp target device(i) //map(tofrom: sum) { From 00eaa0213da9507cf3857163a054785d65e4c886 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:24:44 -0400 Subject: [PATCH 10/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index d1dedb5da..b6a37a782 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -56,8 +56,8 @@ int errors_arr[TotGpus] = {0}; for (int i = 0; i < TotGpus; i++) { #pragma omp target device(i) //map(tofrom: sum) { - init_x(i); - sum = 0; + init_x(i); + sum = 0; } } From 57e3185803d963c462b7254dc25a24d0d33b8e80 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:24:57 -0400 Subject: [PATCH 11/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index b6a37a782..eb7c7c885 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -62,7 +62,7 @@ int errors_arr[TotGpus] = {0}; } for (int i = 0; i < TotGpus; i++) { - #pragma omp target parallel device(i) nowait//parallel device(i) nowait //map(tofrom: sum) + #pragma omp target parallel device(i) nowait //map(tofrom: sum) { foo(); } From ed81eb1b18b5d897b46c461ce8bbc7594b0a2c93 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:25:05 -0400 Subject: [PATCH 12/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index eb7c7c885..fc2856972 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -70,7 +70,7 @@ int errors_arr[TotGpus] = {0}; #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { - #pragma omp target map(tofrom: errors) device(i) //map(tofrom: sum) + #pragma omp target map(tofrom: errors_arr) device(i) //map(tofrom: sum) { //printf("sum: %d, expected: %d\n", sum, (N)*(N-1)/2 + (N)*i); From 49db4e24710fc82076c97e18cd572d3c9e4e9461 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:25:14 -0400 Subject: [PATCH 13/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index fc2856972..0b02b4a25 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -75,7 +75,7 @@ int errors_arr[TotGpus] = {0}; //printf("sum: %d, expected: %d\n", sum, (N)*(N-1)/2 + (N)*i); if ((N)*(N-1)/2 + (N)*i != sum){ - ++errors; + ++errors_arr[i]; } /* for (int j=0; j < N; ++j){ From c39ca32435b13f6e7dfeacb88226c815ae7f4073 Mon Sep 17 00:00:00 2001 From: Andrew Kallai <73764771+andrewkallai@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:25:23 -0400 Subject: [PATCH 14/19] Update tests/6.0/declare_target/test_declare_target_local.c Co-authored-by: Swaroop Pophale --- tests/6.0/declare_target/test_declare_target_local.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_local.c index 0b02b4a25..f8ed1ad79 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_local.c @@ -85,6 +85,9 @@ int errors_arr[TotGpus] = {0}; } } + for (int i = 0; i < TotGpus; i++) { + errors += errors_arr[i]; + } OMPVV_TEST_AND_SET(errors, errors != 0); return errors; From 86c2119dfd16352e8ed3c85452ef05d6cdbf64a5 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 23 Oct 2025 10:56:00 -0700 Subject: [PATCH 15/19] Adding changes --- ... => test_declare_target_directive_local.c} | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 deletions(-) rename tests/6.0/declare_target/{test_declare_target_local.c => test_declare_target_directive_local.c} (53%) diff --git a/tests/6.0/declare_target/test_declare_target_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c similarity index 53% rename from tests/6.0/declare_target/test_declare_target_local.c rename to tests/6.0/declare_target/test_declare_target_directive_local.c index f8ed1ad79..c46371846 100644 --- a/tests/6.0/declare_target/test_declare_target_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -17,73 +17,66 @@ #define N 100 -// int work_function(int var) { return var + 1; } -// void check_function(int var, int *errors) { -// OMPVV_ERROR_IF(var != 1, "Expected %i, received %i", 1, var); -// OMPVV_TEST_AND_SET(*errors, var != 1); -// return; -// } - int sum; - int x[N]; +int sum; +int x[N]; - #pragma omp declare_target to(sum, x)//local(sum, x) - #pragma omp begin declare_target - void init_x(int dev_id) { - for (int j = 0; j < N; ++j) { - x[j] = j + dev_id; - } +#pragma omp declare_target to(sum, x) // local(sum, x) +#pragma omp begin declare_target +// void init_x(int dev_id) { +// for (int j = 0; j < N; ++j) { +// x[j] = j + dev_id; +// } +// } +void foo(int dev_id) { + int i; + for (int j = 0; j < N; ++j) { + x[j] = j + dev_id; } - void foo(void) { - int i; - #pragma omp for reduction(+:sum) - for (i = 0; i < N; i++) { - sum += x[i]; - } +#pragma omp for reduction(+ : sum) + for (i = 0; i < N; i++) { + sum += x[i]; } - #pragma omp end declare target - +} +#pragma omp end declare target int test_declare_target_local() { int errors = 0; int TotGpus = omp_get_num_devices(); - OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were found. \n This test will be skipped.\n"); + OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were " + "found. \n This test will be skipped.\n"); if (TotGpus < 1) { return OMPVV_SKIPPED_EXIT_CODE; } + int errors_arr[TotGpus]; + int sum_array[TotGpus]; -int errors_arr[TotGpus] = {0}; for (int i = 0; i < TotGpus; i++) { - #pragma omp target device(i) //map(tofrom: sum) - { - init_x(i); - sum = 0; - } + sum_array[i] = 0; + errors_arr[i] = 0; + #pragma omp target device(i) map(tofrom : sum_array) + { + // init_x(i); + // sum = 0; + sum_array[i] = 0; + } } for (int i = 0; i < TotGpus; i++) { - #pragma omp target parallel device(i) nowait //map(tofrom: sum) + #pragma omp target parallel device(i) nowait { - foo(); + foo(i); } } #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { - #pragma omp target map(tofrom: errors_arr) device(i) //map(tofrom: sum) - { - //printf("sum: %d, expected: %d\n", sum, (N)*(N-1)/2 + (N)*i); - - if ((N)*(N-1)/2 + (N)*i != sum){ + #pragma omp target map(tofrom : errors_arr) device(i) + { + if ((N) * (N - 1) / 2 + (N)*i != sum_array[i]) { ++errors_arr[i]; } - /* - for (int j=0; j < N; ++j){ - printf("index %d, value %d\n", j, x[j]); - } - */ - } - + } } for (int i = 0; i < TotGpus; i++) { errors += errors_arr[i]; @@ -97,8 +90,9 @@ int main() { int errors = 0, test_exit_code = 0; OMPVV_TEST_OFFLOADING; - if(test_exit_code == OMPVV_SKIPPED_EXIT_CODE) - { OMPVV_REPORT_AND_RETURN(test_exit_code) } + if (test_exit_code == OMPVV_SKIPPED_EXIT_CODE) { + OMPVV_REPORT_AND_RETURN(test_exit_code) + } OMPVV_TEST_AND_SET(errors, test_declare_target_local() != 0); OMPVV_REPORT_AND_RETURN(errors); From d2f06e63f9b291907806a3900a3abc48f18d0c4c Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Wed, 29 Oct 2025 18:20:24 -0700 Subject: [PATCH 16/19] Adding the changes for testing --- Makefile | 3 +- ompvv/ompvv.h | 23 ++++++++--- .../test_declare_target_directive_local.c | 40 ++++++++----------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index a215f088c..0aa4f3690 100644 --- a/Makefile +++ b/Makefile @@ -322,13 +322,12 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR) $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log)) \ && echo "PASS" > $(LOGTEMPFILE) || echo "FAIL" > $(LOGTEMPFILE)), \ $(if $(findstring _env_,$@), \ - $(call CHECK_OUTPUT, $(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) --env \ $(shell echo "$@" | sed -e 's@.*/@@' -e 's@test_\(.*\)_env_.*@\1@' | tr 'a-z' 'A-Z') \ $(shell echo "$@" | sed -e 's@.*/@@' -e 's@.*_env_\([^.]*\).*@\1@') \ $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log))) ), \ $(call CHECK_OUTPUT, $(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log))) ) \ - ) + )) -$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.run=.log))) -@$(if $(LOG), rm $(LOGTEMPFILE)) diff --git a/ompvv/ompvv.h b/ompvv/ompvv.h index 70f78df3b..1bf963934 100644 --- a/ompvv/ompvv.h +++ b/ompvv/ompvv.h @@ -80,12 +80,12 @@ _Pragma("omp target map (from: _ompvv_isOffloadingOn)") \ #define OMPVV_REPORT(err) { \ OMPVV_INFOMSG("The value of " #err " is %d.", err); \ if (_ompvv_isOffloadingOn == -1) \ - if (err == -667) \ + if (err == OMPVV_SKIPPED_EXIT_CODE) \ printf("[OMPVV_RESULT: %s] Test %s.\n", __FILENAME__, "skipped"); \ else \ printf("[OMPVV_RESULT: %s] Test %s.\n", __FILENAME__, ((err) == 0)? "passed":"failed"); \ else \ - if (err == -667) \ + if (err == OMPVV_SKIPPED_EXIT_CODE) \ printf("[OMPVV_RESULT: %s] Test %s on the %s.\n", __FILENAME__, "skipped", (_ompvv_isOffloadingOn)? "device" : "host"); \ else \ printf("[OMPVV_RESULT: %s] Test %s on the %s.\n", __FILENAME__, ((err) == 0)? "passed":"failed", (_ompvv_isOffloadingOn)? "device" : "host"); \ @@ -102,6 +102,15 @@ _Pragma("omp target map (from: _ompvv_isOffloadingOn)") \ OMPVV_RETURN(err); \ } +// Macro to check if it is a shared data environment +#define OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \ + int _ompvv_isSharedEnv = 0; \ + _ompvv_isOffloadingOn = 0; \ +_Pragma("omp target map (from: _ompvv_isOffloadingOn) map(to: _ompvv_isSharedEnv)") \ + { _ompvv_isOffloadingOn = !omp_is_initial_device(); \ + _ompvv_isSharedEnv = 1; \ + } + // Macro to check if it is a shared data environment #define OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \ int _ompvv_isSharedEnv = 0; \ @@ -124,6 +133,12 @@ _Pragma("omp target map (from: _ompvv_isOffloadingOn) map(to: _ompvv_isSharedEnv var2set = (_ompvv_isOffloadingOn && _ompvv_isSharedEnv == 1);\ } +// Macro for skipping a test +#define OMPVV_CHECK_TO_SKIP(condition) { \ + int SKIPPED_EXIT_CODE = OMPVV_SKIPPED_EXIT_CODE; \ + if (condition) {OMPVV_REPORT_AND_RETURN(SKIPPED_EXIT_CODE)}; \ + } + // Macros to provide thread and team nums if they are not specified #ifndef OMPVV_NUM_THREADS_DEVICE #define OMPVV_NUM_THREADS_DEVICE 8 @@ -141,10 +156,6 @@ _Pragma("omp target map (from: _ompvv_isOffloadingOn) map(to: _ompvv_isSharedEnv #define OMPVV_NUM_THREADS_HOST 8 #endif -#ifndef OMPVV_NUM_THREADS_HOST - #define OMPVV_NUM_THREADS_HOST 8 -#endif - #ifndef OMPVV_SKIPPED_EXIT_CODE #define OMPVV_SKIPPED_EXIT_CODE -667 #endif diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index c46371846..61c7076ef 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -1,15 +1,13 @@ -//--------------- test_declare_target_local.c -------------------------------// +//--------------- test_declare_target_directive_local.c--------------------------------// // OpenMP API Version 6.0 November 2024 -///////////// // Pg. 902, line 4 // *********** // DIRECTIVE: declare_target // CLAUSE: local -// The target_data directive is being used in three scenaries of various task -// configurations for the same functional task. Because target_data is a -// task-generating composite construct, it will have expected effects that are -// being tested in each scenario. If the work_function executes correctly, then -// the value of a should expectedly change to 1. +// The declare_target directive is used with the local clause to make data +// persist on multiple devices, each with their own copy of the referenced +// variables in the clause. If the values retrieved from each of the available +// devices add up to the expected amount, the test will pass. //-------------------------------------------------------------------------------------// #include "ompvv.h" @@ -32,7 +30,7 @@ void foo(int dev_id) { for (int j = 0; j < N; ++j) { x[j] = j + dev_id; } -#pragma omp for reduction(+ : sum) + #pragma omp for reduction(+ : sum) for (i = 0; i < N; i++) { sum += x[i]; } @@ -41,25 +39,19 @@ void foo(int dev_id) { int test_declare_target_local() { int errors = 0; - int TotGpus = omp_get_num_devices(); - OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were " - "found. \n This test will be skipped.\n"); - if (TotGpus < 1) { - return OMPVV_SKIPPED_EXIT_CODE; - } int errors_arr[TotGpus]; int sum_array[TotGpus]; for (int i = 0; i < TotGpus; i++) { sum_array[i] = 0; errors_arr[i] = 0; - #pragma omp target device(i) map(tofrom : sum_array) - { - // init_x(i); - // sum = 0; - sum_array[i] = 0; - } + // #pragma omp target device(i) map(tofrom : sum_array) + // { + // // init_x(i); + // // sum = 0; + // sum_array[i] = 0; + // } } for (int i = 0; i < TotGpus; i++) { @@ -88,12 +80,12 @@ int test_declare_target_local() { int main() { int errors = 0, test_exit_code = 0; + int TotGpus = omp_get_num_devices(); + OMPVV_WARNING_IF(TotGpus < 1, "Test requires non-host devices, but none were " + "found. \n This test will be skipped.\n"); + OMPVV_CHECK_TO_SKIP(TotGpus < 1) OMPVV_TEST_OFFLOADING; - if (test_exit_code == OMPVV_SKIPPED_EXIT_CODE) { - OMPVV_REPORT_AND_RETURN(test_exit_code) - } - OMPVV_TEST_AND_SET(errors, test_declare_target_local() != 0); OMPVV_REPORT_AND_RETURN(errors); } From 618a7c66ed4b7e2a5b704a1505bca358bf81f0f5 Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Thu, 30 Oct 2025 09:53:07 -0700 Subject: [PATCH 17/19] More changes --- .../test_declare_target_directive_local.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index 61c7076ef..00e711e7e 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -17,8 +17,9 @@ int sum; int x[N]; +int sum_array[10]; -#pragma omp declare_target to(sum, x) // local(sum, x) +#pragma omp declare_target to(sum, x, sum_array) // local(sum, x) #pragma omp begin declare_target // void init_x(int dev_id) { // for (int j = 0; j < N; ++j) { @@ -32,7 +33,8 @@ void foo(int dev_id) { } #pragma omp for reduction(+ : sum) for (i = 0; i < N; i++) { - sum += x[i]; + //sum += x[i]; + sum_array[dev_id] += x[i]; } } #pragma omp end declare target @@ -41,7 +43,7 @@ int test_declare_target_local() { int errors = 0; int TotGpus = omp_get_num_devices(); int errors_arr[TotGpus]; - int sum_array[TotGpus]; + //int sum_array[TotGpus]; for (int i = 0; i < TotGpus; i++) { sum_array[i] = 0; @@ -63,8 +65,9 @@ int test_declare_target_local() { #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { - #pragma omp target map(tofrom : errors_arr) device(i) + #pragma omp target map(tofrom : errors_arr, sum_array) device(i) { + printf("%d\n", sum_array[i]); if ((N) * (N - 1) / 2 + (N)*i != sum_array[i]) { ++errors_arr[i]; } From 0e2b1c014ba43e68caf710327dd15c9d00442e4f Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Mon, 3 Nov 2025 14:05:35 -0800 Subject: [PATCH 18/19] Adding the updated test with complete changes --- .../test_declare_target_directive_local.c | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/tests/6.0/declare_target/test_declare_target_directive_local.c b/tests/6.0/declare_target/test_declare_target_directive_local.c index 00e711e7e..210077322 100644 --- a/tests/6.0/declare_target/test_declare_target_directive_local.c +++ b/tests/6.0/declare_target/test_declare_target_directive_local.c @@ -1,4 +1,4 @@ -//--------------- test_declare_target_directive_local.c--------------------------------// +//----------------test_declare_target_directive_local.c--------------------------------// // OpenMP API Version 6.0 November 2024 // Pg. 902, line 4 // *********** @@ -17,24 +17,19 @@ int sum; int x[N]; -int sum_array[10]; -#pragma omp declare_target to(sum, x, sum_array) // local(sum, x) +#pragma omp declare_target local(sum, x) #pragma omp begin declare_target -// void init_x(int dev_id) { -// for (int j = 0; j < N; ++j) { -// x[j] = j + dev_id; -// } -// } -void foo(int dev_id) { - int i; +void init_x(int dev_id) { for (int j = 0; j < N; ++j) { x[j] = j + dev_id; } +} + +void foo(void) { #pragma omp for reduction(+ : sum) - for (i = 0; i < N; i++) { - //sum += x[i]; - sum_array[dev_id] += x[i]; + for (int i = 0; i < N; i++) { + sum += x[i]; } } #pragma omp end declare target @@ -43,32 +38,26 @@ int test_declare_target_local() { int errors = 0; int TotGpus = omp_get_num_devices(); int errors_arr[TotGpus]; - //int sum_array[TotGpus]; for (int i = 0; i < TotGpus; i++) { - sum_array[i] = 0; errors_arr[i] = 0; - // #pragma omp target device(i) map(tofrom : sum_array) - // { - // // init_x(i); - // // sum = 0; - // sum_array[i] = 0; - // } + { + init_x(i); + sum = 0; + } } - for (int i = 0; i < TotGpus; i++) { - #pragma omp target parallel device(i) nowait + #pragma omp target parallel device(i) { - foo(i); + foo(); } } #pragma omp taskwait for (int i = 0; i < TotGpus; i++) { - #pragma omp target map(tofrom : errors_arr, sum_array) device(i) + #pragma omp target map(tofrom : errors_arr[i]) device(i) { - printf("%d\n", sum_array[i]); - if ((N) * (N - 1) / 2 + (N)*i != sum_array[i]) { + if ((N) * (N - 1) / 2 + (N)*i != sum) { ++errors_arr[i]; } } From 73aafb402b346ec21ed73846fb616bd70bd56a9e Mon Sep 17 00:00:00 2001 From: Andrew Kallai Date: Mon, 3 Nov 2025 14:11:47 -0800 Subject: [PATCH 19/19] Removing extra macro definition. --- ompvv/ompvv.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ompvv/ompvv.h b/ompvv/ompvv.h index 1bf963934..cc8c37ab7 100644 --- a/ompvv/ompvv.h +++ b/ompvv/ompvv.h @@ -102,15 +102,6 @@ _Pragma("omp target map (from: _ompvv_isOffloadingOn)") \ OMPVV_RETURN(err); \ } -// Macro to check if it is a shared data environment -#define OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \ - int _ompvv_isSharedEnv = 0; \ - _ompvv_isOffloadingOn = 0; \ -_Pragma("omp target map (from: _ompvv_isOffloadingOn) map(to: _ompvv_isSharedEnv)") \ - { _ompvv_isOffloadingOn = !omp_is_initial_device(); \ - _ompvv_isSharedEnv = 1; \ - } - // Macro to check if it is a shared data environment #define OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \ int _ompvv_isSharedEnv = 0; \