You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Casting uints to bytes sometimes causes unexpected behaviour in simple arithmetic and conditional operations. This appears to happen only when the uint in question has its 128 bit set. The output depends on whether it's being built in Debug or Release mode. This has been tested on at least a T4, and with both rc1 and older ILGPU code.
Code
public class MiscClean {
public static void KernelByteBugs(Index1D index, ArrayView1D<uint, Stride1D.Dense> input, ArrayView1D<uint, Stride1D.Dense> output) {
for (int i = 0; i < input.Length; i++) {
byte b = (byte)input[i];
output[0] += b;
output[1] += ((byte)input[i]) & 255u;
output[2] += ((byte)input[i]);
output[3] += input[i] & 255;
byte b0 = (byte)(input[i]);
if (b0 < 128) output[4]++;
if (((input[i]) & 255) < 128) output[5]++;
}
}
static void Main(string[] args) {
using var context = Context.Create().Cuda().ToContext();
using var acc = context.CreateCudaAccelerator(0);
var input = new uint[1] { 130u };
var output = new uint[6];
var gpuInput = acc.Allocate1D(input);
var gpuOutput = acc.Allocate1D(output);
acc.LaunchAutoGrouped(KernelByteBugs, new Index1D(1), gpuInput.View, gpuOutput.View);
gpuOutput.CopyToCPU(output);
for (int i = 0; i < output.Length; i++) {
Console.WriteLine($"output[{i}] = {output[i]}");
}
}
}
@Ruberik I have raised a PR that fixes this issue.
@m4rs-mt The issue appears to be that nested conversions are ignoring the unsigned flag of the inner conversion. However, I could only replicate this on byte to uint. Is there something that I am missing?
Summary
Casting
uint
s tobyte
s sometimes causes unexpected behaviour in simple arithmetic and conditional operations. This appears to happen only when the uint in question has its128
bit set. The output depends on whether it's being built in Debug or Release mode. This has been tested on at least a T4, and with both rc1 and older ILGPU code.Code
Output
Expected:
Actual, in debug mode:
Actual, in release mode:
Note the difference on
output[4]
.Notes
(value & 128) != 0
. Behaviour is as expected if that bit isn't set.The text was updated successfully, but these errors were encountered: