Check if a pointer-based array had been offloaded to the coprocessor

Check if a pointer-based array had been offloaded to the coprocessor

Hello,

I would like to know if there is a programmatic way to check whether an array located at a certain host address has been uploaded to the coprocessor and retained there using "free_if(0)". If possible, I would also like to query the size of that array. This should be doable, because the word in the street is that the offload RTL stores pointers to all offloaded arrays in some table.

If this functionality is not available, I think there is a good case for enabling it. Consider the following generic task: I am implementing a library function that performs offloaded calculations on the coprocessor. For good performance, it is critical that this function uses data persistence with "free_if(0)". The interface to the function is "void MyFunction(const int size, const float* myData, float* myOutput, const int mode)". Array "myData" of length "size" can potentially be retained on the coprocessor and re-used in subsequent calls to this function. The argument "mode" controls what the function must with "myData": offload the array to the coprocessor and leave it there, or re-use it on the coprocessor, or remove it from the coprocessor:

void MyFunction(const float* size, const float* myData, float* myOutput, int mode) {
  int allocFlag, freeFlag, offloadLength;
  if (mode > 0) {
    // Offload data to coprocessor and retain it there
    offloadLength = size;
    allocFlag = 1;
    freeFlag = 0;
  } else if (mode < 0) {
    // Re-use data already on coprocessor
    offloadLength = 0;
    allocFlag = 0;
    freeFlag = 0; 
  } else if (mode == 0) {
    // Remove data from coprocessor
    offloadLength = 0;
    allocFlag = 0;
    freeFlag = 1;
  }

#pragma offload target(mic) in(myData : length(offloadLength) alloc_if(allocFlag) free_if(freeFlag))
  {
    // ... do some work
  }
}

Here is the problem: if the user calls this library function and erroneously tells it to re-use array "myData" before it was offloaded, it will result in a runtime error, and the application will crash. I don't like this behavior. Instead of a runtime error, I would like to return an error status and allow the user to handle it. However, in order for this to work, I need some way to query whether an array referenced to by a certain pointer has been offloaded or not.

Of course, could use a static list in the function to hold the values of all arrays offloaded by this function. However, there is no guarantee that the user will perform allocation/deallocation of data on the coprocessor using only my function. That is why I think that querying the offload RTL is the way to go here.

Thanks in advance for any advice!

Andrey

publicaciones de 4 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Hi Andrey, 

Looking into this. Will get back to you soon with an answer. 

-Sumedh

Hi Andrey, 

We currently don’t have anything in the compiler for querying if the memory is already allocated on the coprocessor. However we will be implementing OpenMP 4.0 RC2 support who’s behavior is that if memory is already allocated then it does nothing else it allocates memory and updates data.

-Sumedh

Thanks, Sumedh! That's good intel (pun intended).

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya