I am going to parallelize a program, so I replace a two-demensions array with a one-array like this(simplified):
; for (int i = 0; i < N; i++) ptr = new float ; cblas_sgemm(......, ptr, x).
float *p = new float[N * M]; for (int i = 0; i < N; i++) ptr = p + i * M; #pragma offload target(mic) inout(p:length(N * M)) cblas_sgemm(....., p + i * M, x);
Then I got offload error: allocation overlaps with existing allocation". Maybe the array is a little big(~500M). I found that an Intel expert replied in other topic:
The larger size and offload allocation overlap error probably relate to exhausting available resources on the coprocessor.
But I tested a small program and proved that this size is OK, it didn't not caused problem...So I felt very confused about the error.Please give me some advises, thanks in advance!
The second block of code above, where you flatten the array of pointers into a single float array and then offload that array, appears to be OK. No obvious problem with it.
The message indicates that there is another allocation occurring through some other offload in the program, where one of the pointer values lies within the range of the large array you offloaded using the second block of code.
Look at other offloads and see if you can spot it. If you don't find the other allocation, there are some debugging aids you could use, but try examining your source code first.
Thank you all, Jim and Rajiv!
But I still believe that my issue is caused by "exhausting available resources on the coprocessor." Because after rewriting the code I use less memory to implement the transform of two-dimensions array, aka, allocate each dimension suitable size rather than give all of them the max size of dimensions. It works!
Thanks for your patience again:)
That may be so, but was that the source of the problem?
I had a case the other day in a modeling program that had a choice of using a circular or rectangular footprint. The C++ code that called the Fortran code that contained the offload, used a template to declare multi-dimensional arrays in C++ that were to be used within Fortran, and passed as arguments in a subroutine call via offload. The issue presented itself when the "unused" footprint data had a dimension of (N, MwithValueOfZero). This resulted in a report of an overlap issue.
In your case, it may be related to heap allocation failure. But this would happen where allocations were made on the MIC as part of the offload. You may also want to assert that the data being passed into the MIC does not overlap as well as assert that you are not passing in or out null data (not null pointers, rather zero sized).