From 36cb31011962a2b74ad67d2626d76c592b476256 Mon Sep 17 00:00:00 2001 From: Ingo Wald Date: Thu, 12 Nov 2026 09:15:43 -0700 Subject: [PATCH] made refit_aggregate accept a lambda instead of a funciton pointer --- cuBQL/builder/cuda/refit_aggregate.h | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/cuBQL/builder/cuda/refit_aggregate.h b/cuBQL/builder/cuda/refit_aggregate.h index 183e7bb..4db83e0 100644 --- a/cuBQL/builder/cuda/refit_aggregate.h +++ b/cuBQL/builder/cuda/refit_aggregate.h @@ -65,6 +65,41 @@ namespace cuBQL { } } + template + __global__ + void refit_aggregate_run2(BinaryBVH bvh, + AggregateNodeData *aggregateNodeData, + const AggrelateLambda &lambda, + uint32_t *refitData) + { + int nodeID = threadIdx.x+blockIdx.x*blockDim.x; + if (nodeID == 1 || nodeID >= bvh.numNodes) return; + + typename BinaryBVH::Node *node = &bvh.nodes[nodeID]; + if (node->admin.count == 0) + // this is a inner node - exit + return; + + int parentID = (refitData[nodeID] >> 1); + while (true) { + lambda(bvh,aggregateNodeData,nodeID); + __threadfence(); + if (node == bvh.nodes) + break; + + uint32_t refitBits = atomicAdd(&refitData[parentID],1u); + if ((refitBits & 1) == 0) + // we're the first one - let other one do it + break; + + nodeID = parentID; + node = &bvh.nodes[parentID]; + parentID = (refitBits >> 1); + } + } + // ------------------------------------------------------------------ @@ -93,5 +128,31 @@ namespace cuBQL { memResource.free((void*)refitData,s); // we're not syncing here - let APP do that } + + template< + typename T, + int D, + typename AggregateNodeData, + typename AggregateLambda> + void refit_aggregate2(BinaryBVH bvh, + AggregateNodeData *d_aggregateNodeData, + // void (*aggregateFct)(BinaryBVH, + // AggregateNodeData[], + // int), + const AggregateLambda &lambda, + cudaStream_t s, + GpuMemoryResource &memResource) + { + int numNodes = bvh.numNodes; + + uint32_t *refitData = 0; + memResource.malloc((void**)&refitData,numNodes*sizeof(*refitData),s); + refit_init<<>> + (bvh.nodes,refitData,numNodes); + refit_aggregate_run2<<>> + (bvh,d_aggregateNodeData,lambda,refitData); + memResource.free((void*)refitData,s); + // we're not syncing here - let APP do that + } } }