From 5672aff09398164956f7668c82c35486cd947916 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 24 Apr 2025 00:38:45 +0200 Subject: [PATCH] xt-declare-target-ctors: Update for GCC It's not clear from the revision log what compiler the xt-declare-target-ctors test has been written against, in particular, its 'xt-declare-target-ctors/expected' file. But it must've been a long time ago. Updating this for current GCC: 1. Like on the host, also for offloading: destructors run in reverse order of constructors. 2. Offloading is initialized (and with that, offloading constructors are run) upon encountering the first offloading construct (here: '#pragma omp target'), and offloading is shut down (and with that, offloading destructors are run) at the end of 'main', before destructing host objects. --- xt-declare-target-ctors/expected | 12 ++++++------ xt-declare-target-ctors/test.cpp | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/xt-declare-target-ctors/expected b/xt-declare-target-ctors/expected index ba19e20..4217163 100644 --- a/xt-declare-target-ctors/expected +++ b/xt-declare-target-ctors/expected @@ -10,6 +10,12 @@ CtorD: 123 Device CtorD: 123 Device CtorD: 123 Device Main: 123 Device +DtorE: 1860867 Device +DtorD: 1860867 Device +DtorD: 1860867 Device +DtorD: 1860867 Device +DtorC: 123 Device +DtorA: 5159780352 Device DtorW: 56 Host DtorE: 1860867 Host DtorD: 1860867 Host @@ -17,9 +23,3 @@ DtorD: 1860867 Host DtorD: 1860867 Host DtorC: 123 Host DtorA: 5159780352 Host -DtorA: 5159780352 Device -DtorC: 123 Device -DtorD: 1860867 Device -DtorD: 1860867 Device -DtorD: 1860867 Device -DtorE: 1860867 Device diff --git a/xt-declare-target-ctors/test.cpp b/xt-declare-target-ctors/test.cpp index 41ffd91..6f86d1e 100644 --- a/xt-declare-target-ctors/test.cpp +++ b/xt-declare-target-ctors/test.cpp @@ -22,17 +22,15 @@ struct NoOffloadCtorDtor { if (!offloading_disabled() || !RunDtor) return; - printf("DtorA: 5159780352 Device\n"); - printf("DtorC: 123 Device\n"); + printf("DtorE: 1860867 Device\n"); printf("DtorD: 1860867 Device\n"); printf("DtorD: 1860867 Device\n"); printf("DtorD: 1860867 Device\n"); - printf("DtorE: 1860867 Device\n"); + printf("DtorC: 123 Device\n"); + printf("DtorA: 5159780352 Device\n"); } }; -NoOffloadCtorDtor NC0(true); - #pragma omp declare target struct SSW { @@ -107,17 +105,20 @@ SSE se; SSW sw(56); -NoOffloadCtorDtor NC1(false); - int main(void) { bool OffloadDisabled = offloading_disabled(); + NoOffloadCtorDtor NC0(false); + #pragma omp target device(0) #pragma omp teams num_teams(1) thread_limit(1) #pragma omp parallel if(0) { printf("Main: %d %s\n",123, (omp_is_initial_device() && !OffloadDisabled) ? "Host" : "Device"); } + + NoOffloadCtorDtor NC1(true); + return 0; }