diff options
author | Gian-Carlo Pascutto <gcp@sjeng.org> | 2016-06-30 23:57:11 +0200 |
---|---|---|
committer | Gian-Carlo Pascutto <gcp@sjeng.org> | 2016-07-02 21:14:36 +0200 |
commit | 7424532859ff91321da56a72ae1e9195a059a351 (patch) | |
tree | 58adc005b95c441f5e0d27f18424de5b93245918 /src | |
parent | 5a690f4e36ea50d5401ba37d013ef425a98f2542 (diff) |
Ensure clGetKernelWorkGroupInfo return value fits.
In LocalMemUsage(), there's a first call to clGetKernelWorkGroupInfo
to get the "bytes" amount needed to store the result from
CL_KERNEL_LOCAL_MEM_SIZE. However, the actual value passed is an
"auto result = size_t", which in 32-bit mode is 4 bytes, regardless
of the previous return value. The spec describes that it will actually
be a cl_ulong which is 8 bytes. To prevent stack corruption, make sure
we are in fact passing a cl_ulong.
Also adjust all callers to take the changed type into account.
Diffstat (limited to 'src')
-rw-r--r-- | src/clpp11.hpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp index 1eeaf702..2b21e1e1 100644 --- a/src/clpp11.hpp +++ b/src/clpp11.hpp @@ -199,8 +199,8 @@ class Device { std::vector<size_t> MaxWorkItemSizes() const { return GetInfoVector<size_t>(CL_DEVICE_MAX_WORK_ITEM_SIZES); } - size_t LocalMemSize() const { - return static_cast<size_t>(GetInfo<cl_ulong>(CL_DEVICE_LOCAL_MEM_SIZE)); + cl_ulong LocalMemSize() const { + return GetInfo<cl_ulong>(CL_DEVICE_LOCAL_MEM_SIZE); } std::string Capabilities() const { return GetInfoString(CL_DEVICE_EXTENSIONS); } size_t CoreClock() const { return GetInfo(CL_DEVICE_MAX_CLOCK_FREQUENCY); } @@ -211,7 +211,7 @@ class Device { size_t MemoryBusWidth() const { return 0; } // Not exposed in OpenCL // Configuration-validity checks - bool IsLocalMemoryValid(const size_t local_mem_usage) const { + bool IsLocalMemoryValid(const cl_ulong local_mem_usage) const { return (local_mem_usage <= LocalMemSize()); } bool IsThreadConfigValid(const std::vector<size_t> &local) const { @@ -655,11 +655,11 @@ class Kernel { } // Retrieves the amount of local memory used per work-group for this kernel - size_t LocalMemUsage(const Device &device) const { + cl_ulong LocalMemUsage(const Device &device) const { auto bytes = size_t{0}; auto query = cl_kernel_work_group_info{CL_KERNEL_LOCAL_MEM_SIZE}; CheckError(clGetKernelWorkGroupInfo(*kernel_, device(), query, 0, nullptr, &bytes)); - auto result = size_t{0}; + auto result = cl_ulong{0}; CheckError(clGetKernelWorkGroupInfo(*kernel_, device(), query, bytes, &result, nullptr)); return result; } |