2019-08-05 21:16:57 +08:00
|
|
|
/*
|
2020-02-11 00:58:02 +08:00
|
|
|
* Copyright (C) 2019-2020 Intel Corporation
|
2019-08-05 21:16:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/bit_helpers.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-26 21:21:01 +08:00
|
|
|
#include "opencl/extensions/public/cl_ext_private.h"
|
2020-05-04 17:04:43 +08:00
|
|
|
#include "opencl/source/helpers/memory_properties_helpers.h"
|
2019-08-05 21:16:57 +08:00
|
|
|
|
|
|
|
#include "CL/cl_ext_intel.h"
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2020-06-05 06:16:55 +08:00
|
|
|
MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags flags, cl_mem_flags_intel flagsIntel,
|
|
|
|
cl_mem_alloc_flags_intel allocflags, const Device *pDevice) {
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties memoryProperties;
|
2019-08-05 21:16:57 +08:00
|
|
|
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_READ_WRITE)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.readWrite = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_WRITE_ONLY)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.writeOnly = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_READ_ONLY)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.readOnly = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_USE_HOST_PTR)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.useHostPtr = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_ALLOC_HOST_PTR)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.allocHostPtr = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_COPY_HOST_PTR)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.copyHostPtr = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_HOST_WRITE_ONLY)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.hostWriteOnly = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_HOST_READ_ONLY)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.hostReadOnly = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_HOST_NO_ACCESS)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.hostNoAccess = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_KERNEL_READ_AND_WRITE)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.kernelReadAndWrite = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_FORCE_LINEAR_STORAGE_INTEL) ||
|
|
|
|
isValueSet(flagsIntel, CL_MEM_FORCE_LINEAR_STORAGE_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.forceLinearStorage = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.accessFlagsUnrestricted = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_NO_ACCESS_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.noAccess = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
|
|
|
|
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.allowUnrestrictedSize = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flagsIntel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.locallyUncachedResource = true;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
2019-08-30 14:18:34 +08:00
|
|
|
|
2019-10-23 01:51:53 +08:00
|
|
|
if (isValueSet(flagsIntel, CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.locallyUncachedInSurfaceState = true;
|
2019-08-30 14:18:34 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 22:17:51 +08:00
|
|
|
if (isValueSet(flags, CL_MEM_FORCE_HOST_MEMORY_INTEL)) {
|
|
|
|
memoryProperties.flags.forceHostMemory = true;
|
2019-08-09 18:20:05 +08:00
|
|
|
}
|
2019-08-05 21:16:57 +08:00
|
|
|
|
2019-12-05 17:32:42 +08:00
|
|
|
if (isValueSet(allocflags, CL_MEM_ALLOC_WRITE_COMBINED_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.allocFlags.allocWriteCombined = true;
|
2019-12-05 17:32:42 +08:00
|
|
|
}
|
|
|
|
|
2020-02-11 00:58:02 +08:00
|
|
|
if (isValueSet(flagsIntel, CL_MEM_48BIT_RESOURCE_INTEL)) {
|
2020-04-22 20:37:30 +08:00
|
|
|
memoryProperties.flags.resource48Bit = true;
|
2020-02-11 00:58:02 +08:00
|
|
|
}
|
|
|
|
|
2020-06-05 06:16:55 +08:00
|
|
|
addExtraMemoryProperties(memoryProperties, flags, flagsIntel, pDevice);
|
2019-08-05 21:16:57 +08:00
|
|
|
|
2020-04-22 20:37:30 +08:00
|
|
|
return memoryProperties;
|
2019-08-05 21:16:57 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 08:23:13 +08:00
|
|
|
AllocationProperties MemoryPropertiesHelper::getAllocationProperties(
|
|
|
|
uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size,
|
|
|
|
GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo,
|
|
|
|
DeviceBitfield subDevicesBitfieldParam) {
|
|
|
|
|
|
|
|
auto deviceBitfield = adjustDeviceBitfield(rootDeviceIndex, memoryProperties, subDevicesBitfieldParam);
|
2020-06-03 20:30:16 +08:00
|
|
|
AllocationProperties allocationProperties(rootDeviceIndex, allocateMemory, size, type, multiStorageResource, deviceBitfield);
|
2020-05-04 17:04:43 +08:00
|
|
|
fillPoliciesInProperties(allocationProperties, memoryProperties, hwInfo);
|
|
|
|
return allocationProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryPropertiesHelper::fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly,
|
|
|
|
bool deviceOnlyVisibilty) {
|
|
|
|
allocationProperties.flags.uncacheable = uncached;
|
|
|
|
auto cacheFlushRequired = !uncached && !readOnly && !deviceOnlyVisibilty;
|
|
|
|
allocationProperties.flags.flushL3RequiredForRead = cacheFlushRequired;
|
|
|
|
allocationProperties.flags.flushL3RequiredForWrite = cacheFlushRequired;
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:18:34 +08:00
|
|
|
} // namespace NEO
|