Skip to content

Commit 79f0ead

Browse files
committed
Added context
1 parent 4756873 commit 79f0ead

File tree

1 file changed

+5
-194
lines changed

1 file changed

+5
-194
lines changed

src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 5 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,9 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
5757
.arg( openClProgramBaseName( ) ), QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Info );
5858
return processRasterGPU( source, feedback );
5959
}
60-
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
6160
catch ( cl::Error &e )
6261
{
6362
QString err = QObject::tr( "Error running OpenCL program: %1 - %2" ).arg( e.what( ) ).arg( QgsOpenClUtils::errorText( e.err( ) ) );
64-
=======
65-
catch ( cl::BuildError &e )
66-
{
67-
cl::BuildLogType build_logs = e.getBuildLog();
68-
QString build_log;
69-
if ( build_logs.size() > 0 )
70-
build_log = QString::fromStdString( build_logs[0].second );
71-
else
72-
build_log = QObject::tr( "Build logs not available!" );
73-
QString err = QObject::tr( "Error building OpenCL program: %1" )
74-
.arg( build_log );
75-
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
76-
throw QgsProcessingException( err );
77-
}
78-
catch ( cl::Error &e )
79-
{
80-
QString err = QObject::tr( "Error %1 running OpenCL program in %2" )
81-
.arg( QgsOpenClUtils::errorText( e.err() ), QString::fromStdString( e.what() ) );
82-
>>>>>>> Try to avoid crash on intel haswell
8363
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
8464
throw QgsProcessingException( err );
8565
}
@@ -235,21 +215,9 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
235215
return 6;
236216
}
237217

238-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
239218
// Prepare context and queue
240219
cl::Context ctx = QgsOpenClUtils::context();
241220
cl::CommandQueue queue( ctx );
242-
=======
243-
//keep only three scanlines in memory at a time, make room for initial and final nodata
244-
QgsOpenClUtils::CPLAllocator<float> scanLine1( xSize + 2 );
245-
QgsOpenClUtils::CPLAllocator<float> scanLine2( xSize + 2 );
246-
QgsOpenClUtils::CPLAllocator<float> scanLine3( xSize + 2 );
247-
//float *scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
248-
//float *scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
249-
250-
//float *resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
251-
QgsOpenClUtils::CPLAllocator<float> resultLine( xSize );
252-
>>>>>>> CPLAllocator smart wrapper
253221

254222
//keep only three scanlines in memory at a time, make room for initial and final nodata
255223
QgsOpenClUtils::CPLAllocator<float> scanLine( xSize + 2 );
@@ -268,8 +236,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
268236
// used to pass additional args to opencl program
269237
addExtraRasterParams( rasterParams );
270238

271-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
272-
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
273239
std::size_t bufferSize( sizeof( float ) * ( xSize + 2 ) );
274240
std::size_t inputSize( sizeof( float ) * ( xSize ) );
275241

@@ -297,43 +263,17 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
297263

