Bug 98717 - Incorrect result with __attribute__((packed))
Summary: Incorrect result with __attribute__((packed))
Status: RESOLVED MOVED
Alias: None
Product: Beignet
Classification: Unclassified
Component: Beignet (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Xiuli Pan
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-14 12:15 UTC by Kai
Modified: 2018-10-12 21:24 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Minimal example to reproduce (3.73 KB, text/x-c)
2016-11-14 12:15 UTC, Kai
Details

Description Kai 2016-11-14 12:15:16 UTC
Created attachment 127966 [details]
Minimal example to reproduce

Declaring a struct with __attribute__((packed)) causes writes to sometimes be incorrect. The attached program prints:

  Node {
      right_edge = 0,
      children = {257, 65536}
  }

The expected result is:

  Node {
      right_edge = 0,
      children = {1, 1}
  }

which is produced on the nVidia OpenCL driver. Removing __attribute__((packed)) (from the CL src only), or changing the order of writes as described in the comments also works around the issue.

Device information from utests is:

> device_name "Intel(R) HD Graphics Haswell Ultrabook GT2 Mobile"
Comment 1 Xiuli Pan 2016-11-18 05:04:55 UTC
Hi Kai,

I have tried your code and there is another error here, and I have fixed this bug. What beinget version your are runing? I will try your version to see if there is the same problem.

Thanks
Xiuli
Comment 2 Kai 2016-11-18 11:29:31 UTC
It happens with 1.2.1 and latest git master (git-75b6f38).

What was the error in my example? It seems to work for me (though it might need `-std=c11`).
Comment 3 Xiuli Pan 2016-11-21 02:29:29 UTC
Hi Kai,

I will get an assert in compiling the kernel and could not get the result. I think you have built release version?

This bug is very complex and not only related to packed structure, it also related to the llvm optimization that on my machine, the structure type was optimized to int3.

I have a workaround on llvm 3.8 and I am not sure if it works fine with other llvm and I will send a patch to fix this problem as soon as I figured out which optimization caused the bug. 

Thanks
Xiuli
Comment 4 Kai 2016-11-21 11:23:52 UTC
Ah - I think my mistake might be in the LLVM version. I have LLVM 3.9.0, which looking here (https://www.freedesktop.org/wiki/Software/Beignet/) is not officially supported.
Comment 5 Xiuli Pan 2016-12-01 02:49:34 UTC
Hi Kai,

Now we support llvm3.9 on master. Could you try again with a debug version to verify if we meet the same problem?

Thanks
Xiuli
Comment 6 Kai 2017-01-03 17:35:26 UTC
Sorry for the long delay. I can confirm that the issue still occurs with the latest version 'OpenCL 1.2 beignet 1.3 (git-989db5f)' and LLVM 3.9.1 on a Release build.

Is there an easy way to use a local build of beignet without removing the system install? I have tried the following, but get an error (where <...> is just a long directory name):

$ env OPENCL_VENDOR_PATH=<...>/beignet/build LD_LIBRARY_PATH=<...>/beignet/build/backend/src/ ./a.out
unable to load /usr/local/lib64/beignet//libgbeinterp.so which is part of the driver, please check!
a.out: packbug.c:84: main: Assertion `err == 0' failed.
fish: “env OPENCL_VENDOR_PATH=/home/ka…” terminated by signal SIGABRT (Abort)
Comment 7 Xiuli Pan 2017-01-06 08:27:29 UTC
Hi Kai,

We found the bug is about the structure is treated as int3 in backend, and as OpenCL spec int3 is treated as int4, such as the alignment and offset. We will meet an assert when use the debug version beignet.

If you want to build the program with some standalone beignet but not over through the ICD, you can use some build option like:
gcc test.c -o test -L/usr/local/lib/beignet -lcl
these will by pass the ICD and using the build and installed beinet, if you did not want to install, maybe you can try the libcl.so in <...>/beignet/build/ and refer the setenv.sh in <...>/beignet/build/utests/

Thanks
Xiuli
Comment 8 GitLab Migration User 2018-10-12 21:24:10 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/beignet/beignet/issues/26.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.