2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-12 01:04:14 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-17 20:03:37 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/pipe.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/get_info.h"
|
2023-01-13 01:05:31 +08:00
|
|
|
#include "shared/source/helpers/memory_properties_helpers.h"
|
2023-01-12 01:04:14 +08:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-03-20 18:15:25 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
2021-10-07 01:00:24 +08:00
|
|
|
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/helpers/get_info_status_mapper.h"
|
|
|
|
#include "opencl/source/mem_obj/mem_obj_helper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Pipe::Pipe(Context *context,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_uint packetSize,
|
|
|
|
cl_uint maxPackets,
|
|
|
|
const cl_pipe_properties *properties,
|
|
|
|
void *memoryStorage,
|
2020-07-20 17:08:15 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation)
|
2017-12-21 07:45:38 +08:00
|
|
|
: MemObj(context,
|
|
|
|
CL_MEM_OBJECT_PIPE,
|
2021-10-07 01:00:24 +08:00
|
|
|
ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
|
2019-09-24 22:05:17 +08:00
|
|
|
flags,
|
|
|
|
0,
|
2017-12-21 07:45:38 +08:00
|
|
|
static_cast<size_t>(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace),
|
|
|
|
memoryStorage,
|
|
|
|
nullptr,
|
2020-07-21 16:21:15 +08:00
|
|
|
std::move(multiGraphicsAllocation),
|
2017-12-21 07:45:38 +08:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false),
|
|
|
|
pipePacketSize(packetSize),
|
|
|
|
pipeMaxPackets(maxPackets) {
|
|
|
|
magic = objectMagic;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pipe *Pipe::create(Context *context,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_uint packetSize,
|
|
|
|
cl_uint maxPackets,
|
|
|
|
const cl_pipe_properties *properties,
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
Pipe *pPipe = nullptr;
|
|
|
|
errcodeRet = CL_SUCCESS;
|
|
|
|
|
|
|
|
MemoryManager *memoryManager = context->getMemoryManager();
|
|
|
|
DEBUG_BREAK_IF(!memoryManager);
|
|
|
|
|
2020-06-05 06:16:55 +08:00
|
|
|
MemoryProperties memoryProperties =
|
2021-10-07 01:00:24 +08:00
|
|
|
ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice());
|
2017-12-21 07:45:38 +08:00
|
|
|
while (true) {
|
2018-07-09 20:12:32 +08:00
|
|
|
auto size = static_cast<size_t>(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace);
|
2019-11-07 21:15:04 +08:00
|
|
|
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
|
2019-04-03 17:22:04 +08:00
|
|
|
AllocationProperties allocProperties =
|
2020-05-04 17:04:43 +08:00
|
|
|
MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties,
|
|
|
|
true, // allocateMemory
|
2022-02-04 21:59:01 +08:00
|
|
|
size, AllocationType::PIPE,
|
2020-05-04 17:04:43 +08:00
|
|
|
false, // isMultiStorageAllocation
|
2021-07-07 20:43:54 +08:00
|
|
|
context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex),
|
|
|
|
context->isSingleDeviceContext());
|
2019-04-02 19:17:57 +08:00
|
|
|
GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (!memory) {
|
|
|
|
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-20 17:08:15 +08:00
|
|
|
auto multiGraphicsAllocation = MultiGraphicsAllocation(rootDeviceIndex);
|
|
|
|
multiGraphicsAllocation.addAllocation(memory);
|
|
|
|
|
|
|
|
pPipe = new (std::nothrow) Pipe(context, flags, packetSize, maxPackets, properties, memory->getUnderlyingBuffer(), std::move(multiGraphicsAllocation));
|
2017-12-21 07:45:38 +08:00
|
|
|
if (!pPipe) {
|
|
|
|
memoryManager->freeGraphicsMemory(memory);
|
|
|
|
memory = nullptr;
|
|
|
|
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Initialize pipe_control_intel_t structure located at the beginning of the surface
|
|
|
|
memset(memory->getUnderlyingBuffer(), 0, intelPipeHeaderReservedSpace);
|
|
|
|
*reinterpret_cast<unsigned int *>(memory->getUnderlyingBuffer()) = maxPackets + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pPipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_int Pipe::getPipeInfo(cl_image_info paramName,
|
|
|
|
size_t paramValueSize,
|
|
|
|
void *paramValue,
|
|
|
|
size_t *paramValueSizeRet) {
|
|
|
|
|
|
|
|
cl_int retVal;
|
2020-05-18 22:13:59 +08:00
|
|
|
size_t srcParamSize = GetInfo::invalidSourceSize;
|
2017-12-21 07:45:38 +08:00
|
|
|
void *srcParam = nullptr;
|
|
|
|
|
|
|
|
switch (paramName) {
|
|
|
|
case CL_PIPE_PACKET_SIZE:
|
|
|
|
srcParamSize = sizeof(cl_uint);
|
|
|
|
srcParam = &(pipePacketSize);
|
|
|
|
break;
|
|
|
|
case CL_PIPE_MAX_PACKETS:
|
|
|
|
srcParamSize = sizeof(cl_uint);
|
|
|
|
srcParam = &(pipeMaxPackets);
|
|
|
|
break;
|
2020-05-27 23:12:32 +08:00
|
|
|
case CL_PIPE_PROPERTIES:
|
|
|
|
srcParamSize = 0;
|
|
|
|
break;
|
2017-12-21 07:45:38 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-18 22:13:59 +08:00
|
|
|
auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, srcParam, srcParamSize);
|
|
|
|
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
|
|
|
|
GetInfo::setParamValueReturnSize(paramValueSizeRet, srcParamSize, getInfoStatus);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:01:35 +08:00
|
|
|
void Pipe::setPipeArg(void *memory, uint32_t patchSize, uint32_t rootDeviceIndex) {
|
|
|
|
patchWithRequiredSize(memory, patchSize, static_cast<uintptr_t>(multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)->getGpuAddressToPatch()));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Pipe::~Pipe() = default;
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|