Skip to content

[smoke-fort-dev] Add test for omp_get_mapped_ptr#2180

Merged
DominikAdamski merged 2 commits intoROCm:aomp-devfrom
DominikAdamski:get_mapped_ptr_test_case
Apr 27, 2026
Merged

[smoke-fort-dev] Add test for omp_get_mapped_ptr#2180
DominikAdamski merged 2 commits intoROCm:aomp-devfrom
DominikAdamski:get_mapped_ptr_test_case

Conversation

@DominikAdamski
Copy link
Copy Markdown
Contributor

@DominikAdamski DominikAdamski commented Apr 21, 2026

Motivation

Add test for omp_get_mapped_ptr.

Technical Details

The test case with omp_get_mapped_ptr should
generate the same output as the test case with use_device_addr clause.

omp_get_mapped ptr does not work as expected
on MI210.

The test case with omp_get_mapped_ptr should
generate the same output as the test case with use_device_addr
clause.
@DominikAdamski DominikAdamski force-pushed the get_mapped_ptr_test_case branch from 77d4452 to 126d2bc Compare April 23, 2026 12:46
#include <hip/hip_runtime.h>
#include <stdlib.h>

__global__ void bar_kernel(int *x, int *y, int *z)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd pass n and not use 1000 as a fixed number. Does not much change the test, but makes it easier to use a bigger working set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{
int i = blockIdx.x * blockDim.x + threadIdx.x;

if (i < 1000) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/1000/n/ :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


extern "C" {

void bar_GPU(int *x, int *y, int *z)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add n as a parameter to the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


void bar_GPU(int *x, int *y, int *z)
{
hipLaunchKernelGGL(bar_kernel, dim3(32), dim3(32), 0, 0, x, y, z);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested the test on my machine, but hipLaunchKernelGGL launches the kernel asynchronously. So, you need a hipDeviceSynchronize() after it. Otherwise, you might (and you likely are) returning back to Fortran too early and the !$omp end target data deletes the device buffer to early before the kernel is complete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. I added synchronization and I don't see data race.

Comment thread test/smoke-fort-dev/use-omp-get-mapped-ptr/main.f90
Copy link
Copy Markdown
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DominikAdamski DominikAdamski changed the title [smoke-fort-fail] Add test for omp_get_mapped_ptr [smoke-fort-dev] Add test for omp_get_mapped_ptr Apr 27, 2026
@DominikAdamski DominikAdamski merged commit ea5887c into ROCm:aomp-dev Apr 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants