Hash :
d4abe622
Author :
Date :
2024-04-03T17:46:38
CL/VK: Implement enqueue NDRangeKernel & Task Adding support for: clEnqueueNDRangeKernel clEnqueueTask Bug: angleproject:8631 Change-Id: If57002be3ea00a55215e89ca47ab8fe9a422c6e7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5406614 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Austin Annestrand <a.annestrand@samsung.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
//
// 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.
//
// CLKernelVk.cpp: Implements the class methods for CLKernelVk.
#include "libANGLE/renderer/vulkan/CLKernelVk.h"
#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/CLDeviceVk.h"
#include "libANGLE/renderer/vulkan/CLProgramVk.h"
#include "libANGLE/CLContext.h"
#include "libANGLE/CLKernel.h"
#include "libANGLE/CLProgram.h"
#include "libANGLE/cl_utils.h"
namespace rx
{
CLKernelVk::CLKernelVk(const cl::Kernel &kernel,
std::string &name,
std::string &attributes,
CLKernelArguments &args)
: CLKernelImpl(kernel),
mProgram(&kernel.getProgram().getImpl<CLProgramVk>()),
mContext(&kernel.getProgram().getContext().getImpl<CLContextVk>()),
mName(name),
mAttributes(attributes),
mArgs(args)
{
mShaderProgramHelper.setShader(gl::ShaderType::Compute,
mKernel.getProgram().getImpl<CLProgramVk>().getShaderModule());
}
CLKernelVk::~CLKernelVk()
{
for (auto &dsLayouts : mDescriptorSetLayouts)
{
dsLayouts.reset();
}
mPipelineLayout.reset();
for (auto &pipelineHelper : mComputePipelineCache)
{
pipelineHelper.destroy(mContext->getDevice());
}
mShaderProgramHelper.destroy(mContext->getRenderer());
}
angle::Result CLKernelVk::setArg(cl_uint argIndex, size_t argSize, const void *argValue)
{
auto &arg = mArgs.at(argIndex);
if (arg.used)
{
arg.handle = const_cast<void *>(argValue);
arg.handleSize = argSize;
}
return angle::Result::Continue;
}
angle::Result CLKernelVk::createInfo(CLKernelImpl::Info *info) const
{
info->functionName = mName;
info->attributes = mAttributes;
info->numArgs = static_cast<cl_uint>(mArgs.size());
for (const auto &arg : mArgs)
{
ArgInfo argInfo;
argInfo.name = arg.info.name;
argInfo.typeName = arg.info.typeName;
argInfo.accessQualifier = arg.info.accessQualifier;
argInfo.addressQualifier = arg.info.addressQualifier;
argInfo.typeQualifier = arg.info.typeQualifier;
info->args.push_back(std::move(argInfo));
}
auto &ctx = mKernel.getProgram().getContext();
info->workGroups.resize(ctx.getDevices().size());
const CLProgramVk::DeviceProgramData *deviceProgramData = nullptr;
for (auto i = 0u; i < ctx.getDevices().size(); ++i)
{
auto &workGroup = info->workGroups[i];
const auto deviceVk = &ctx.getDevices()[i]->getImpl<CLDeviceVk>();
deviceProgramData = mProgram->getDeviceProgramData(ctx.getDevices()[i]->getNative());
if (deviceProgramData == nullptr)
{
continue;
}
// TODO: http://anglebug.com/8576
ANGLE_TRY(
deviceVk->getInfoSizeT(cl::DeviceInfo::MaxWorkGroupSize, &workGroup.workGroupSize));
// TODO: http://anglebug.com/8575
workGroup.privateMemSize = 0;
workGroup.localMemSize = 0;
workGroup.prefWorkGroupSizeMultiple = 16u;
workGroup.globalWorkSize = {0, 0, 0};
if (deviceProgramData->reflectionData.kernelCompileWorkgroupSize.contains(mName))
{
workGroup.compileWorkGroupSize = {
deviceProgramData->reflectionData.kernelCompileWorkgroupSize.at(mName)[0],
deviceProgramData->reflectionData.kernelCompileWorkgroupSize.at(mName)[1],
deviceProgramData->reflectionData.kernelCompileWorkgroupSize.at(mName)[2]};
}
else
{
workGroup.compileWorkGroupSize = {0, 0, 0};
}
}
return angle::Result::Continue;
}
angle::Result CLKernelVk::getOrCreateComputePipeline(vk::PipelineCacheAccess *pipelineCache,
const cl::NDRange &ndrange,
const cl::Device &device,
vk::PipelineHelper **pipelineOut,
cl::WorkgroupCount *workgroupCountOut)
{
uint32_t constantDataOffset = 0;
angle::FixedVector<size_t, 3> specConstantData;
angle::FixedVector<VkSpecializationMapEntry, 3> mapEntries;
const CLProgramVk::DeviceProgramData *devProgramData =
getProgram()->getDeviceProgramData(device.getNative());
ASSERT(devProgramData != nullptr);
// Start with Workgroup size (WGS) from kernel attribute (if available)
cl::WorkgroupSize workgroupSize = devProgramData->getCompiledWorkgroupSize(getKernelName());
if (workgroupSize == kEmptyWorkgroupSize)
{
if (ndrange.nullLocalWorkSize)
{
// NULL value was passed, in which case the OpenCL implementation will determine
// how to be break the global work-items into appropriate work-group instances.
workgroupSize = device.getImpl<CLDeviceVk>().selectWorkGroupSize(ndrange);
}
else
{
// Local work size (LWS) was valid, use that as WGS
workgroupSize = ndrange.localWorkSize;
}
// If at least one of the kernels does not use the reqd_work_group_size attribute, the
// Vulkan SPIR-V produced by the compiler will contain specialization constants
const std::array<uint32_t, 3> &specConstantWorkgroupSizeIDs =
devProgramData->reflectionData.specConstantWorkgroupSizeIDs;
ASSERT(ndrange.workDimensions <= 3);
for (cl_uint i = 0; i < ndrange.workDimensions; ++i)
{
mapEntries.push_back(
VkSpecializationMapEntry{.constantID = specConstantWorkgroupSizeIDs.at(i),
.offset = constantDataOffset,
.size = sizeof(uint32_t)});
constantDataOffset += sizeof(uint32_t);
specConstantData.push_back(workgroupSize[i]);
}
}
// Calculate the workgroup count
// TODO: Add support for non-uniform WGS
// http://angleproject:8631
ASSERT(workgroupSize[0] != 0);
ASSERT(workgroupSize[1] != 0);
ASSERT(workgroupSize[2] != 0);
(*workgroupCountOut)[0] = static_cast<uint32_t>((ndrange.globalWorkSize[0] / workgroupSize[0]));
(*workgroupCountOut)[1] = static_cast<uint32_t>((ndrange.globalWorkSize[1] / workgroupSize[1]));
(*workgroupCountOut)[2] = static_cast<uint32_t>((ndrange.globalWorkSize[2] / workgroupSize[2]));
VkSpecializationInfo computeSpecializationInfo{
.mapEntryCount = static_cast<uint32_t>(mapEntries.size()),
.pMapEntries = mapEntries.data(),
.dataSize = specConstantData.size() * sizeof(specConstantData[0]),
.pData = specConstantData.data(),
};
// Now get or create (on compute pipeline cache miss) compute pipeline and return it
return mShaderProgramHelper.getOrCreateComputePipeline(
mContext, &mComputePipelineCache, pipelineCache, getPipelineLayout().get(),
vk::ComputePipelineFlags{}, PipelineSource::Draw, pipelineOut, mName.c_str(),
&computeSpecializationInfo);
}
} // namespace rx