Skip to content

Scoping concern about outlining an OpenMP loop #149

@ouankou

Description

@ouankou

Moving the declaration of the loop control variable during the normalization of an OpenMP loop may cause a declaration issue because of scoping change. After some thinking and testing on REX, in my opinion, this probably won't be an issue. Given the following AXPY example:

int i = 10; // i(1), scope 1
#pragma omp target parallel for map(...)
  for (int i = 0; i < n; ++i) // i(2), scope 2
    y[i] += a * x[i];

In this case, two symbols i(1) and i(2) share the same name, but it's OK because they are in different scopes. To lower the directive, we move int i(2) out of the loop. It seems like a declaration conflict will happen. However, before doing that, we always outline first so that the OpenMP code will all go to another function. Thus, an intermediate status of lowering would be something like this:

__global__ void outlined_func(...) {
// waiting for loop normalization and transformation
  for (int i = 0; i < n; ++i) // i(2)
    y[i] += a * x[i];
}

int i = 10; // i(1), scope 1
{
  // some statements for GPU kernel call.
}

In this case, i(2) is not even part of the outlined function parameter because its declaration is always inside the outlining region.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions