Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Update To From lvalue Pointer #824

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions tests/5.0/target/test_target_update_to_from_lvalue_ptr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===------ test_target_update_to_from_map_lvalue_pointer.cpp ----------------===//
//
// OpenMP API Version 5.0 Nov 2018
//
// This test evaluates the target update directive using to and from clauses,
// supporting various lvalue expressions, such as dereferenced pointers.
// Additionally, it examines the map clause and its handling of lvalue expressions
//===------------------------------------------------------------------------===//

#include <omp.h>
#include <iostream>
#include "ompvv.h"

int test_target_update() {
int errors = 0;
int before_value;
int after_value;
int* host_pointer = new int;
*host_pointer = -1;

#pragma omp target enter data map(to: *host_pointer)

//Before should be set to -1
#pragma omp target map(from: before_value)
{
before_value = *host_pointer;
}

//Host_pointer should now be 1
*host_pointer = 1;
// Copy data from the host variable to the device variable using a dereferenced pointer
#pragma omp target update to(*host_pointer)

#pragma omp target map(from: after_value)
{
after_value = *host_pointer;
*host_pointer = 2;
}

//Update host_pointer to 2
#pragma omp target update from(*host_pointer)

// Verify the results
if (*host_pointer != 2) {
errors++;
}
if (before_value != -1){
errors++;
}
if (after_value != 1){
errors++;
}

#pragma omp target exit data map(from: *host_pointer)
delete host_pointer;

OMPVV_TEST_AND_SET(errors, errors != 0);
return errors;
}

int main() {
OMPVV_TEST_OFFLOADING;
int errors = 0;

OMPVV_TEST_AND_SET_VERBOSE(errors, test_target_update() != 0);

OMPVV_REPORT_AND_RETURN(errors);
}