Skip to content

[libomptarget] omp_get_default_device doesn't returning host device in the case of OMP_TARGET_OFFLOAD=disabled #144786

@ye-luo

Description

@ye-luo
Contributor

spec 6.0 says
Support for the disabled value is implementation defined. If an implementation supports it, the behavior is as if the only device is the host device.

Based on the above spec, when the environment variable OMP_TARGET_OFFLOAD=disabled is set, the expected return from omp_get_default_device should agree with omp_get_initial_device which reports the host device. This is not the current case

reproducer.cpp

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

int main(){
        std::cout << "num_of_device = " << omp_get_num_devices() << std::endl;
        std::cout << "initial_device = " << omp_get_initial_device() << std::endl;
        std::cout << "default_device = " << omp_get_default_device() << std::endl;

        int a[8];
#pragma omp target enter data map(to: a[:8])
        int* b = (int *)omp_get_mapped_ptr(a, omp_get_default_device());

        std::cout << "a_ptr = " << a << " b_ptr = " << b << std::endl;
}

compile and run

yeluo@epyc-server:~/temp$ clang++ -fopenmp --offload-arch=gfx906 main.cpp
yeluo@epyc-server:~/temp$ OMP_TARGET_OFFLOAD=disabled ./a.out 
num_of_device = 1
initial_device = 1
default_device = 0
a_ptr = 0x7ffdd63e4440 b_ptr = 0
yeluo@epyc-server:~/temp$ OMP_TARGET_OFFLOAD=mandatory ./a.out 
num_of_device = 1
initial_device = 1
default_device = 0
a_ptr = 0x7fff3355e020 b_ptr = 0x721958200000

default_device doesn't behave as expected.

Activity

ye-luo

ye-luo commented on Jun 30, 2025

@ye-luo
ContributorAuthor

021a1f6 already took care of this issue. I'm going to submit a test to safe guard working cases.

llvmbot

llvmbot commented on Jun 30, 2025

@llvmbot
Member

@llvm/issue-subscribers-offload

Author: Ye Luo (ye-luo)

spec 6.0 says Support for the disabled value is implementation defined. If an implementation supports it, the behavior is as if the only device is the host device.

Based on the above spec, when the environment variable OMP_TARGET_OFFLOAD=disabled is set, the expected return from omp_get_default_device should agree with omp_get_initial_device which reports the host device. This is not the current case

reproducer.cpp

#include &lt;omp.h&gt;
#include &lt;iostream&gt;

int main(){
        std::cout &lt;&lt; "num_of_device = " &lt;&lt; omp_get_num_devices() &lt;&lt; std::endl;
        std::cout &lt;&lt; "initial_device = " &lt;&lt; omp_get_initial_device() &lt;&lt; std::endl;
        std::cout &lt;&lt; "default_device = " &lt;&lt; omp_get_default_device() &lt;&lt; std::endl;

        int a[8];
#pragma omp target enter data map(to: a[:8])
        int* b = (int *)omp_get_mapped_ptr(a, omp_get_default_device());

        std::cout &lt;&lt; "a_ptr = " &lt;&lt; a &lt;&lt; " b_ptr = " &lt;&lt; b &lt;&lt; std::endl;
}

compile and run

yeluo@<!-- -->epyc-server:~/temp$ clang++ -fopenmp --offload-arch=gfx906 main.cpp
yeluo@<!-- -->epyc-server:~/temp$ OMP_TARGET_OFFLOAD=disabled ./a.out 
num_of_device = 1
initial_device = 1
default_device = 0
a_ptr = 0x7ffdd63e4440 b_ptr = 0
yeluo@<!-- -->epyc-server:~/temp$ OMP_TARGET_OFFLOAD=mandatory ./a.out 
num_of_device = 1
initial_device = 1
default_device = 0
a_ptr = 0x7fff3355e020 b_ptr = 0x721958200000

default_device doesn't behave as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ye-luo@EugeneZelenko@llvmbot

      Issue actions

        [libomptarget] omp_get_default_device doesn't returning host device in the case of OMP_TARGET_OFFLOAD=disabled · Issue #144786 · llvm/llvm-project