Why are bit fields prohibited in OpenCL?

Cue bits are not supported in the OpenCL language. What is the reason for not supporting them? Unlike other missing objects (recursion, function pointers, ...), where there is an obvious reason not to support them, I do not see them for bitfields. I'm sure this is not oversight on behalf of commits, but what is the reason?

(I store some bits packed in ints, and the code will be nicer to read with them. I understand bit fields as good syntax to avoid shifting bits and masking back and forth, which in any case translates to assembly.)

+6
source share
2 answers

I was able to ask this question to someone participating in the working group. Here is what he had to say:

Bit fields are not portable, so they cannot be used in the types used for kernel arguments.

The only place they can be used is the types for local variables declared inside the kernel.

The OpenCL working group was not convinced that this was very useful. In addition, there are concerns that compilers may not generate efficient code when using bit fields. All this led to a working group's decision not to support bit fields in OpenCL C.

+9
source

Wikipedia has information about the disadvantages of bit fields :

Bit elements in structures, as presented above, have potential practical disadvantages. First, the ordering of bits in memory depends on the processor, and the rules for filling memory may vary between compilers. In addition, less optimized compilers sometimes generate low-quality code for reading and writing bit elements, and there are potential thread safety problems associated with bit fields, because most machines cannot manipulate arbitrary sets of bits in memory, but should instead load and store them whole words.

I think that all these shortcomings are relevant in the OpenCL environment.

+1
source

Source: https://habr.com/ru/post/907021/


All Articles