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

Handling declare target #111

Open
yanyh15 opened this issue Oct 18, 2021 · 1 comment
Open

Handling declare target #111

yanyh15 opened this issue Oct 18, 2021 · 1 comment
Assignees

Comments

@yanyh15
Copy link
Member

yanyh15 commented Oct 18, 2021

The declare directive, e.g. declare target, impacts the lowering of the code in the later stage, thus needs to handled at the very beginning before the lowering.

Declare target indicates to put device for a symbol (variable or function) to make it as a device-side-only symbol. Thus the symbol should not be applied default mapping when the compiler analyze symbols to apply default mapping. To do this, all the symbols of the declare target need to be inserted in the symbol table as global first for the file that will be produced by lowering for the kernel.

@ouankou
Copy link
Contributor

ouankou commented May 2, 2023

declare target creates two copies of declared symbols.
Given the following code:

#include <stdio.h>

#pragma omp declare target
int x = 100;
#pragma omp end declare target

int main(int argc, char **argv) {

  printf("On host: x = %d\n", x); // output: x = 100

#pragma omp target
  {
    x = 200;
    printf("On device: x = %d\n", x); // output: x = 200
  }

  printf("On host: x = %d\n", x); // output: x = 100
  x = 300;

#pragma omp target
  { printf("On device: x = %d\n", x); } // output: x = 200

  return 0;
}

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

No branches or pull requests

3 participants