rzel / aparapi

Automatically exported from code.google.com/p/aparapi
Other
0 stars 0 forks source link

Array .length returns negative number instead of actual array length #140

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

int[] test = new int[100];
Device.hsaForEach(1, i -> {
   test[0] = test.length;
});
System.out.println("Length: " + test[0]);

What is the expected output? What do you see instead?
I expected to see the output: 
Length: 100

I see the following instead:
Length: -134217363

What version of the product are you using? On what operating system?
Aparapi-lambda r1610 on Ubuntu 13.10

Please provide any additional information below.
AMD A10-7850K APU, GIGABYTE|GA-F2A88X-UP4 ( F4 BIOS, IOMMU enabled )

In the mean time, is there a workaround to retrieve the length of an array? 

Original issue reported on code.google.com by adri...@caloiaro.com on 26 Mar 2014 at 2:49

GoogleCodeExporter commented 8 years ago
It is also worth noting that the value returned is contingent on the array's 
datatype. When test[] is a double[], .length returns: -1.34217543E8.

Original comment by adri...@caloiaro.com on 26 Mar 2014 at 2:54

GoogleCodeExporter commented 8 years ago
Interesting.  

This code returns 100 for me as expected.  On two platforms. 

Are you running with -D-UseCompressedOops ?

Basically the length of an array is a field of the instance and it's offset 
changes based on whether you are using compressed oops or not.

Can you send me the HSAIL output by setting 
-Dcom.amd.aparapi.enableShowGeneratedHSAIL=true

Mine looks like this.... 

version 0:95: $full : $large;
kernel &run(
    kernarg_u64 %_arg0, 
     kernarg_s32 %_arg1
   ){
         ld_kernarg_u64 $d0, [%_arg0];
         ld_kernarg_s32 $s1, [%_arg1];
         workitemabsid_s32 $s2, 0;

 // 0000_0000 aload_0  var#0(oref_0 [I)
         add_s32 $s1, $s1, $s2;
         mov_b64 $d2, $d0;

 // 0000_0001 iconst_0.0
         mov_b32 $s3, 0;

 // 0000_0002 aload_0  var#0(oref_0 [I)
         mov_b64 $d4, $d0;

 // 0000_0003 arraylength
         ld_global_s32 $s4, [$d4+16];

 // 0000_0004 iastore 
         cvt_u64_s32 $d3, $s3;
         mad_u64 $d3, $d3, 4, $d2;
         st_global_s32 $s4, [$d3+24];

 // 0000_0005 return  
         ret;
};

Original comment by frost.g...@gmail.com on 26 Mar 2014 at 7:47

GoogleCodeExporter commented 8 years ago
Thank you once again, Gary. This also cleared up the other issue that I was 
reluctant to post about until I tested more thoroughly: indexing into an 
Object[] array and getting very unexpected results! 

Original comment by adri...@caloiaro.com on 26 Mar 2014 at 7:57

GoogleCodeExporter commented 8 years ago
So -D-UseCompressedOops=false worked?

Nice.

Actually I though that Aparapi would dump an error message if this was not set. 
  Let me check that code. 

Gary

Original comment by frost.g...@gmail.com on 26 Mar 2014 at 9:46