298264
// values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
299265
for ( int i = 0; i < ySize; ++i )
300-
=======
301-
try
302-
>>>>>>> Try to avoid crash on intel haswell
303-
{
304-
=======
305-
>>>>>>> CPLAllocator smart wrapper
306-
307-
cl::Buffer rasterParamsBuffer( rasterParams.begin(), rasterParams.end(), true, false, &errorCode );
308-
cl::Buffer scanLine1Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
309-
cl::Buffer scanLine2Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
310-
cl::Buffer scanLine3Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
311-
cl::Buffer resultLineBuffer( CL_MEM_WRITE_ONLY, sizeof( float ) * xSize, nullptr, &errorCode );
312-
313-
// Create a program from the kernel source
314-
cl::Program program( source.toStdString() );
315-
// Use CL 1.1 for compatibility with older libs
316-
program.build( "-cl-std=CL1.1" );
317-
318-
// Create the OpenCL kernel
319-
auto kernel = cl::KernelFunctor <
320-
cl::Buffer &,
321-
cl::Buffer &,
322-
cl::Buffer &,
323-
cl::Buffer &,
324-
cl::Buffer &
325-
> ( program, "processNineCellWindow" );
326-
327-
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
328-
for ( int i = 0; i < ySize; ++i )
329266
{
330267
if ( feedback && feedback->isCanceled() )
331268
{
332269
break;
333270
}
334271

335-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
336-
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
272+
if ( feedback )
273+
{
274+
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
275+
}
276+
337277
if ( i == 0 )
338278
{
339279
// Fill scanline 1 with (input) nodata for the values above the first row and
@@ -346,35 +286,9 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
346286

347287
// Read scanline2: first real raster row
348288
if ( GDALRasterIO( rasterBand, GF_Read, 0, i, xSize, 1, &scanLine[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
349-
=======
350-
if ( feedback )
351-
{
352-
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
353-
}
354-
355-
if ( i == 0 )
356-
>>>>>>> Try to avoid crash on intel haswell
357-
=======
358-
if ( feedback )
359-
{
360-
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
361-
}
362-
363-
if ( i == 0 )
364-
{
365-
//fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
366-
for ( int a = 0; a < xSize + 2 ; ++a )
367-
>>>>>>> CPLAllocator smart wrapper
368-
{
369-
scanLine1[a] = mInputNodataValue;
370-
}
371-
// Read scanline2
372-
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, &scanLine2[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
373289
{
374290
QgsDebugMsg( "Raster IO Error" );
375291
}
376-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
377-
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
378292
queue.enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0, bufferSize, scanLine.get() );
379293

380294
// Read scanline3: second real raster row
@@ -389,69 +303,13 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
389303
// Normally fetch only scanLine3 and move forward one row
390304
// Read scanline 3, fill the last row with nodata values if it's the last iteration
391305
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
392-
=======
393-
=======
394-
}
395-
else
396-
{
397-
//normally fetch only scanLine3 and release scanline 1 if we move forward one row
398-
//scanLine1 = scanLine2;
399-
//scanLine2 = scanLine3;
400-
//scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
401-
scanLine1.reset( scanLine2.release() );
402-
scanLine2.reset( scanLine3.release() );
403-
scanLine3.reset( xSize + 2 );
404-
}
405-
>>>>>>> CPLAllocator smart wrapper
406-
407-
// Read scanline 3
408-
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
409-
{
410-
for ( int a = 0; a < xSize + 2; ++a )
411-
{
412-
scanLine3[a] = mInputNodataValue;
413-
}
414-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
415-
// Set first and last extra colums to nodata
416-
scanLine1[0] = scanLine1[xSize + 1] = mInputNodataValue;
417-
scanLine2[0] = scanLine2[xSize + 1] = mInputNodataValue;
418-
scanLine3[0] = scanLine3[xSize + 1] = mInputNodataValue;
419-
420-
errorCode = cl::enqueueWriteBuffer( scanLine1Buffer, CL_TRUE, 0,
421-
sizeof( float ) * ( xSize + 2 ), scanLine1 );
422-
errorCode = cl::enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0,
423-
sizeof( float ) * ( xSize + 2 ), scanLine2 );
424-
errorCode = cl::enqueueWriteBuffer( scanLine3Buffer, CL_TRUE, 0,
425-
sizeof( float ) * ( xSize + 2 ), scanLine3 );
426-
427-
kernel( cl::EnqueueArgs(
428-
cl::NDRange( xSize )
429-
),
430-
scanLine1Buffer,
431-
scanLine2Buffer,
432-
scanLine3Buffer,
433-
resultLineBuffer,
434-
rasterParamsBuffer
435-
);
436-
437-
cl::enqueueReadBuffer( resultLineBuffer, CL_TRUE, 0, xSize * sizeof( float ), resultLine );
438-
439-
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
440-
>>>>>>> Try to avoid crash on intel haswell
441-
=======
442-
}
443-
else
444-
{
445-
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, &scanLine3[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
446-
>>>>>>> CPLAllocator smart wrapper
447306
{
448307
for ( int a = 0; a < xSize + 2; ++a )
449308
{
450309
scanLine[a] = mInputNodataValue;
451310
}
452311
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
453312
}
454-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
455313
else // Read line i + 1 and put it into scanline 3
456314
// Overwrite from input, skip first and last
457315
{
@@ -461,7 +319,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
461319
}
462320
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
463321
}
464-
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
465322
}
466323

467324
kernel( cl::EnqueueArgs(
@@ -482,54 +339,8 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
482339
QgsDebugMsg( "Raster IO Error" );
483340
}
484341
std::rotate( rowIndex.begin(), rowIndex.begin() + 1, rowIndex.end() );
485-
=======
486-
=======
487-
}
488-
// Set first and last extra colums to nodata
489-
scanLine1[0] = scanLine1[xSize + 1] = mInputNodataValue;
490-
scanLine2[0] = scanLine2[xSize + 1] = mInputNodataValue;
491-
scanLine3[0] = scanLine3[xSize + 1] = mInputNodataValue;
492-
>>>>>>> CPLAllocator smart wrapper
493-
494-
errorCode = cl::enqueueWriteBuffer( scanLine1Buffer, CL_TRUE, 0,
495-
sizeof( float ) * ( xSize + 2 ), scanLine1.get() );
496-
errorCode = cl::enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0,
497-
sizeof( float ) * ( xSize + 2 ), scanLine2.get() );
498-
errorCode = cl::enqueueWriteBuffer( scanLine3Buffer, CL_TRUE, 0,
499-
sizeof( float ) * ( xSize + 2 ), scanLine3.get() );
500-
501-
kernel( cl::EnqueueArgs(
502-
cl::NDRange( xSize )
503-
),
504-
scanLine1Buffer,
505-
scanLine2Buffer,
506-
scanLine3Buffer,
507-
resultLineBuffer,
508-
rasterParamsBuffer
509-
);
510-
511-
cl::enqueueReadBuffer( resultLineBuffer, CL_TRUE, 0, xSize * sizeof( float ), resultLine.get() );
512-
513-
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine.get(), xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
514-
{
515-
QgsDebugMsg( "Raster IO Error" );
516-
}
517-
}
518-
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
519-
catch ( cl::Error &e )
520-
{
521-
CPLFree( resultLine );
522-
CPLFree( scanLine1 );
523-
CPLFree( scanLine2 );
524-
CPLFree( scanLine3 );
525-
throw e;
526-
>>>>>>> Try to avoid crash on intel haswell
527342
}
528343

529-
=======
530-
531-
532-
>>>>>>> CPLAllocator smart wrapper
533344
if ( feedback && feedback->isCanceled() )
534345
{
535346
//delete the dataset without closing (because it is faster)

0 commit comments

Comments
 (0)