Commit 78948b41 authored by Jørgen Lind's avatar Jørgen Lind
Browse files

Make it possible to have single threaded requests

This is needed when target format is 1 Bit.
parent d37b9e5b
......@@ -524,7 +524,6 @@ static int32_t CombineAndReduceDimensions (int32_t (&sourceSize )[DataStoreDime
nCopyDimensions++;
}
// Resulting number of copy dimensions must not exceed HueDataBlock_c::DIMENSIONALITY_MAX
assert(nCopyDimensions <= DataStoreDimensionality_Max && "Invalid Copy Parameters #4");
// Further combine inner dimensions if possible, to minimize number of copy invocations
......@@ -587,7 +586,7 @@ static force_inline void CopyBytesT(T* __restrict target, const T* __restrict so
{
if (size >= MIN_MEMCPY)
{
memcpy (target, source, size);
memcpy (target, source, size_t(size));
}
else
{
......@@ -600,18 +599,18 @@ static force_inline void CopyBytesT(T* __restrict target, const T* __restrict so
if (nTail)
{
assert(nTail <= 7 && "Invalid Sample Size Remainder\n");
uint8_t *sourceTail = (uint8_t *) (source + nBigElements);
const uint8_t *sourceTail = (const uint8_t *) (source + nBigElements);
uint8_t *targetTail = (uint8_t *) (target + nBigElements);
int32_t iTail = 0;
switch (nTail)
{
case 7: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 6: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 5: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 4: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 3: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 2: targetTail [iTail] = sourceTail [iTail]; iTail++;
case 7: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 6: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 5: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 4: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 3: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 2: targetTail [iTail] = sourceTail [iTail]; iTail++; [[clang::fallthrough]];
case 1: targetTail [iTail] = sourceTail [iTail];
}
}
......@@ -868,7 +867,7 @@ static int64_t StaticRequestVolumeSubset(VolumeDataRequestProcessor &request_pro
abort();
}
return request_processor.AddJob(chunksInRegion, [boxRequested, buffer, format](VolumeDataPageImpl* page, VolumeDataChunk dataChunk, Error &error) {return RequestSubsetProcessPage(page, dataChunk, boxRequested.min, boxRequested.max, format, buffer, error);});
return request_processor.AddJob(chunksInRegion, [boxRequested, buffer, format](VolumeDataPageImpl* page, VolumeDataChunk dataChunk, Error &error) {return RequestSubsetProcessPage(page, dataChunk, boxRequested.min, boxRequested.max, format, buffer, error);}, format == VolumeDataChannelDescriptor::Format_1Bit);
}
static VolumeDataLayer *GetLayer(VolumeDataLayout const *layout, DimensionsND dimensionsND, int lod, int channel)
......@@ -1416,8 +1415,7 @@ static int64_t StaticRequestProjectedVolumeSubset(VolumeDataRequestProcessor &re
fmt::print(stderr, "Requested volume subset does not contain any data");
abort();
}
return request_processor.AddJob(chunksInRegion, [boxRequested, buffer, projectedDimensions, voxelPlaneSwapped, interpolationMethod, isReplaceNoValue, replacementNoValue](VolumeDataPageImpl* page, VolumeDataChunk dataChunk, Error &error) { return RequestProjectedVolumeSubsetProcessPage(page, dataChunk, boxRequested.min, boxRequested.max, projectedDimensions, voxelPlaneSwapped, interpolationMethod, isReplaceNoValue, replacementNoValue, buffer, error);});
return request_processor.AddJob(chunksInRegion, [boxRequested, buffer, projectedDimensions, voxelPlaneSwapped, interpolationMethod, isReplaceNoValue, replacementNoValue](VolumeDataPageImpl* page, VolumeDataChunk dataChunk, Error &error) { return RequestProjectedVolumeSubsetProcessPage(page, dataChunk, boxRequested.min, boxRequested.max, projectedDimensions, voxelPlaneSwapped, interpolationMethod, isReplaceNoValue, replacementNoValue, buffer, error);}, eFormat == VolumeDataChannelDescriptor::Format_1Bit);
}
struct VolumeDataSamplePos
......
......@@ -139,7 +139,7 @@ static Error ProcessPageInJob(Job *job, size_t pageIndex, VolumeDataPageAccessor
return error;
}
int64_t VolumeDataRequestProcessor::AddJob(const std::vector<VolumeDataChunk>& chunks, std::function<bool(VolumeDataPageImpl * page, const VolumeDataChunk &volumeDataChunk, Error & error)> processor)
int64_t VolumeDataRequestProcessor::AddJob(const std::vector<VolumeDataChunk>& chunks, std::function<bool(VolumeDataPageImpl * page, const VolumeDataChunk &volumeDataChunk, Error & error)> processor, bool singleThread)
{
auto layer = chunks.front().Layer;
DimensionsND dimensions = DimensionGroupUtil::GetDimensionsNDFromDimensionGroup(layer->GetPrimaryChannelLayer().GetChunkDimensionGroup());
......@@ -181,9 +181,37 @@ int64_t VolumeDataRequestProcessor::AddJob(const std::vector<VolumeDataChunk>& c
jobPage.page = static_cast<VolumeDataPageImpl *>(pageAccessor->PrepareReadPage(c.Index, &jobPage.needToReadPage));
assert(jobPage.page && "Need to add error handling here when the page cannot be read");
jobPage.chunk = c;
size_t index = job->pages.size() - 1;
if (!singleThread)
{
size_t index = job->pages.size() - 1;
auto job_ptr = job.get();
job->future.push_back(m_threadPool.Enqueue([job_ptr, index, pageAccessor, processor] { return ProcessPageInJob(job_ptr, index, pageAccessor, processor); }));
}
}
if (singleThread)
{
auto job_ptr = job.get();
job->future.push_back(m_threadPool.Enqueue([job_ptr, index, pageAccessor, processor] { return ProcessPageInJob(job_ptr, index, pageAccessor, processor); }));
job->future.push_back(m_threadPool.Enqueue([job_ptr, pageAccessor, processor]
{
Error error;
int pages_size = int(job_ptr->pages.size());
for (int i = 0; i < pages_size; i++)
{
if (error.code == 0)
{
error = ProcessPageInJob(job_ptr, size_t(i), pageAccessor, processor);
if (error.code)
{
job_ptr->cancelled = true;
}
}
else
{
ProcessPageInJob(job_ptr, size_t(i), pageAccessor, processor);
}
}
return error;
}));
}
return job->jobId;
}
......
......@@ -81,7 +81,7 @@ public:
VolumeDataRequestProcessor(VolumeDataAccessManagerImpl &manager);
~VolumeDataRequestProcessor();
int64_t AddJob(const std::vector<VolumeDataChunk> &chunks, std::function<bool(VolumeDataPageImpl *page, const VolumeDataChunk &volumeDataChunk, Error &error)> processor);
int64_t AddJob(const std::vector<VolumeDataChunk> &chunks, std::function<bool(VolumeDataPageImpl *page, const VolumeDataChunk &volumeDataChunk, Error &error)> processor, bool singleThread = false);
bool IsCompleted(int64_t requestID);
bool IsCanceled(int64_t requestID);
bool WaitForCompletion(int64_t requestID, int millisecondsBeforeTimeout = 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment