Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from OSGeo:master #49

Merged
merged 94 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
21cb6b4
VSIFilesystemHandler: remove 'virtual' qualifier from ReadDir(), whic…
rouault Sep 6, 2023
cf27998
Add /vsicached? virtual file system, as another way of doing the same…
rouault Sep 6, 2023
183b77f
Add OGRFieldDefn::GetTZFlag()/SetTZFlag(), and OGR_TZFLAG_ constants
rouault Sep 23, 2023
0496737
ogrinfo: output timezone flag
rouault Sep 23, 2023
ce930bb
GeoJSON reading: set field TZFlag
rouault Sep 23, 2023
97889b6
ArrowStream interface: set timezone on schema (when known), and do ne…
rouault Sep 23, 2023
dce4b24
Arrow/Parquet reading: set field TZFlag
rouault Sep 23, 2023
3c1ca62
Arrow/Parquet writing: read field TZFlag
rouault Sep 23, 2023
6299428
Add OGRTimezoneToTZFlag() and OGRTZFlagToTimezone()
rouault Sep 24, 2023
3a071ca
ArrowStream interface: make TIMEZONE="unknown", "UTC", "(+|:)HH:MM" o…
rouault Sep 24, 2023
072e30f
Arrow/Parquet: on reading, set OGRFieldDefn::TZFlag to OGR_TZFLAG_UTC…
rouault Sep 24, 2023
ac75d43
gdalcompare.py: multiple enhancements
rouault Sep 27, 2023
4b10700
GDALDataset::ICreateLayer(): now takes a const OGRSpatialReference* i…
rouault Sep 29, 2023
78efa59
GPKG: declare OGR_GPKG_GeometryTypeAggregate_INTERNAL only when needed
rouault Oct 4, 2023
4d3c1d4
GPKG/SQLITE: declare relevant SQL functions as SQLITE_INNOCUOUS (refs…
rouault Oct 4, 2023
f9846d5
SQLite: turn PRAGMA trusted_schema = 1 when loading Spatialite (refs …
rouault Oct 4, 2023
6dfc963
Add OGRSQLiteRTreeRequiresTrustedSchemaOn() (refs #8514)
rouault Oct 4, 2023
b827f22
GPKG: turn PRAGMA trusted_schema = 1 if RTree+update mode or if views…
rouault Oct 4, 2023
4d6bb03
validate_gpkg.py: make it work with -DSQLITE_TRUSTED_SCHEMA=0 SQLite …
rouault Oct 4, 2023
b4755d9
CI: test with a sqlite3 build with -DSQLITE_TRUSTED_SCHEMA=0 (refs #8…
rouault Oct 4, 2023
e239d4e
Add a GDALPamDataset::SetDerivedDatasetName() method, and use it to b…
rouault Oct 5, 2023
24eec38
autotest/ogr/data/esrijson/: make valid json without trailing commas
rouault Oct 5, 2023
740d1aa
ESRIJSON: add support for esriFieldTypeSingle and esriFieldTypeDate d…
rouault Oct 5, 2023
4eba152
Doc: virtual_file_systems.rst: more precisions about CPL_VSIL_CURL_CH…
rouault Oct 6, 2023
1cacce3
/vsicurl/: emit warnings if invalid values of CPL_VSIL_CURL_CHUNK_SIZ…
rouault Oct 6, 2023
0adb0c5
Doc: RasterIO(): document how overviews are selected
rouault Oct 8, 2023
e63d4bf
Add OGRLayer::WriteArrowBatch()
rouault Oct 2, 2023
8984509
Add OGRWKBFixupCounterClockWiseExternalRing()
rouault Oct 3, 2023
c966382
Arrow/Parquet: implement WriteArrowBatch()
rouault Oct 3, 2023
498cf61
Add perftests/ogr2ogr_arrow.py
rouault Oct 3, 2023
79768eb
OGRFeature::FillUnsetWithDefault(): micro-optim
rouault Oct 3, 2023
0bcb959
GPKG CreateFeature(): micro-optimizations
rouault Oct 3, 2023
bd16a7c
Remove now unused SQLiteFieldFromOGR()
rouault Oct 4, 2023
d9e5754
Doc: add a 'Writing to OGR using the Arrow C Data interface' section
rouault Oct 4, 2023
87d0745
.github/workflows/ubuntu_20.04/Dockerfile.ci: add pyarrow
rouault Oct 5, 2023
5ac5022
.github/workflows/alpine/Dockerfile.ci: add apache-arrow-dev
rouault Oct 4, 2023
2b1d57a
WriteArrowBatch() generic implementation: support dictionary, by reso…
rouault Oct 5, 2023
f962662
ogr_mem.py: Add testing of WKB in large binary column
rouault Oct 5, 2023
a0d7dd0
WriteArrowBatch() generic implementation: support Decimal128/256 limi…
rouault Oct 5, 2023
6d114cf
PostFilterArrowArray(): add support for filtering on Decimal128 (if p…
rouault Oct 5, 2023
bd9b6ee
WriteArrowBatch() generic implementation: support list of Decimal128/256
rouault Oct 5, 2023
298a4e3
ogrlayerarrow.cpp: use symbolic constants for Arrow data types
rouault Oct 5, 2023
cf1769d
IsArrowSchemaSupported(), CreateFieldFromArrowSchema(), WriteArrowBat…
rouault Oct 6, 2023
75bb33e
WriteArrowBatch() generic implementation: support list and map of any…
rouault Oct 7, 2023
0fa2f17
OGRArrowLayer::GetArrowSchemaInternal() / FillValidityArrayFromAttrQu…
rouault Oct 7, 2023
149f959
.github/workflows/ubuntu_20.04/Dockerfile.ci: fix pyarrow
rouault Oct 7, 2023
109b077
IsArrowSchemaSupported(), CreateFieldFromArrowSchema(), WriteArrowBat…
rouault Oct 8, 2023
d482337
OGRFeature::GetFieldAsSerializedJSon(): take into account list of boo…
rouault Oct 8, 2023
809616a
OGRFeature::SetFrom(): add a bUseISO8601ForDateTimeAsString option
rouault Oct 8, 2023
53b52e4
OGRLayer::WriteArrowBatch(): use OGRFeature::SetFrom() bUseISO8601For…
rouault Oct 8, 2023
94453bb
ENVI: support Int64 and UInt64
rouault Oct 9, 2023
3404941
test_misc_5(): test Int8, Int64 and UInt64
rouault Oct 9, 2023
26bace1
gdal_translate: when specifying -srcwin, preserve source block size i…
rouault Oct 9, 2023
6141c38
OAPIF: make comparison of rel case insensitive to acount for describe…
rouault Oct 10, 2023
f3bb638
Doc: oapif.rst: mention we use describedby to establish the schema
rouault Oct 10, 2023
ba72918
Merge pull request #8531 from rouault/gdal_translate_preserve_block
rouault Oct 10, 2023
981f8e8
Merge pull request #8529 from rouault/envi_int64
rouault Oct 10, 2023
9301e3f
Merge pull request #8526 from rouault/doc_rasterio_overview
rouault Oct 10, 2023
207bb3e
Merge pull request #8521 from rouault/8499
rouault Oct 10, 2023
4288c3d
Merge pull request #8519 from rouault/esrijson_datetime
rouault Oct 10, 2023
6a3584b
Merge pull request #8518 from rouault/SetDerivedDatasetName
rouault Oct 10, 2023
b6f206e
OPENCL: scan multiple devices for each platform (#8537)
elpaso Oct 11, 2023
92f1934
Merge pull request #8351 from rouault/vsicached
rouault Oct 11, 2023
d2d399e
Merge pull request #8461 from rouault/fix_8460
rouault Oct 11, 2023
aafe9da
Merge pull request #8482 from rouault/gdalcompare_enhancements
rouault Oct 11, 2023
e499956
Merge pull request #8495 from rouault/fix_8493
rouault Oct 11, 2023
4ae8505
Merge pull request #8516 from rouault/fix_8514
rouault Oct 11, 2023
3dfcc31
Merge pull request #8517 from rouault/write_arrow_batch
rouault Oct 11, 2023
f3bc13d
Warper: ThreadFuncAdapter: make checks under mutex to avoid potential…
rouault Oct 11, 2023
0bafa8f
GDALSerializeReprojectionTransformer(): fallback to WKT2 for SourceCR…
rouault Oct 11, 2023
188e72a
OGRProjCT::TransformBounds(): do not emit errors when trying to repro…
rouault Oct 11, 2023
ed86608
OGRArrowWriterLayer::WriteArrowBatchInternal(): fix wrong offsets in …
rouault Oct 11, 2023
7ce8e00
test_ogr2ogr_lib.py: make test pass with CPL_DEBUG=ON
rouault Oct 11, 2023
f2b6fea
VSI7Z: Accept ArcGIS Pro Project Packages
arredond Oct 11, 2023
2aee0af
Fix cppcheck warnings
rouault Oct 11, 2023
c9072d7
OGR SQL: fix min/max on string fields (master only)
rouault Oct 11, 2023
13c5c52
Merge pull request #8547 from rouault/fix_min_max
rouault Oct 12, 2023
4a9d91c
Merge pull request #8545 from arredond/support-arcgis-pro-ppkx-files
rouault Oct 12, 2023
c70e1da
OGR2OGR: fix preserve_fid and explodecollections incompatible options…
elpaso Oct 12, 2023
7309472
Merge pull request #8542 from rouault/reprojection_fixes
rouault Oct 12, 2023
501bef9
ogr2ogr: use Arrow interface in reading and writing when possible
rouault Oct 11, 2023
e6baccb
API: add GDALGetSubdatasetInfo() and related functions (#8155)
elpaso Oct 12, 2023
0f8bb8d
FlatGeoBuf: make GetNextArrowArray() capable of dealing with attribut…
rouault Oct 12, 2023
57d59bd
Fix build with libparquet v10 (master only)
rouault Oct 12, 2023
20df18a
Fix potential memleaks related to sqlite3_open() failure (fixes #8554)
rouault Oct 12, 2023
2142523
Merge pull request #8544 from rouault/ogr2ogr_arrow
rouault Oct 12, 2023
f3e0e8d
Merge pull request #8555 from rouault/fix_8554
rouault Oct 12, 2023
8472895
Merge pull request #8553 from rouault/flatgeobuf_GetNextArrowArray_at…
rouault Oct 12, 2023
b25706e
GeoJSON & GeoJSONSeq: use faster file write() primitive and detect wr…
rouault Oct 12, 2023
134842b
FlatGeoBuf:: ICreateFeature(): reuse temporary buffer
rouault Oct 13, 2023
8af9e10
PGDump: use faster file write() primitive
rouault Oct 13, 2023
2cfeb1a
Merge pull request #8556 from rouault/geojson_write
rouault Oct 13, 2023
2f780d7
jpeg.rst: Fix typo for bitmask: `valid date` → `valid data` [ci skip]
schwehr Oct 13, 2023
1ce1fb4
Merge pull request #8559 from schwehr/jpeg-rst-type
rouault Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/alpine/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ RUN apk add \
qhull-dev \
unixodbc-dev \
libpq-dev \
apache-arrow-dev \
py3-pyarrow py3-pyarrow-pyc \
libxml2-dev \
podofo-dev

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/coverage/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cmake ${GDAL_SOURCE_DIR:=..} \
-DGDAL_USE_GEOTIFF_INTERNAL=ON \
-DECW_ROOT=/opt/libecwj2-3.3 \
-DMRSID_ROOT=/usr/local \
-DFileGDB_ROOT=/usr/local/FileGDB_API
-DFileGDB_ROOT=/usr/local/FileGDB_API \
-DSQLite3_INCLUDE_DIR=/usr/local/install-sqlite-trusted-schema-off/include \
-DSQLite3_LIBRARY=/usr/local/install-sqlite-trusted-schema-off/lib/libsqlite3.so

make -j$(nproc)
15 changes: 14 additions & 1 deletion .github/workflows/ubuntu_20.04/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ RUN mkdir odbc-cpp-wrapper \
&& rm -rf odbc-cpp-wrapper

# Arrow
# We should perhaps pin the pyarrow version to the one of libarrow...
# Actually not: the libarrow embedded in pyarrow 13 doesn't work with libarrow 13 linked from GDAL...
RUN wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb \
&& dpkg --install apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb \
&& apt-get update \
&& apt-get install -y -V libarrow-dev libparquet-dev libarrow-dataset-dev \
&& rm ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& python3 -m pip install pyarrow==11.0.0

# Build libQB3
# Used by the MRF driver
Expand All @@ -243,6 +246,16 @@ RUN git clone -b cmake https://github.com/rouault/basis_universal.git \
&& cd ../..\
&& rm -rf basis_universal

# Build a SQLite version with -DSQLITE_TRUSTED_SCHEMA=0
RUN mkdir sqlite \
&& wget -q https://sqlite.org/2023/sqlite-autoconf-3430100.tar.gz -O - \
| tar xz -C sqlite --strip-components=1 \
&& cd sqlite \
&& CFLAGS="-O2 -DSQLITE_TRUSTED_SCHEMA=0 -DSQLITE_ENABLE_COLUMN_METADATA" ./configure --prefix=/usr/local/install-sqlite-trusted-schema-off \
&& make -j$(nproc) \
&& make -j$(nproc) install \
&& cd .. \
&& rm -rf sqlite

RUN ldconfig

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ubuntu_20.04/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ cmake ${GDAL_SOURCE_DIR:=..} \
-DGDAL_USE_GEOTIFF_INTERNAL=ON \
-DECW_ROOT=/opt/libecwj2-3.3 \
-DMRSID_ROOT=/usr/local \
-DFileGDB_ROOT=/usr/local/FileGDB_API
-DFileGDB_ROOT=/usr/local/FileGDB_API \
-DSQLite3_INCLUDE_DIR=/usr/local/install-sqlite-trusted-schema-off/include \
-DSQLite3_LIBRARY=/usr/local/install-sqlite-trusted-schema-off/lib/libsqlite3.so

unset CXXFLAGS
unset CFLAGS
Expand Down
8 changes: 8 additions & 0 deletions MIGRATION_GUIDE.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
MIGRATION GUIDE FROM GDAL 3.7 to GDAL 3.8
-----------------------------------------

- Out-of-tree vector drivers:
* GDALDataset::ICreateLayer() now takes a const OGRSpatialReference* instead
of a OGRSpatialReference*. Drivers should clone the passed SRS if they need
to keep it.

MIGRATION GUIDE FROM GDAL 3.6 to GDAL 3.7
-----------------------------------------

Expand Down
39 changes: 32 additions & 7 deletions alg/gdaltransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3504,14 +3504,40 @@ static CPLXMLNode *GDALSerializeReprojectionTransformer(void *pTransformArg)
/* -------------------------------------------------------------------- */
/* Handle SourceCS. */
/* -------------------------------------------------------------------- */
char *pszWKT = nullptr;
const auto ExportToWkt = [](const OGRSpatialReference *poSRS)
{
// Try first in WKT1 for backward compat
{
char *pszWKT = nullptr;
const char *const apszOptions[] = {"FORMAT=WKT1", nullptr};
CPLErrorHandlerPusher oHandler(CPLQuietErrorHandler);
CPLErrorStateBackuper oBackuper;
if (poSRS->exportToWkt(&pszWKT, apszOptions) == OGRERR_NONE)
{
std::string osRet(pszWKT);
CPLFree(pszWKT);
return osRet;
}
CPLFree(pszWKT);
}

char *pszWKT = nullptr;
const char *const apszOptions[] = {"FORMAT=WKT2_2019", nullptr};
if (poSRS->exportToWkt(&pszWKT, apszOptions) == OGRERR_NONE)
{
std::string osRet(pszWKT);
CPLFree(pszWKT);
return osRet;
}
CPLFree(pszWKT);
return std::string();
};

auto poSRS = psInfo->poForwardTransform->GetSourceCS();
if (poSRS)
{
poSRS->exportToWkt(&pszWKT);
CPLCreateXMLElementAndValue(psTree, "SourceSRS", pszWKT);
CPLFree(pszWKT);
const auto osWKT = ExportToWkt(poSRS);
CPLCreateXMLElementAndValue(psTree, "SourceSRS", osWKT.c_str());
}

/* -------------------------------------------------------------------- */
Expand All @@ -3520,9 +3546,8 @@ static CPLXMLNode *GDALSerializeReprojectionTransformer(void *pTransformArg)
poSRS = psInfo->poForwardTransform->GetTargetCS();
if (poSRS)
{
poSRS->exportToWkt(&pszWKT);
CPLCreateXMLElementAndValue(psTree, "TargetSRS", pszWKT);
CPLFree(pszWKT);
const auto osWKT = ExportToWkt(poSRS);
CPLCreateXMLElementAndValue(psTree, "TargetSRS", osWKT.c_str());
}

/* -------------------------------------------------------------------- */
Expand Down
9 changes: 6 additions & 3 deletions alg/gdalwarpkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,17 @@ static void ThreadFuncAdapter(void *pData)
psThreadData->mapThreadToTransformerArg[nThreadId] =
pTransformerArg;
}

if (pTransformerArg == nullptr)
{
CPLAssert(psThreadData->pTransformerArgInput != nullptr);
CPLAssert(!psThreadData->bTransformerArgInputAssignedToThread);
}
}

// If no transformer assigned to current thread, instantiate one
if (pTransformerArg == nullptr)
{
CPLAssert(psThreadData->pTransformerArgInput != nullptr);
CPLAssert(!psThreadData->bTransformerArgInputAssignedToThread);

// This somehow assumes that GDALCloneTransformer() is thread-safe
// which should normally be the case.
pTransformerArg =
Expand Down
175 changes: 97 additions & 78 deletions alg/gdalwarpkernel_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#include <algorithm>
#if defined(HAVE_OPENCL)

/* The following line may be uncommented for increased debugging traces and
Expand Down Expand Up @@ -294,11 +295,10 @@ static cl_device_id get_device(OCLVendor *peVendor)
size_t returned_size = 0;
cl_char vendor_name[1024] = {0};
cl_char device_name[1024] = {0};
cl_device_type device_type;

std::vector<cl_platform_id> platforms;
cl_uint num_platforms = 0;
cl_device_id preferred_device_id = nullptr;
int preferred_is_gpu = FALSE;

static bool gbBuggyOpenCL = false;
if (gbBuggyOpenCL)
Expand All @@ -323,110 +323,129 @@ static cl_device_id get_device(OCLVendor *peVendor)
return nullptr;
}

bool bUseOpenCLCPU =
const bool bUseOpenCLCPU =
CPLTestBool(CPLGetConfigOption("OPENCL_USE_CPU", "FALSE"));

// In case we have several implementations, pick up the non Intel one by
// default, unless the PREFERRED_OPENCL_VENDOR config option is specified.
for (cl_uint i = 0; i < num_platforms; i++)
{
cl_device_id device = nullptr;
const char *pszBlacklistedVendor;
const char *pszPreferredVendor;
int is_gpu;
const char *pszBlacklistedVendor = "";
const char *pszPreferredVendor = "";

// Find the GPU CL device, this is what we really want
// If there is no GPU device is CL capable, fall back to CPU
if (bUseOpenCLCPU)
err = CL_DEVICE_NOT_FOUND;
else
err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, 1, &device,
nullptr);
is_gpu = (err == CL_SUCCESS);
if (err != CL_SUCCESS)
{
// Find the CPU CL device, as a fallback
err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_CPU, 1, &device,
nullptr);
if (err != CL_SUCCESS || device == nullptr)
continue;
}
struct device_info
{
cl_device_id id;
cl_device_type device_type;
std::string vendor_name;
std::string device_name;
};

// Get some information about the returned device
err = clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(vendor_name),
vendor_name, &returned_size);
err |= clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, &returned_size);
assert(err == CL_SUCCESS);
std::vector<device_info> openCLdevices;

if (num_platforms > 1)
CPLDebug("OpenCL",
"Found vendor='%s' / device='%s' (%s implementation).",
vendor_name, device_name, (is_gpu) ? "GPU" : "CPU");
// In case we have several implementations, pick up the non Intel one by
// default, unless the PREFERRED_OPENCL_VENDOR config option is specified.
if (num_platforms > 0)
{

pszPreferredVendor =
CPLGetConfigOption("PREFERRED_OPENCL_VENDOR", nullptr);
pszBlacklistedVendor =
CPLGetConfigOption("BLACKLISTED_OPENCL_VENDOR", nullptr);
if (pszBlacklistedVendor &&
EQUAL(reinterpret_cast<const char *>(vendor_name),
pszBlacklistedVendor))
{
CPLDebug(
"OpenCL",
"Blacklisted vendor='%s' / device='%s' implementation skipped",
vendor_name, device_name);
continue;
}

if (preferred_device_id == nullptr || (is_gpu && !preferred_is_gpu))
for (cl_uint platformIndex = 0; platformIndex < num_platforms;
platformIndex++)
{
preferred_device_id = device;
preferred_is_gpu = is_gpu;
}

pszPreferredVendor =
CPLGetConfigOption("PREFERRED_OPENCL_VENDOR", nullptr);
if (pszPreferredVendor)
{
if (EQUAL(reinterpret_cast<const char *>(vendor_name),
pszPreferredVendor))
constexpr int max_devices{20};
cl_uint num_devices;
cl_device_id devices[max_devices];
err = clGetDeviceIDs(platforms[platformIndex],
bUseOpenCLCPU
? CL_DEVICE_TYPE_CPU
: CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU,
max_devices, devices, &num_devices);

if (err != CL_SUCCESS)
{
preferred_device_id = device;
preferred_is_gpu = is_gpu;
break;
continue;
}

cl_device_id device = nullptr;

for (cl_uint deviceIndex = 0; deviceIndex < num_devices;
++deviceIndex)
{

device = devices[deviceIndex];
err = clGetDeviceInfo(device, CL_DEVICE_VENDOR,
sizeof(vendor_name), vendor_name,
&returned_size);
err |=
clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, &returned_size);
err |=
clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(device_type),
&device_type, &returned_size);
assert(err == CL_SUCCESS);
if (pszBlacklistedVendor &&
EQUAL(reinterpret_cast<const char *>(vendor_name),
pszBlacklistedVendor))
{
CPLDebug("OpenCL",
"Blacklisted vendor='%s' / device='%s' "
"implementation skipped",
vendor_name, device_name);
}
else
{
CPLDebug(
"OpenCL",
"Found vendor='%s' / device='%s' (%s implementation).",
vendor_name, device_name,
(device_type == CL_DEVICE_TYPE_GPU) ? "GPU" : "CPU");
openCLdevices.push_back(
{device, device_type,
reinterpret_cast<const char *>(vendor_name),
reinterpret_cast<const char *>(device_name)});
}
}
}
else if (is_gpu &&
!STARTS_WITH(reinterpret_cast<const char *>(vendor_name),
"Intel"))
{
preferred_device_id = device;
preferred_is_gpu = is_gpu;
break;
}
}
if (preferred_device_id == nullptr)

if (!openCLdevices.empty())
{
// Sort, GPU first, then preferred vendor, Intel comes last (unless is the preferred of course)
const std::string preferredVendorName{pszPreferredVendor};
std::sort(
openCLdevices.begin(), openCLdevices.end(),
[&](const device_info first, const device_info second) -> int
{
return (first.device_type == CL_DEVICE_TYPE_GPU ? 4 : 0) +
(first.vendor_name == preferredVendorName ? 2 : 0) +
(first.vendor_name.find("Intel") == 0 ? 0 : 1) >
(second.device_type == CL_DEVICE_TYPE_GPU ? 4 : 0) +
(second.vendor_name == preferredVendorName ? 2 : 0) +
(second.vendor_name.find("Intel") == 0 ? 0 : 1);
});
}
else
{
CPLDebug("OpenCL", "No implementation found");
return nullptr;
}

err = clGetDeviceInfo(preferred_device_id, CL_DEVICE_VENDOR,
sizeof(vendor_name), vendor_name, &returned_size);
err |= clGetDeviceInfo(preferred_device_id, CL_DEVICE_NAME,
sizeof(device_name), device_name, &returned_size);
const device_info &device{openCLdevices.front()};

CPLDebug("OpenCL",
"Connected to vendor='%s' / device='%s' (%s implementation).",
vendor_name, device_name, (preferred_is_gpu) ? "GPU" : "CPU");
device.vendor_name.c_str(), device.device_name.c_str(),
(device.device_type == CL_DEVICE_TYPE_GPU) ? "GPU" : "CPU");

if (STARTS_WITH(reinterpret_cast<const char *>(vendor_name),
"Advanced Micro Devices"))
if (STARTS_WITH(device.vendor_name.c_str(), "Advanced Micro Devices"))
*peVendor = VENDOR_AMD;
else if (STARTS_WITH(reinterpret_cast<const char *>(vendor_name), "Intel"))
else if (STARTS_WITH(device.vendor_name.c_str(), "Intel"))
*peVendor = VENDOR_INTEL;
else
*peVendor = VENDOR_OTHER;

return preferred_device_id;
return device.id;
}

/*
Expand Down
Loading