cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

diapolo
Adept I

kernel output-buffer as ulong (64-Bit)?

Is it allowed to write into global memory if it is defined as __global ulong *? I want to pack 2 uints into 1 ulong and write this in global memory and reverse this in the host application.

const ulong a = (ulong)(Var1 << 32);
const ulong b = ((Var2 & 0xFFFFFFFFU;
const ulong Var64 = a | b;

output[0] = Var64;

Currently it seems as if only 32 Bits of data are written into the output-buffer. On host application side the buffer is of type uint64 (numpy - Python).

Thanks,

Dia

0 Likes
11 Replies

Why not just use uint2 a = some value;
output[0] = as_ulong(a);
0 Likes

Originally posted by: MicahVillmow Why not just use uint2 a = some value; output[0] = as_ulong(a);


Thanks, I didn't know, that this can be used for packing :). But the problem is, that my host application always seems to only get 32 Bits of data.

But the question if it's possible to write an ulong to global memory is yes, right? Any idea what could cause a bit-loss here?

Dia

0 Likes

diapolo,
Yeah, you can write ulong to memory. Make sure that you are using the correct types on the host side. Instead of unsigned long, use cl_ulong. Some systems have unsigned long as 32bits.
0 Likes

Hey Micah,

I figured out, that he host application is doing it's job pretty fine. The buffer consists of an uint64 array.

But there seems to be some kind of weird bug in the OpenCL runtime, please look at this 2 code samples:

 

1.

__constant constVal = 0xec9fcd13;

uint2 Result = (uint2)(((Vec2a.x == constVal) * Vec2b.x), ((Vec2a.y == constVal) * Vec2b.y));
output[1023 & Result.x] = ((ulong)Result.x << 32) | (Result.y & 0xFFFFFFFFUL);

This doesn't work as it should, there are only results in the hi-part of the output-buffer element. lo-part is always 0!

2.

__constant constVal = 0xec9fcd13;

uint2 Result = (uint2)(((Vec2a.x == constVal) * Vec2b.x), ((Vec2a.y == constVal) * Vec2b.y));
output[1023 & Result.x] = ((ulong)Result.x << 32) | (5 & 0xFFFFFFFFUL);

This works as expected, sometimes there is something in the hi-part, but 5 is always in the lo part!

What is that? I need this to work :-/.

 

Thanks,

Dia

0 Likes

This is real output from the host application!

Example for 1:

(full) 8778967785008005120 - (hi) 2044012720  - (lo) 0

 

Example for 2:

(full) 18141958308028743685 - (hi) 4224003830 - (lo) 5

Dia

0 Likes

Originally posted by: diapolo This is real output from the host application!

 

Example for 1:

 

(full) 8778967785008005120 - (hi) 2044012720  - (lo) 0

 

Example for 2:

 

(full) 18141958308028743685 - (hi) 4224003830 - (lo) 5

 

Could you please paste both runtime and kernel code here?

Please replace 0xFFFFFFFFUL with a ulong variable which is initialized to thi s value and see what happens.

0 Likes

Same behaviour  with const ulong Mask = 0xFFFFFFFFUL; as before. I'll open a ticket and send in the kernel and the part, where host app processes the OpenCL stuff. I will post the ID here!

It seems not logical to me what happens there ... could you please tell me if my code should work in theory.

Dia

0 Likes

Ticket ID is 1488 (whose kernel is the latest one, and is used in Ticket ID 1481, too).

Dia

0 Likes

Originally posted by: diapolo Ticket ID is 1488 (whose kernel is the latest one, and is used in Ticket ID 1481, too).

 

Dia

 

Thanks for filing ticket. 

0 Likes

You could also try upsample().

 

0 Likes

Thanks, upsamle() seems to be the function I really want, because as_ulong() is implementation specific, even if it works here.

It seems I found the part that didn't work:

uint2 Result = (uint2)(((Vec2a.x == constVal) * Vec2b.x), ((Vec2a.y == constVal) * Vec2b.y));
output[1023 & (Result.x | Result.y)] = upsample(Result.x, Result.y)

If Result.x == 0 the code would have written to output[0], even if Result.y != 0. Now the result is only written to output[0], if both components of Result are 0.

But it still seems weird, what I described a few postings before. Could well be a small Compiler glitch.

Dia

0 Likes