Software Archive
Read-only legacy content
17061 Discussions

Segfault when using scatter intrinsic

Tim_D_1
Beginner
748 Views

Hi, 

I have been trying to use the scatter intrinsic, but seem to be getting a segfault any time I use it. Here is a minimal example, I checked the compiler reference and seem to be passing correct arguments, can anyone enlighten me as to what I'm doing wrong? If I comment out the scatter, it runs fine, and if I extract and print the contents of _indices and _temp the correct values are there, but if I use scatter I get a segfault.

If data contains rgbargbargbargba the result should be that out contains rgbrgbrgbrgbaaaa.

[cpp]

#include <cstdio>
#ifdef __MIC__
#include "immintrin.h"
#endif

#define ALLOC alloc_if(1) free_if(0)
#define FREE alloc_if(0) free_if(1)
#define REUSE alloc_if(0) free_if(0)


#pragma offload_attribute(push, target(mic))
struct pixel{
    float r;
    float g;
    float b;
    float a;
};

void func(pixel* data)
{
#ifdef __MIC__

    __m512i _indices = _mm512_setzero_epi32();
    _indices = _mm512_set_epi32(15,11,10,9,14,8,7,6,13,5,4,3,12,2,1,0);

   

    float* out = (float*)_mm_malloc(16*sizeof(float), 64);
    __m512 _temp =_mm512_load_ps((void*)data);

    _mm512_i32scatter_ps((void*)out,_indices,_temp,1);

#endif
}

#pragma offload_attribute(pop)

int main(int argc, char* argv[])
{
    pixel* data = (pixel*)_mm_malloc(16*sizeof(pixel), 64);
    for(unsigned i = 0; i < 16; i++) {
        data.r = i;

        data.g = i;

        data.b = i; 

        data.a = i; 

    }

 #pragma offload_transfer target(mic:0) in(data : length(ARRSIZE) ALLOC)


#pragma offload target(mic:0) nocopy(data)
 {

    func(data);

 }


    return 0;
}

[/cpp]

0 Kudos
3 Replies
Tim_D_1
Beginner
748 Views

Sorry assume that for loop in main says "i < 4" not "i < 16" and the mm_malloc is 4 not 16, also ARRSIZE is 4, I mistyped and cannot seem to edit the post.

0 Kudos
robert-reed
Valued Contributor II
748 Views

What happens if you do this?

[cpp]

#pragma offload_transfer target(mic:0) in(data : length(ARRSIZE) ALLOC )

{

    func(data);

}

[/cpp]

Or this?

[cpp]

#pragma offload_transfer target(mic:0) in(data : length(ARRSIZE) ALLOC)

#pragma offload target(mic:0) in(data : length(0) REUSE )

{

    func(data);

}

[/cpp]

In the code sample provided in this thread, the offload line doesn't have a good linkage from the offload_transfer.  The compiler may be getting confused as to which "data" you mean.

0 Kudos
Tim_D_1
Beginner
748 Views

Hi Robert, thanks for the reply

I still recieve the segfault still with both methods you suggest. I am not sure I understand why it doesnt have good linkage - as far as I was aware from the documentation the nocopy is an acceptable method of referencing persistant memory across offloads?

In any case it does not affect the result...

0 Kudos
Reply