From fa50fef2975e1220fbf03d75acf0822b79a0ece1 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 17 Sep 2018 18:48:11 -0500 Subject: [PATCH] Introduce PYOPENCL_STACK_CONTAINER to dispatch VLA/std::vector for opposite compiler needs --- src/wrap_cl.hpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 1253c499..e25207c4 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -90,6 +90,15 @@ #endif +#if defined(_WIN32) +// MSVC does not understand variable-length arrays +#define PYOPENCL_STACK_CONTAINER(TYPE, NAME, COUNT) std::vector NAME(COUNT) +#define PYOPENCL_STACK_CONTAINER_GET_PTR(NAME) (name.size() ? name.data() : nullptr) +#else +// gcc et al complain about stripping attributes in template arguments +#define PYOPENCL_STACK_CONTAINER(TYPE, NAME, COUNT) TYPE NAME[COUNT] +#define PYOPENCL_STACK_CONTAINER_GET_PTR(NAME) NAME +#endif // }}} @@ -1363,7 +1372,7 @@ namespace pyopencl "may be a crash." << std:: endl; } - std::vector props(py::len(py_props) + 1); + PYOPENCL_STACK_CONTAINER(cl_queue_properties, props, py::len(py_props) + 1); { size_t i = 0; for (auto prop: py_props) @@ -1374,7 +1383,7 @@ namespace pyopencl cl_int status_code; PYOPENCL_PRINT_CALL_TRACE("clCreateCommandQueueWithProperties"); m_queue = clCreateCommandQueueWithProperties( - ctx.data(), dev, props.data(), &status_code); + ctx.data(), dev, PYOPENCL_STACK_CONTAINER_GET_PTR(props), &status_code); if (status_code != CL_SUCCESS) throw pyopencl::error("CommandQueue", status_code); @@ -3610,7 +3619,7 @@ namespace pyopencl "may be a crash." << std:: endl; } - std::vector props(py::len(py_props) + 1); + PYOPENCL_STACK_CONTAINER(cl_sampler_properties, props, py::len(py_props) + 1); { size_t i = 0; for (auto prop: py_props) @@ -3623,7 +3632,7 @@ namespace pyopencl m_sampler = clCreateSamplerWithProperties( ctx.data(), - props.data(), + PYOPENCL_STACK_CONTAINER_GET_PTR(props), &status_code); if (status_code != CL_SUCCESS) @@ -4005,7 +4014,7 @@ namespace pyopencl sizes.push_back(len); } - std::vector binary_statuses(num_devices); + PYOPENCL_STACK_CONTAINER(cl_int, binary_statuses, num_devices); cl_int status_code; PYOPENCL_PRINT_CALL_TRACE("clCreateProgramWithBinary"); @@ -4014,7 +4023,7 @@ namespace pyopencl devices.empty( ) ? nullptr : &devices.front(), sizes.empty( ) ? nullptr : &sizes.front(), binaries.empty( ) ? nullptr : &binaries.front(), - binary_statuses.data(), + PYOPENCL_STACK_CONTAINER_GET_PTR(binary_statuses), &status_code); if (status_code != CL_SUCCESS) throw pyopencl::error("clCreateProgramWithBinary", status_code); -- GitLab