diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp index 3246b21..79dd943 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp @@ -711,16 +711,21 @@ bool OpenClCollatingAndMeshingEngine::stop() return wasAcceptingRequests; } -void OpenClCollatingAndMeshingEngine::compactKernelComplete() +void OpenClCollatingAndMeshingEngine::compactKernelComplete(bool isFinalizing) { + cl_map_flags mapFlags; + /** EXPLANATION: * Technically we should only need to do this if we plan to read the * compacted slots for debugging purposes. Otherwise this is unnecessary. */ - mapAssemblyBuffer(CL_MAP_READ); + + if (isFinalizing) { mapFlags = CL_MAP_WRITE_INVALIDATE_REGION; } + else { mapFlags = CL_MAP_READ; } + + mapAssemblyBuffer(mapFlags); unmapAssemblyBuffer(); clFlush(commandQueue); - clFinish(commandQueue); // Stop only compact kernel if (compactIsRunning && currentCompactKernelEvent) @@ -729,20 +734,26 @@ void OpenClCollatingAndMeshingEngine::compactKernelComplete() clReleaseEvent(currentCompactKernelEvent); currentCompactKernelEvent = nullptr; } + + clFinish(commandQueue); compactKernelCb = [](cl_int){}; compactIsRunning = false; } -void OpenClCollatingAndMeshingEngine::collateKernelComplete() +void OpenClCollatingAndMeshingEngine::collateKernelComplete(bool isFinalizing) { + cl_map_flags mapFlags; /** EXPLANATION: * Technically we should only need to do this if we plan to read the * collated dgrams for debugging purposes. Otherwise this is unnecessary. */ - mapCollationBuffer(CL_MAP_READ); + if (isFinalizing) { mapFlags = CL_MAP_WRITE_INVALIDATE_REGION; } + else { mapFlags = CL_MAP_READ; } + + mapCollationBuffer(mapFlags); unmapCollationBuffer(); clFlush(commandQueue); - clFinish(commandQueue); + // Stop only collate kernel if (collateIsRunning && currentCollateKernelEvent) { @@ -750,6 +761,8 @@ void OpenClCollatingAndMeshingEngine::collateKernelComplete() clReleaseEvent(currentCollateKernelEvent); currentCollateKernelEvent = nullptr; } + + clFinish(commandQueue); collateKernelCb = [](cl_int){}; collateIsRunning = false; } diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h index 31a841c..5d5b5e0 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h @@ -60,8 +60,8 @@ private: StagingBuffer& assemblyBuff, StagingBuffer& collationBuff, collateKernelCbFn callback); - void compactKernelComplete(); - void collateKernelComplete(); + void compactKernelComplete(bool isFinalizing=false); + void collateKernelComplete(bool isFinalizing=false); bool stop(); public: