Quantcast
Channel: CUDAfy.NET
Viewing all articles
Browse latest Browse all 1169

Commented Unassigned: ulong compile issue? [1095]

$
0
0
Is this an issue ( the line that reads):

array[(1)] = (unsigned short)((unsigned int)(num5 & (unsigned long long)-65536) >> 16);

Here is the original C# source, and below is the CUDA-C.


```
window[00] = (ushort)((zero & 0x000000000000ffff) >> 00);
window[01] = (ushort)((zero & 0x00000000ffff0000) >> 16);
window[02] = (ushort)((zero & 0x0000ffff00000000) >> 32);
window[03] = (ushort)((zero & 0xffff000000000000) >> 48);

window[04] = (ushort)((one & 0x000000000000ffff) >> 00);
window[05] = (ushort)((one & 0x00000000ffff0000) >> 16);
window[06] = (ushort)((one & 0x0000ffff00000000) >> 32);
window[07] = (ushort)((one & 0xffff000000000000) >> 48);

window[08] = (ushort)((two & 0x000000000000ffff) >> 00);
window[09] = (ushort)((two & 0x00000000ffff0000) >> 16);
window[10] = (ushort)((two & 0x0000ffff00000000) >> 32);
window[11] = (ushort)((two & 0xffff000000000000) >> 48);

window[12] = (ushort)((three & 0x000000000000ffff) >> 00);
window[13] = (ushort)((three & 0x00000000ffff0000) >> 16);
window[14] = (ushort)((three & 0x0000ffff00000000) >> 32);
```


```
array[(0)] = (unsigned short)(num5 & 65535uL);
array[(1)] = (unsigned short)((unsigned int)(num5 & (unsigned long long)-65536) >> 16);
array[(2)] = (unsigned short)((unsigned int)(num5 & 281470681743360uL) >> 32);
array[(3)] = (unsigned short)((unsigned int)(num5 & 18446462598732840960uL) >> 48);
array[(4)] = (unsigned short)(num6 & 65535uL);
array[(5)] = (unsigned short)((unsigned int)(num6 & (unsigned long long)-65536) >> 16);
array[(6)] = (unsigned short)((unsigned int)(num6 & 281470681743360uL) >> 32);
array[(7)] = (unsigned short)((unsigned int)(num6 & 18446462598732840960uL) >> 48);
array[(8)] = (unsigned short)(num7 & 65535uL);
array[(9)] = (unsigned short)((unsigned int)(num7 & (unsigned long long)-65536) >> 16);
array[(10)] = (unsigned short)((unsigned int)(num7 & 281470681743360uL) >> 32);
array[(11)] = (unsigned short)((unsigned int)(num7 & 18446462598732840960uL) >> 48);
array[(12)] = (unsigned short)(num8 & 65535uL);
array[(13)] = (unsigned short)((unsigned int)(num8 & (unsigned long long)-65536) >> 16);
array[(14)] = (unsigned short)((unsigned int)(num8 & 281470681743360uL) >> 32);
```
Comments: ** Comment from web user: ygutfreund **

Here is the full source. it takes a single frame of video data (2560x2048, 12 bits per pixel) pushes into the frames stack, and finds the median value for each pixel (via a bubble sort). It then subtracts that median. Basically it is a sensor noise removal algorithm that finds sticky bits and removes that from the image. I found that 64 bit reads work faster than storing it as ushorts.

```
[Cudafy]
public static void gMedianFast(GThread thread, ushort[] raw, ulong[,] frames, short[,] cleanground, int slot, int viewMedian)
{
int x = (thread.threadIdx.x + (thread.blockDim.x * thread.blockIdx.x)) % Frame.width;
int y = (thread.threadIdx.x + (thread.blockDim.x * thread.blockIdx.x)) / Frame.width;
int tid = thread.threadIdx.x;
ushort newPix;
ushort median;
int block;
int offset;
ulong zero;
ulong one;
ulong two;
ulong three;
ulong value;
int idx = x + (y * Frame.width);

ushort[,] window = thread.AllocateShared<ushort>("window", frameStackSize, medianThreadBlock);

newPix = raw[idx];
zero = frames[0,idx];
one = frames[1, idx];
two = frames[2, idx];
three = frames[3, idx];

window[00, tid] = (ushort)((zero & 0x000000000000ffff) >> 00);
window[01, tid] = (ushort)((zero & 0x00000000ffff0000) >> 16);
window[02, tid] = (ushort)((zero & 0x0000ffff00000000) >> 32);
window[03, tid] = (ushort)((zero & 0xffff000000000000) >> 48);

window[04, tid] = (ushort)((one & 0x000000000000ffff) >> 00);
window[05, tid] = (ushort)((one & 0x00000000ffff0000) >> 16);
window[06, tid] = (ushort)((one & 0x0000ffff00000000) >> 32);
window[07, tid] = (ushort)((one & 0xffff000000000000) >> 48);

window[08, tid] = (ushort)((two & 0x000000000000ffff) >> 00);
window[09, tid] = (ushort)((two & 0x00000000ffff0000) >> 16);
window[10, tid] = (ushort)((two & 0x0000ffff00000000) >> 32);
window[11, tid] = (ushort)((two & 0xffff000000000000) >> 48);

window[12, tid] = (ushort)((three & 0x000000000000ffff) >> 00);
window[13, tid] = (ushort)((three & 0x00000000ffff0000) >> 16);
window[14, tid] = (ushort)((three & 0x0000ffff00000000) >> 32);

window[slot, tid] = newPix;

block = slot / 4;
offset = slot % 4;
value = zero; // make c# happy by defining value
switch (block)
{
case 0: value = zero; break;
case 1: value = one; break;
case 2: value = two; break;
case 3: value = three; break;
}

switch (offset)
{
case 0:
value = (value & 0xffffffffffff0000) | ((ulong)newPix << 00);
break;
case 1:
value = (value & 0xffffffff0000ffff) | ((ulong)newPix << 16);
break;
case 2:
value = (value & 0xffff0000ffffffff) | ((ulong)newPix << 32);
break;
case 3:
value = (value & 0x0000ffffffffffff) | ((ulong)newPix << 48);
break;
}
frames[block, idx] = value;

for (int j = 0; j < (frameStackSize + 1) / 2; j++)
{
int min = j;
for (int l = j + 1; l < frameStackSize; l++)
{
if (window[l, tid] < window[min, tid])
min = l;
}
ushort temp = window[j, tid];
window[j, tid] = window[min, tid];
window[min, tid] = temp;
}

median = window[frameStackSize / 2, tid];
if (viewMedian == 0)
{
cleanground[y, x] = (short)(raw[idx] - median);
}
else
{
cleanground[y, x] = (short)median;
}
}
```


Viewing all articles
Browse latest Browse all 1169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>