Out values from coprocessor garbage

Out values from coprocessor garbage

#include <stdlib.h>
#include <malloc.h>

#pragma offload_attribute(push, target(mic))
#include <stdio.h>
float *h;// *t;
int bytes, x, y, z;
#pragma offload_attribute(pop)

__attribute__((target (mic))) float *t;
__declspec(target (mic)) void memTest();

__declspec(target (mic)) void memTest() {
int j;
for(j=0; j<bytes; j++)
t[j] = h[j] + 1.0;
}

int main()
{
int i;

x = y = z = 2;
bytes = x*y*z;

h = (float*) _mm_malloc(bytes*sizeof(float), 64);
t = (float*) _mm_malloc(bytes*sizeof(float), 64);
for(i=0; i< bytes; i++)
{
h[i] = i*1.0;
t[i] = 0.0;
}

#pragma offload target(mic:0) in(h : length(bytes)) out( t : length(bytes) alloc_if(1) free_if(0))
{
memTest();

}

for(i=0; i<bytes; i++)
printf("%f : %f\n",h[i], t[i]);

_mm_free(h);
_mm_free(t);
return 0;
}

 icc memoryTest.c -o memoryTest

./memoryTest

Output : 

0.000000 : 17466475581477486592.000000
1.000000 : 17897706240914489344.000000
2.000000 : 289526669708602574255922241077248.000000
3.000000 : 283188126565264719737436795568128.000000
4.000000 : 1125978593735313417306112.000000
5.000000 : 1128588921008050770330779648.000000
6.000000 : 16383931617141325824.000000
7.000000 : 289526669708602574255922241077248.000000

Instead of : 

0.000000 : 1
1.000000 : 2
2.000000 : 3
3.000000 : 4
4.000000 : 5
5.000000 : 6
6.000000 : 7
7.000000 : 8

Please, suggest me what i am doing wrong

3 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hi Arpit,

You need to add "in(bytes)" to the clauses of #pragma offload, because "bytes" is a global variable:

#pragma offload target(mic:0) in(bytes) in(h : length(bytes)) out( t : length(bytes) alloc_if(1) free_if(0))

A

Thank you so much..Andrey Vladimirov..problem has been resloved.

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui