Hash :
2c8d9a9a
Author :
Date :
2021-06-09T16:09:35
CL: Remaining functions for OpenCL 1.2 Add support for the remaining functions for OpenCL 1.2 for the front end and pass-through back end. Also fix several bugs discovered by the conformance tests. Bug: angleproject:6015 Change-Id: I1dca1c3f4c1d9aea7f0501094c171116ea01381f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2954259 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: John Plate <jplate@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CLProgramCL.cpp: Implements the class methods for CLProgramCL.
#include "libANGLE/renderer/cl/CLProgramCL.h"
#include "libANGLE/renderer/cl/CLDeviceCL.h"
#include "libANGLE/renderer/cl/CLKernelCL.h"
#include "libANGLE/CLDevice.h"
#include "libANGLE/CLProgram.h"
namespace rx
{
CLProgramCL::CLProgramCL(const cl::Program &program, cl_program native)
: CLProgramImpl(program), mNative(native)
{}
CLProgramCL::~CLProgramCL()
{
if (mNative->getDispatch().clReleaseProgram(mNative) != CL_SUCCESS)
{
ERR() << "Error while releasing CL program";
}
}
std::string CLProgramCL::getSource(cl_int &errorCode) const
{
size_t size = 0u;
errorCode =
mNative->getDispatch().clGetProgramInfo(mNative, CL_PROGRAM_SOURCE, 0u, nullptr, &size);
if (errorCode == CL_SUCCESS)
{
if (size != 0u)
{
std::vector<char> valString(size, '\0');
errorCode = mNative->getDispatch().clGetProgramInfo(mNative, CL_PROGRAM_SOURCE, size,
valString.data(), nullptr);
if (errorCode == CL_SUCCESS)
{
return std::string(valString.data(), valString.size() - 1u);
}
}
}
return std::string{};
}
cl_int CLProgramCL::build(const cl::DevicePtrs &devices, const char *options, cl::Program *notify)
{
std::vector<cl_device_id> nativeDevices;
for (const cl::DevicePtr &device : devices)
{
nativeDevices.emplace_back(device->getImpl<CLDeviceCL>().getNative());
}
const cl_uint numDevices = static_cast<cl_uint>(nativeDevices.size());
const cl_device_id *const nativeDevicesPtr =
!nativeDevices.empty() ? nativeDevices.data() : nullptr;
const cl::ProgramCB callback = notify != nullptr ? Callback : nullptr;
return mNative->getDispatch().clBuildProgram(mNative, numDevices, nativeDevicesPtr, options,
callback, notify);
}
cl_int CLProgramCL::compile(const cl::DevicePtrs &devices,
const char *options,
const cl::ProgramPtrs &inputHeaders,
const char **headerIncludeNames,
cl::Program *notify)
{
std::vector<cl_device_id> nativeDevices;
for (const cl::DevicePtr &device : devices)
{
nativeDevices.emplace_back(device->getImpl<CLDeviceCL>().getNative());
}
const cl_uint numDevices = static_cast<cl_uint>(nativeDevices.size());
const cl_device_id *const nativeDevicesPtr =
!nativeDevices.empty() ? nativeDevices.data() : nullptr;
std::vector<cl_program> nativePrograms;
for (const cl::ProgramPtr &program : inputHeaders)
{
nativePrograms.emplace_back(program->getImpl<CLProgramCL>().getNative());
}
const cl_uint numInputHeaders = static_cast<cl_uint>(nativePrograms.size());
const cl_program *const inputHeadersPtr =
!nativePrograms.empty() ? nativePrograms.data() : nullptr;
const cl::ProgramCB callback = notify != nullptr ? Callback : nullptr;
return mNative->getDispatch().clCompileProgram(mNative, numDevices, nativeDevicesPtr, options,
numInputHeaders, inputHeadersPtr,
headerIncludeNames, callback, notify);
}
cl_int CLProgramCL::getInfo(cl::ProgramInfo name,
size_t valueSize,
void *value,
size_t *valueSizeRet) const
{
return mNative->getDispatch().clGetProgramInfo(mNative, cl::ToCLenum(name), valueSize, value,
valueSizeRet);
}
cl_int CLProgramCL::getBuildInfo(const cl::Device &device,
cl::ProgramBuildInfo name,
size_t valueSize,
void *value,
size_t *valueSizeRet) const
{
return mNative->getDispatch().clGetProgramBuildInfo(
mNative, device.getImpl<CLDeviceCL>().getNative(), cl::ToCLenum(name), valueSize, value,
valueSizeRet);
}
CLKernelImpl::Ptr CLProgramCL::createKernel(const cl::Kernel &kernel,
const char *name,
cl_int &errorCode)
{
const cl_kernel nativeKernel = mNative->getDispatch().clCreateKernel(mNative, name, &errorCode);
return CLKernelImpl::Ptr(nativeKernel != nullptr ? new CLKernelCL(kernel, nativeKernel)
: nullptr);
}
cl_int CLProgramCL::createKernels(cl_uint numKernels,
CLKernelImpl::CreateFuncs &createFuncs,
cl_uint *numKernelsRet)
{
if (numKernels == 0u)
{
return mNative->getDispatch().clCreateKernelsInProgram(mNative, 0u, nullptr, numKernelsRet);
}
std::vector<cl_kernel> nativeKernels(numKernels, nullptr);
const cl_int errorCode = mNative->getDispatch().clCreateKernelsInProgram(
mNative, numKernels, nativeKernels.data(), numKernelsRet);
if (errorCode == CL_SUCCESS)
{
for (cl_kernel nativeKernel : nativeKernels)
{
createFuncs.emplace_back([nativeKernel](const cl::Kernel &kernel) {
return CLKernelImpl::Ptr(new CLKernelCL(kernel, nativeKernel));
});
}
}
return errorCode;
}
void CLProgramCL::Callback(cl_program program, void *userData)
{
static_cast<cl::Program *>(userData)->callback();
}
} // namespace rx