-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Target Update To From lvalue Pointer (#824)
* Target Update To From LValue Pointer * Added Exit Data * fixed description to add map clause --------- Co-authored-by: Raymundo Escobar <[email protected]>
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
tests/5.0/target/test_target_update_to_from_lvalue_ptr.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|