Skip to content

Commit dacf7fb

Browse files
author
Grok Compression
committed
TileProcessor: simplify scheduling
1 parent 89207d5 commit dacf7fb

File tree

5 files changed

+70
-76
lines changed

5 files changed

+70
-76
lines changed

.vscode/launch.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,15 @@
326326
"request": "launch",
327327
"program": "${workspaceFolder}/build/bin/grk_decompress",
328328
"args": [
329-
"-i",
330-
"$HOME/src/grok-test-data/input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k",
331-
"-H 1",
332-
"-r 4",
333-
"-o",
334-
"$HOME/temp/test_failed.tif"
329+
"-i",
330+
"/home/aaron/src/grok-test-data/input/nonregression/issue391.jp2",
331+
"-o",
332+
"/home/aaron/temp/issue391.jp2.tif"
335333
],
336334
"cwd": "${workspaceFolder}",
337335
"environment": [
338-
{ "name": "GRK_DEBUG", "value": "4" }
336+
{ "name": "GRK_DEBUG", "value": "4"} ,
337+
{ "name": "GRK_TEST_SINGLE", "value": "1"}
339338
],
340339
"MIMode": "gdb",
341340
"miDebuggerPath": "/usr/bin/gdb"
@@ -786,10 +785,12 @@
786785
"program": "${workspaceFolder}/build/bin/grk_decompress",
787786
"args": [
788787
"-i",
789-
"$HOME/Downloads/clusterfuzz-testcase-minimized-grk_decompress_fuzzer-6033353920020480",
790-
"-d 0,0,1024,1024",
791-
"-o",
792-
"$HOME/temp/fuzz.tif"
788+
"$HOME/temp/clusterfuzz-testcase-minimized-grk_decompress_fuzzer-5280426615963648",
789+
// "-d 0,0,1024,1024",
790+
"-t",
791+
"20",
792+
"-o",
793+
"$HOME/temp/fuzz.pgx"
793794

794795
],
795796
"environment": [

src/lib/core/codestream/CodingParams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define GRK_RESTRICT /* GRK_RESTRICT */
3333
#endif
3434

35-
#include <Logger.h>
35+
#include "Logger.h"
3636

3737
#include "CodeStreamLimits.h"
3838
#include "geometry.h"

src/lib/core/codestream/decompress/CodeStreamDecompress_Dump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ITileProcessor;
4242
#include "PacketLengthCache.h"
4343
#include "CoderPool.h"
4444
#include "ICoder.h"
45-
#include "WindowScheduler.h"
45+
#include "CodecScheduler.h"
4646
#include "ITileProcessor.h"
4747
#include "TileCache.h"
4848
#include "TileCompletion.h"

src/lib/core/tile_processor/TileProcessor.cpp

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "grk_exceptions.h"
19-
#include <Logger.h>
19+
#include "Logger.h"
2020
#include "CodeStreamLimits.h"
2121
#include "geometry.h"
2222
#include "buffer.h"
@@ -992,45 +992,7 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
992992
scheduler_->release();
993993
}
994994

995-
bool doT2 = !current_plugin_tile_ || (current_plugin_tile_->decompress_flags & GRK_DECODE_T2);
996-
997-
auto allocAndSchedule = [this]() {
998-
if(!Scheduling::isWindowedScheduling())
999-
{
1000-
for(uint16_t compno = 0; compno < tile_->numcomps_; ++compno)
1001-
{
1002-
auto tilec = tile_->comps_ + compno;
1003-
if(!tcp_->wholeTileDecompress_)
1004-
{
1005-
try
1006-
{
1007-
tilec->allocRegionWindow(tilec->nextPacketProgressionState_.numResolutionsRead(),
1008-
truncated_);
1009-
}
1010-
catch([[maybe_unused]] const std::runtime_error& ex)
1011-
{
1012-
continue;
1013-
}
1014-
catch([[maybe_unused]] const std::bad_alloc& baex)
1015-
{
1016-
success_ = false;
1017-
return;
1018-
}
1019-
}
1020-
if(!tilec->getWindow()->alloc())
1021-
{
1022-
grklog.error("Not enough memory for tile data");
1023-
success_ = false;
1024-
return;
1025-
}
1026-
}
1027-
}
1028-
if(!scheduler_->schedule(this))
1029-
{
1030-
success_ = false;
1031-
return;
1032-
}
1033-
};
995+
// bool doT2 = !current_plugin_tile_ || (current_plugin_tile_->decompress_flags & GRK_DECODE_T2);
1034996

1035997
auto t2Parse = [this]() {
1036998
// synch plugin with T2 data
@@ -1107,40 +1069,68 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
11071069
}
11081070
};
11091071

