Nothing works

This commit is contained in:
Dynamitos
2024-10-14 18:14:08 +02:00
parent 98a7e16756
commit 62d6662ad1
14 changed files with 244 additions and 187 deletions
+38 -45
View File
@@ -1,26 +1,44 @@
import Parameters;
// The maximal size of the LDS is 16kbyte.
#ifndef WORKGROUP_SIZE
#define WORKGROUP_SIZE 64
#endif
/*
Level 0: 32 bit // [0, 131072] x 1, needs a minimum of 18 bits (rounded up to 32 for alignment and required for atomic operations)
Level 1: 32 bit // [0, 65536] x 2, needs a minimum of 17 bits (rounded up to 32 for alignment and required for atomic operations)
Level 2: 32 bit // [0, 32768] x 4, needs a minimum of 16 bits (bumped to 32 bits for atomic operations)
Level 3: 32 bit // [0, 16384] x 8, needs a minimum of 15 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 4: 32 bit // [0, 8192] x 16, needs a minimum of 14 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 5: 32 bit // [0, 4096] x 32, needs a minimum of 13 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 6: 32 bit // [0, 2048] x 64, needs a minimum of 12 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 7: 16 bit // [0, 1024] x 128, needs a minimum of 11 bits (rounded up to 16 for alignment)
Level 8: 16 bit // [0, 512] x 256, needs a minimum of 10 bits (rounded up to 16 for alignment)
Level 9: 16 bit // [0, 256] x 512, needs a minimum of 9 bits (rounded up to 16 for alignment)
Level 10: 8 bit // [0, 128] x 1024, needs a minimum of 8 bits
Level 11: Raw 64 bits representation
*/
// Num elements
#define OCBT_NUM_ELEMENTS 1048576
#define OCBT_NUM_ELEMENTS 131072
// Tree sizes
#define OCBT_TREE_SIZE_BITS (32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16* 2048 + 16 * 4096 + 8 * 8192)
#define OCBT_TREE_SIZE_BITS (32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 8 * 1024)
#define OCBT_TREE_NUM_SLOTS (OCBT_TREE_SIZE_BITS / 32)
#define OCBT_BITFIELD_NUM_SLOTS (OCBT_NUM_ELEMENTS / 64)
#define OCBT_LAST_LEVEL_SIZE 8192
#define OCBT_LAST_LEVEL_SIZE 1024
// Tree last level
#define TREE_LAST_LEVEL 13
#define TREE_LAST_LEVEL 10
// First virtual level
#define FIRST_VIRTUAL_LEVEL 14
#define FIRST_VIRTUAL_LEVEL 11
// Leaf level
#define LEAF_LEVEL 20
#define LEAF_LEVEL 17
// per level offset
static const uint32_t OCBT_depth_offset[21] = { 0, // Level 0
static const uint32_t OCBT_depth_offset[18] = { 0, // Level 0
32 * 1, // level 1
32 * 1 + 32 * 2, // level 2
32 * 1 + 32 * 2 + 32 * 4, // level 3
@@ -32,20 +50,17 @@ static const uint32_t OCBT_depth_offset[21] = { 0, // Level 0
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128, // Level 8
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256, // Level 9
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512, // Level 10
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024, // Level 11
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16 * 2048, // Level 12
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16 * 2048 + 16 * 4096, // Level 13
0, // Level 12
0, // Level 13
0, // Level 14
0, // Level 15
0, // Level 16
0, // Level 17
0, // Level 18
0, // Level 19
0, // Level 20
};
static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17
static const uint64_t OCBT_bit_mask[18] = { 0xffffffff, // Root 17
0xffffffff, // Level 16
0xffffffff, // level 15
0xffffffff, // level 14
@@ -56,9 +71,6 @@ static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17
0xffff, // level 10
0xffff, // level 9
0xffff, // level 8
0xffff, // level 8
0xffff, // level 8
0xffff, // level 8
0xff, // level 8
0xffffffffffffffff, // level 7
@@ -70,7 +82,7 @@ static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17
0x1, // level 1
};
static const uint32_t OCBT_bit_count[21] = { 32, // Root 17
static const uint32_t OCBT_bit_count[18] = { 32, // Root 17
32, // Level 16
32, // level 15
32, // level 14
@@ -81,9 +93,6 @@ static const uint32_t OCBT_bit_count[21] = { 32, // Root 17
16, // level 10
16, // level 9
16, // level 8
16, // level 8
16, // level 8
16, // level 8
8, // level 8
64, // Level 5
@@ -417,11 +426,9 @@ void reduce_first_pass(uint dispatchThreadID, uint groupIndex)
{
// Load the lowest level (and only the last level)
const uint level0Offset = OCBT_depth_offset[TREE_LAST_LEVEL] / 32;
for (uint e = 0; e < 4; ++e)
{
uint target_element = 4 * dispatchThreadID + e;
gs_cbtTree[level0Offset + target_element] = pParams.cbtBuffer[level0Offset + target_element];
}
if (groupIndex % 2 == 0)
gs_cbtTree[level0Offset + dispatchThreadID / 2] = pParams.cbtBuffer[level0Offset + dispatchThreadID / 2];
GroupMemoryBarrierWithGroupSync();
// First we do a reduction until each lane has exactly one element to process
@@ -444,29 +451,15 @@ void reduce_first_pass(uint dispatchThreadID, uint groupIndex)
GroupMemoryBarrierWithGroupSync();
// Load the first reduced level
const uint level2Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 1] / 32;
for (uint e = 0; e < 4; ++e)
{
uint target_element = 4 * dispatchThreadID + e;
pParams.cbtBuffer[level2Offset + target_element] = gs_cbtTree[level2Offset + target_element];
}
// Load the first reduced level
const uint level3Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 2] / 32;
for (uint e = 0; e < 2; ++e)
{
uint target_element = 2 * dispatchThreadID + e;
pParams.cbtBuffer[level3Offset + target_element] = gs_cbtTree[level3Offset + target_element];
}
const uint level4Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 3] / 32;
pParams.cbtBuffer[level4Offset + dispatchThreadID] = gs_cbtTree[level4Offset + dispatchThreadID];
const uint level5Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 4] / 32;
if (groupIndex % 2 == 0)
pParams.cbtBuffer[level5Offset + dispatchThreadID / 2] = gs_cbtTree[level5Offset + dispatchThreadID / 2];
pParams.cbtBuffer[level2Offset + dispatchThreadID / 2] = gs_cbtTree[level2Offset + dispatchThreadID / 2];
const uint level3Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 2] / 32;
if (groupIndex % 4 == 0)
pParams.cbtBuffer[level3Offset + dispatchThreadID / 4] = gs_cbtTree[level3Offset + dispatchThreadID / 4];
}
void reduce_second_pass(uint groupIndex)
{
// Load the lowest level (and only the last level)