mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Unified memory sharing 1/n
This change introduces creating and releasing buffers from memory handle. Currently Windows NT Handles are supported. Change-Id: I61b89d97946ce61617ad98922b7e9731d4a754a9 Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com> Related-To: NEO-3771
This commit is contained in:
committed by
sys_ocldev
parent
684d58d2aa
commit
603bce2164
@@ -21,7 +21,8 @@ enum SharingType {
|
||||
D3D9_SHARING = 2,
|
||||
D3D10_SHARING = 3,
|
||||
D3D11_SHARING = 4,
|
||||
MAX_SHARING_VALUE = 5
|
||||
UNIFIED_SHARING = 5,
|
||||
MAX_SHARING_VALUE = 6
|
||||
};
|
||||
|
||||
class SharingContextBuilder {
|
||||
@@ -36,7 +37,7 @@ class SharingBuilderFactory {
|
||||
virtual ~SharingBuilderFactory() = default;
|
||||
virtual std::unique_ptr<SharingContextBuilder> createContextBuilder() = 0;
|
||||
virtual std::string getExtensions() = 0;
|
||||
virtual void fillGlobalDispatchTable() = 0;
|
||||
virtual void fillGlobalDispatchTable() {}
|
||||
virtual void *getExtensionFunctionAddress(const std::string &functionName) = 0;
|
||||
};
|
||||
|
||||
|
||||
19
runtime/sharings/unified/CMakeLists.txt
Normal file
19
runtime/sharings/unified/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(RUNTIME_SRCS_SHARINGS_UNIFIED
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enable_unified.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/unified_buffer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/unified_buffer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/unified_sharing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/unified_sharing.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/unified_sharing_types.h
|
||||
)
|
||||
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_UNIFIED})
|
||||
set_property(GLOBAL PROPERTY RUNTIME_SRCS_SHARINGS_UNIFIED ${RUNTIME_SRCS_SHARINGS_UNIFIED})
|
||||
add_subdirectories()
|
||||
55
runtime/sharings/unified/enable_unified.cpp
Normal file
55
runtime/sharings/unified/enable_unified.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/sharings/unified/enable_unified.h"
|
||||
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/context/context.inl"
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
#include "runtime/sharings/sharing_factory.inl"
|
||||
#include "runtime/sharings/unified/unified_sharing.h"
|
||||
#include "runtime/sharings/unified/unified_sharing_types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
bool UnifiedSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue,
|
||||
cl_int &errcodeRet) {
|
||||
switch (propertyType) {
|
||||
case static_cast<cl_context_properties>(UnifiedSharingContextType::DeviceHandle):
|
||||
case static_cast<cl_context_properties>(UnifiedSharingContextType::DeviceGroup):
|
||||
this->contextData = std::make_unique<UnifiedCreateContextProperties>();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UnifiedSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) {
|
||||
if (contextData.get() != nullptr) {
|
||||
context.registerSharing(new UnifiedSharingFunctions());
|
||||
contextData.reset(nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<SharingContextBuilder> UnifiedSharingBuilderFactory::createContextBuilder() {
|
||||
return std::make_unique<UnifiedSharingContextBuilder>();
|
||||
};
|
||||
|
||||
std::string UnifiedSharingBuilderFactory::getExtensions() {
|
||||
return "cl_intel_unified_sharing ";
|
||||
}
|
||||
|
||||
void *UnifiedSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SharingFactory::RegisterSharing<UnifiedSharingBuilderFactory, UnifiedSharingFunctions> unifiedSharing;
|
||||
} // namespace NEO
|
||||
34
runtime/sharings/unified/enable_unified.h
Normal file
34
runtime/sharings/unified/enable_unified.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
class Context;
|
||||
|
||||
struct UnifiedCreateContextProperties {
|
||||
};
|
||||
|
||||
class UnifiedSharingContextBuilder : public SharingContextBuilder {
|
||||
protected:
|
||||
std::unique_ptr<UnifiedCreateContextProperties> contextData;
|
||||
|
||||
public:
|
||||
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) override;
|
||||
bool finalizeProperties(Context &context, int32_t &errcodeRet) override;
|
||||
};
|
||||
|
||||
class UnifiedSharingBuilderFactory : public SharingBuilderFactory {
|
||||
public:
|
||||
std::unique_ptr<SharingContextBuilder> createContextBuilder() override;
|
||||
std::string getExtensions() override;
|
||||
void *getExtensionFunctionAddress(const std::string &functionName) override;
|
||||
};
|
||||
} // namespace NEO
|
||||
44
runtime/sharings/unified/unified_buffer.cpp
Normal file
44
runtime/sharings/unified/unified_buffer.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "unified_buffer.h"
|
||||
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/gmm_helper/gmm.h"
|
||||
#include "runtime/helpers/get_info.h"
|
||||
#include "runtime/mem_obj/buffer.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
Buffer *UnifiedBuffer::createSharedUnifiedBuffer(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription extMem, cl_int *errcodeRet) {
|
||||
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
|
||||
|
||||
auto graphicsAllocation = UnifiedBuffer::createGraphicsAllocation(context, extMem.handle);
|
||||
if (!graphicsAllocation) {
|
||||
errorCode.set(CL_INVALID_MEM_OBJECT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnifiedSharingFunctions *sharingFunctions = context->getSharing<UnifiedSharingFunctions>();
|
||||
auto sharingHandler = new UnifiedBuffer(sharingFunctions, extMem.type);
|
||||
return Buffer::createSharedBuffer(context, flags, sharingHandler, graphicsAllocation);
|
||||
}
|
||||
|
||||
void UnifiedBuffer::synchronizeObject(UpdateData &updateData) {
|
||||
// Acquiring is not implemented yet
|
||||
}
|
||||
|
||||
GraphicsAllocation *UnifiedBuffer::createGraphicsAllocation(Context *context, void *handle) {
|
||||
auto graphicsAllocation = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(handle, 0);
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
||||
void UnifiedBuffer::releaseResource(MemObj *memObject) {
|
||||
}
|
||||
27
runtime/sharings/unified/unified_buffer.h
Normal file
27
runtime/sharings/unified/unified_buffer.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/sharings/unified/unified_sharing.h"
|
||||
|
||||
namespace NEO {
|
||||
class Buffer;
|
||||
class Context;
|
||||
|
||||
class UnifiedBuffer : public UnifiedSharing {
|
||||
using UnifiedSharing::UnifiedSharing;
|
||||
|
||||
public:
|
||||
static Buffer *createSharedUnifiedBuffer(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription description, cl_int *errcodeRet);
|
||||
void synchronizeObject(UpdateData &updateData) override;
|
||||
|
||||
protected:
|
||||
void releaseResource(MemObj *memObject) override;
|
||||
static GraphicsAllocation *createGraphicsAllocation(Context *context, void *handle);
|
||||
};
|
||||
} // namespace NEO
|
||||
41
runtime/sharings/unified/unified_sharing.cpp
Normal file
41
runtime/sharings/unified/unified_sharing.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/sharings/unified/unified_sharing.h"
|
||||
|
||||
#include "core/helpers/string.h"
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/helpers/timestamp_packet.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
const uint32_t UnifiedSharingFunctions::sharingId = SharingType::UNIFIED_SHARING;
|
||||
|
||||
UnifiedSharing::UnifiedSharing(UnifiedSharingFunctions *sharingFunctions, UnifiedSharingHandleType memoryType)
|
||||
: sharingFunctions(sharingFunctions),
|
||||
memoryType(memoryType) {
|
||||
}
|
||||
|
||||
int UnifiedSharing::synchronizeHandler(UpdateData &updateData) {
|
||||
synchronizeObject(updateData);
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
void UnifiedSharing::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
|
||||
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
|
||||
}
|
||||
|
||||
template <>
|
||||
UnifiedSharingFunctions *Context::getSharing() {
|
||||
UNRECOVERABLE_IF(UnifiedSharingFunctions::sharingId >= sharingFunctions.size())
|
||||
return reinterpret_cast<UnifiedSharingFunctions *>(sharingFunctions[UnifiedSharingFunctions::sharingId].get());
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
47
runtime/sharings/unified/unified_sharing.h
Normal file
47
runtime/sharings/unified/unified_sharing.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/mem_obj/mem_obj.h"
|
||||
#include "runtime/os_interface/os_library.h"
|
||||
#include "runtime/sharings/sharing.h"
|
||||
#include "runtime/sharings/unified/unified_sharing_types.h"
|
||||
|
||||
#include "CL/cl.h"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class UnifiedSharingFunctions : public SharingFunctions {
|
||||
public:
|
||||
uint32_t getId() const override {
|
||||
return UnifiedSharingFunctions::sharingId;
|
||||
}
|
||||
static const uint32_t sharingId;
|
||||
};
|
||||
|
||||
class UnifiedSharing : public SharingHandler {
|
||||
public:
|
||||
UnifiedSharing(UnifiedSharingFunctions *sharingFunctions, UnifiedSharingHandleType memoryType);
|
||||
|
||||
UnifiedSharingFunctions *peekFunctionsHandler() { return sharingFunctions; }
|
||||
UnifiedSharingHandleType getExternalMemoryType() { return memoryType; }
|
||||
|
||||
protected:
|
||||
int synchronizeHandler(UpdateData &updateData) override;
|
||||
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override;
|
||||
|
||||
private:
|
||||
UnifiedSharingFunctions *sharingFunctions;
|
||||
UnifiedSharingHandleType memoryType;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
33
runtime/sharings/unified/unified_sharing_types.h
Normal file
33
runtime/sharings/unified/unified_sharing_types.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
using UnifiedSharingMemoryProperties = uint64_t;
|
||||
|
||||
enum class UnifiedSharingContextType {
|
||||
DeviceHandle = 0x300B,
|
||||
DeviceGroup = 0x300C
|
||||
};
|
||||
|
||||
enum class UnifiedSharingHandleType {
|
||||
LinuxFd = 1,
|
||||
Win32Shared = 2,
|
||||
Win32Nt = 3
|
||||
};
|
||||
|
||||
struct UnifiedSharingMemoryDescription {
|
||||
UnifiedSharingHandleType type;
|
||||
void *handle;
|
||||
unsigned long long size;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user