1110-
if(doT2)
1111-
{
1112-
if(ExecSingleton::num_threads() > 1)
1072+
auto allocAndSchedule = [this]() {
1073+
if(!Scheduling::isWindowedScheduling())
11131074
{
1114-
if(!t2ParseFlow_)
1115-
t2ParseFlow_ = std::make_unique<FlowComponent>();
1116-
else
1117-
t2ParseFlow_->clear();
1118-
t2ParseFlow_->nextTask().work(t2Parse);
1119-
1120-
if(!allocAndScheduleFlow_)
1121-
allocAndScheduleFlow_ = std::make_unique<FlowComponent>();
1122-
else
1123-
allocAndScheduleFlow_->clear();
1124-
allocAndScheduleFlow_->nextTask().work(allocAndSchedule);
1075+
for(uint16_t compno = 0; compno < tile_->numcomps_; ++compno)
1076+
{
1077+
auto tilec = tile_->comps_ + compno;
1078+
if(!tcp_->wholeTileDecompress_)
1079+
{
1080+
try
1081+
{
1082+
tilec->allocRegionWindow(tilec->nextPacketProgressionState_.numResolutionsRead(),
1083+
truncated_);
1084+
}
1085+
catch([[maybe_unused]] const std::runtime_error& ex)
1086+
{
1087+
continue;
1088+
}
1089+
catch([[maybe_unused]] const std::bad_alloc& baex)
1090+
{
1091+
success_ = false;
1092+
return;
1093+
}
1094+
}
1095+
if(!tilec->getWindow()->alloc())
1096+
{
1097+
grklog.error("Not enough memory for tile data");
1098+
success_ = false;
1099+
return;
1100+
}
1101+
}
11251102
}
1126-
else
1103+
if(!scheduler_->schedule(this))
11271104
{
1128-
t2Parse();
1129-
allocAndSchedule();
1105+
success_ = false;
1106+
return;
11301107
}
1131-
}
1108+
};
11321109

11331110
if(ExecSingleton::num_threads() > 1)
11341111
{
1112+
if(!t2ParseFlow_)
1113+
t2ParseFlow_ = std::make_unique<FlowComponent>();
1114+
else
1115+
t2ParseFlow_->clear();
1116+
t2ParseFlow_->nextTask().work(t2Parse);
1117+
1118+
if(!allocAndScheduleFlow_)
1119+
allocAndScheduleFlow_ = std::make_unique<FlowComponent>();
1120+
else
1121+
allocAndScheduleFlow_->clear();
1122+
allocAndScheduleFlow_->nextTask().work(allocAndSchedule);
1123+
1124+
// 1. create root flow
11351125
if(!rootFlow_)
11361126
rootFlow_ = new FlowComponent();
11371127
else
11381128
rootFlow_->clear();
1139-
1140-
std::function<int()> condition_lambda = [this]() -> int { return hasError() ? 1 : 0; };
1141-
11421129
scheduler_->addTo(*rootFlow_);
11431130

1131+
// 2. schedule T2
1132+
1133+
std::function<int()> condition_lambda = [this]() -> int { return hasError() ? 1 : 0; };
11441134
allocAndScheduleFlow_->addTo(*rootFlow_);
11451135
allocAndScheduleFlow_->conditional_precede(rootFlow_, scheduler_, condition_lambda);
11461136

@@ -1156,18 +1146,21 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
11561146
tileHeaderParseFlow_->conditional_precede(rootFlow_, prepareFlow_.get(), condition_lambda);
11571147
}
11581148

1149+
// 3. schedule post decompression
11591150
if(!postDecompressFlow_)
11601151
postDecompressFlow_ = new FlowComponent();
11611152
else
11621153
postDecompressFlow_->clear();
11631154
postDecompressFlow_->nextTask().work(post);
11641155
postDecompressFlow_->addTo(*rootFlow_);
1165-
11661156
scheduler_->precede(*postDecompressFlow_);
1157+
11671158
futures.add(tileIndex_, ExecSingleton::get().run(*rootFlow_));
11681159
}
11691160
else
11701161
{
1162+
t2Parse();
1163+
allocAndSchedule();
11711164
post();
11721165
}
11731166
return true;

src/lib/core/util/GrkImage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "Quantizer.h"
2121
#include "Logger.h"
2222
#include "buffer.h"
23-
#include "GrkObjectWrapper.h">
23+
#include "GrkObjectWrapper.h"
2424
#include "SparseCanvas.h"
2525
#include "ImageComponentFlow.h"
2626
#include "IStream.h"

0 commit comments

Comments
 (0)