From 6b2b42972accc0efd559e8a2113fef1e81e7dd74 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Mon, 17 Feb 2025 14:23:39 +0000 Subject: [PATCH] fix: Add asserts to ensure NonCopyable and NonMovable 1/n Signed-off-by: Filip Hazubski --- level_zero/core/source/driver/driver_handle.h | 11 ++++++----- .../core/source/driver/host_pointer_manager.h | 11 +++++++++-- level_zero/core/source/kernel/kernel.h | 12 ++++-------- level_zero/core/source/module/module.h | 14 ++++++-------- level_zero/core/source/module/module_build_log.h | 10 +++++++--- .../core/source/printf_handler/printf_handler.h | 9 +++++---- .../api/events/windows/sysman_os_events_imp.h | 7 +++---- .../sysman/source/driver/sysman_driver_handle.h | 10 +++++----- .../source/sysman/events/windows/os_events_imp.h | 7 +++---- .../windows/os_global_operations_imp.h | 4 ++-- level_zero/tools/source/sysman/linux/fs_access.h | 9 +++++++-- .../source/sysman/vf_management/vf_management.h | 10 +++++----- opencl/source/cl_device/cl_device.h | 8 ++++---- opencl/source/command_queue/command_queue.h | 5 ++--- opencl/source/command_queue/resource_barrier.h | 12 ++++++------ opencl/source/context/context.h | 6 +++--- opencl/source/event/event.h | 7 +++---- opencl/source/event/event_builder.h | 12 ++++++------ opencl/source/helpers/base_object.h | 8 +++----- opencl/source/helpers/dispatch_info.h | 11 ++++++----- opencl/source/kernel/kernel.h | 8 ++++---- opencl/source/platform/platform.h | 6 +++--- opencl/source/program/program.h | 7 +++---- opencl/source/sharings/gl/gl_buffer.h | 11 +++++++---- opencl/source/tracing/tracing_notify.h | 11 +++++------ shared/source/helpers/non_copyable_or_moveable.h | 15 ++++++++------- 26 files changed, 125 insertions(+), 116 deletions(-) diff --git a/level_zero/core/source/driver/driver_handle.h b/level_zero/core/source/driver/driver_handle.h index 6369f2d79b..18ec01f8f6 100644 --- a/level_zero/core/source/driver/driver_handle.h +++ b/level_zero/core/source/driver/driver_handle.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" + #include "level_zero/core/source/helpers/api_handle_helper.h" #include #include @@ -38,7 +40,7 @@ struct BaseDriver : _ze_driver_handle_t { static BaseDriver *fromHandle(ze_driver_handle_t handle) { return static_cast(handle); } }; -struct DriverHandle : BaseDriver { +struct DriverHandle : BaseDriver, NEO::NonCopyableAndNonMovableClass { virtual ze_result_t createContext(const ze_context_desc_t *desc, uint32_t numDevices, ze_device_handle_t *phDevices, @@ -90,10 +92,9 @@ struct DriverHandle : BaseDriver { static DriverHandle *fromHandle(ze_driver_handle_t handle) { return static_cast(handle); } inline ze_driver_handle_t toHandle() { return this; } - DriverHandle &operator=(const DriverHandle &) = delete; - DriverHandle &operator=(DriverHandle &&) = delete; - static DriverHandle *create(std::vector> devices, const L0EnvVariables &envVariables, ze_result_t *returnValue); }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/core/source/driver/host_pointer_manager.h b/level_zero/core/source/driver/host_pointer_manager.h index b9330b66fd..2c0340282d 100644 --- a/level_zero/core/source/driver/host_pointer_manager.h +++ b/level_zero/core/source/driver/host_pointer_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "shared/source/helpers/device_bitfield.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/memory_manager/multi_graphics_allocation.h" #include "shared/source/utilities/spinlock.h" @@ -40,7 +41,10 @@ struct HostPointerData { } } } - HostPointerData &operator=(const HostPointerData &) = delete; + HostPointerData(HostPointerData &&other) noexcept = delete; + HostPointerData &operator=(HostPointerData &&other) noexcept = delete; + HostPointerData &operator=(const HostPointerData &other) = delete; + NEO::MultiGraphicsAllocation hostPtrAllocations; void *basePtr = nullptr; size_t size = 0u; @@ -81,4 +85,7 @@ class HostPointerManager { NEO::MemoryManager *memoryManager; NEO::SpinLock mtx; }; + +static_assert(NEO::NonMovable); + } // namespace L0 diff --git a/level_zero/core/source/kernel/kernel.h b/level_zero/core/source/kernel/kernel.h index e55222f8fc..a34125eef6 100644 --- a/level_zero/core/source/kernel/kernel.h +++ b/level_zero/core/source/kernel/kernel.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -110,7 +110,7 @@ struct KernelImmutableData { bool isaCopiedToAllocation = false; }; -struct Kernel : _ze_kernel_handle_t, virtual NEO::DispatchKernelEncoderI { +struct Kernel : _ze_kernel_handle_t, virtual NEO::DispatchKernelEncoderI, NEO::NonCopyableAndNonMovableClass { template struct Allocator { static Kernel *allocate(Module *module) { return new Type(module); } @@ -174,12 +174,6 @@ struct Kernel : _ze_kernel_handle_t, virtual NEO::DispatchKernelEncoderI { virtual ze_result_t setSchedulingHintExp(ze_scheduling_hint_exp_desc_t *pHint) = 0; - Kernel() = default; - Kernel(const Kernel &) = delete; - Kernel(Kernel &&) = delete; - Kernel &operator=(const Kernel &) = delete; - Kernel &operator=(Kernel &&) = delete; - static Kernel *fromHandle(ze_kernel_handle_t handle) { return static_cast(handle); } inline ze_kernel_handle_t toHandle() { return this; } @@ -215,4 +209,6 @@ struct KernelPopulateFactory { } }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/core/source/module/module.h b/level_zero/core/source/module/module.h index 6c853a2161..f4a24761fa 100644 --- a/level_zero/core/source/module/module.h +++ b/level_zero/core/source/module/module.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" + #include #include @@ -28,7 +30,7 @@ enum class ModuleType { user }; -struct Module : _ze_module_handle_t { +struct Module : _ze_module_handle_t, NEO::NonCopyableAndNonMovableClass { static Module *create(Device *device, const ze_module_desc_t *desc, ModuleBuildLog *moduleBuildLog, ModuleType type, ze_result_t *result); @@ -60,15 +62,11 @@ struct Module : _ze_module_handle_t { virtual uint32_t getProfileFlags() const = 0; virtual void checkIfPrivateMemoryPerDispatchIsNeeded() = 0; - Module() = default; - Module(const Module &) = delete; - Module(Module &&) = delete; - Module &operator=(const Module &) = delete; - Module &operator=(Module &&) = delete; - static Module *fromHandle(ze_module_handle_t handle) { return static_cast(handle); } inline ze_module_handle_t toHandle() { return this; } }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/core/source/module/module_build_log.h b/level_zero/core/source/module/module_build_log.h index c6604c3803..f73cd56a7e 100644 --- a/level_zero/core/source/module/module_build_log.h +++ b/level_zero/core/source/module/module_build_log.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" + #include struct _ze_module_build_log_handle_t {}; @@ -15,7 +17,7 @@ namespace L0 { struct Module; -struct ModuleBuildLog : _ze_module_build_log_handle_t { +struct ModuleBuildLog : _ze_module_build_log_handle_t, NEO::NonCopyableAndNonMovableClass { static ModuleBuildLog *create(); virtual ~ModuleBuildLog() = default; @@ -36,4 +38,6 @@ struct ModuleBuildLog : _ze_module_build_log_handle_t { inline ze_module_build_log_handle_t toHandle() { return this; } }; -} // namespace L0 \ No newline at end of file +static_assert(NEO::NonCopyableAndNonMovable); + +} // namespace L0 diff --git a/level_zero/core/source/printf_handler/printf_handler.h b/level_zero/core/source/printf_handler/printf_handler.h index b0bdd90c01..8dfc0099b8 100644 --- a/level_zero/core/source/printf_handler/printf_handler.h +++ b/level_zero/core/source/printf_handler/printf_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #pragma once #include "shared/source/helpers/constants.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "level_zero/core/source/kernel/kernel.h" @@ -21,19 +22,19 @@ class GraphicsAllocation; namespace L0 { struct Device; -struct PrintfHandler { +struct PrintfHandler : NEO::NonCopyableAndNonMovableClass { static NEO::GraphicsAllocation *createPrintfBuffer(Device *device); static void printOutput(const KernelImmutableData *kernelData, NEO::GraphicsAllocation *printfBuffer, Device *device, bool useInternalBlitter); static size_t getPrintBufferSize(); protected: - PrintfHandler(const PrintfHandler &) = delete; - PrintfHandler &operator=(PrintfHandler const &) = delete; PrintfHandler() = delete; constexpr static size_t printfBufferSize = 4 * MemoryConstants::megaByte; constexpr static uint32_t printfSurfaceInitialDataSize = sizeof(uint32_t); }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/sysman/source/api/events/windows/sysman_os_events_imp.h b/level_zero/sysman/source/api/events/windows/sysman_os_events_imp.h index 7d81ed4d72..f8d8a6bf11 100644 --- a/level_zero/sysman/source/api/events/windows/sysman_os_events_imp.h +++ b/level_zero/sysman/source/api/events/windows/sysman_os_events_imp.h @@ -29,10 +29,6 @@ class WddmEventsImp : public OsEvents, NEO::NonCopyableAndNonMovableClass { WddmEventsImp(OsSysman *pOsSysman); ~WddmEventsImp(); - // Don't allow copies of the WddmEventsImp object - WddmEventsImp(const WddmEventsImp &obj) = delete; - WddmEventsImp &operator=(const WddmEventsImp &obj) = delete; - private: void registerEvents(zes_event_type_flags_t eventId, uint32_t requestId); void unregisterEvents(); @@ -55,5 +51,8 @@ class WddmEventsImp : public OsEvents, NEO::NonCopyableAndNonMovableClass { std::vector eventList; }; +// Don't allow copies of the WddmEventsImp object +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/source/driver/sysman_driver_handle.h b/level_zero/sysman/source/driver/sysman_driver_handle.h index ea842139c6..162fd89d38 100644 --- a/level_zero/sysman/source/driver/sysman_driver_handle.h +++ b/level_zero/sysman/source/driver/sysman_driver_handle.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "level_zero/core/source/driver/driver_handle.h" #include @@ -15,13 +16,10 @@ namespace L0 { namespace Sysman { -struct SysmanDriverHandle : BaseDriver { +struct SysmanDriverHandle : BaseDriver, NEO::NonCopyableAndNonMovableClass { static SysmanDriverHandle *fromHandle(zes_driver_handle_t handle) { return static_cast(handle); } inline zes_driver_handle_t toHandle() { return this; } - SysmanDriverHandle &operator=(const SysmanDriverHandle &) = delete; - SysmanDriverHandle &operator=(SysmanDriverHandle &&) = delete; - static SysmanDriverHandle *create(NEO::ExecutionEnvironment &executionEnvironment, ze_result_t *returnValue); virtual ze_result_t getDeviceByUuid(zes_uuid_t uuid, zes_device_handle_t *phDevice, ze_bool_t *onSubdevice, uint32_t *subdeviceId) = 0; virtual ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) = 0; @@ -32,5 +30,7 @@ struct SysmanDriverHandle : BaseDriver { uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace Sysman } // namespace L0 diff --git a/level_zero/tools/source/sysman/events/windows/os_events_imp.h b/level_zero/tools/source/sysman/events/windows/os_events_imp.h index 3b6bec7958..aaf4dbc3a0 100644 --- a/level_zero/tools/source/sysman/events/windows/os_events_imp.h +++ b/level_zero/tools/source/sysman/events/windows/os_events_imp.h @@ -30,10 +30,6 @@ class WddmEventsImp : public OsEvents, NEO::NonCopyableAndNonMovableClass { CloseHandle(exitHandle); } - // Don't allow copies of the WddmEventsImp object - WddmEventsImp(const WddmEventsImp &obj) = delete; - WddmEventsImp &operator=(const WddmEventsImp &obj) = delete; - private: void registerEvents(zes_event_type_flags_t eventId, uint32_t requestId); void unregisterEvents(); @@ -44,4 +40,7 @@ class WddmEventsImp : public OsEvents, NEO::NonCopyableAndNonMovableClass { std::vector eventList; }; +// Don't allow copies of the WddmEventsImp object +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/tools/source/sysman/global_operations/windows/os_global_operations_imp.h b/level_zero/tools/source/sysman/global_operations/windows/os_global_operations_imp.h index c140a8cbe7..a5e5617859 100644 --- a/level_zero/tools/source/sysman/global_operations/windows/os_global_operations_imp.h +++ b/level_zero/tools/source/sysman/global_operations/windows/os_global_operations_imp.h @@ -31,9 +31,7 @@ class WddmGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableAndNo ze_result_t resetExt(zes_reset_properties_t *pProperties) override; WddmGlobalOperationsImp(OsSysman *pOsSysman); - WddmGlobalOperationsImp(const WddmGlobalOperationsImp &obj) = delete; WddmGlobalOperationsImp() = default; - WddmGlobalOperationsImp &operator=(const WddmGlobalOperationsImp &obj) = delete; ~WddmGlobalOperationsImp() override = default; private: @@ -43,4 +41,6 @@ class WddmGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableAndNo KmdSysManager *pKmdSysManager = nullptr; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/fs_access.h b/level_zero/tools/source/sysman/linux/fs_access.h index 60697106dd..cf220e7ce3 100644 --- a/level_zero/tools/source/sysman/linux/fs_access.h +++ b/level_zero/tools/source/sysman/linux/fs_access.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/os_interface/linux/sys_calls.h" #include "level_zero/ze_api.h" @@ -49,8 +50,10 @@ class FsAccess { public: static FsAccess *create(); FsAccess(const FsAccess &fsAccess); - FsAccess &operator=(const FsAccess &) = delete; virtual ~FsAccess() = default; + FsAccess(FsAccess &&other) noexcept = delete; + FsAccess &operator=(FsAccess &&other) noexcept = delete; + FsAccess &operator=(const FsAccess &other) = delete; virtual ze_result_t canRead(const std::string file); virtual ze_result_t canWrite(const std::string file); @@ -159,4 +162,6 @@ class SysfsAccess : protected FsAccess { static const std::string intelGpuUnbindEntry; }; +static_assert(NEO::NonMovable); + } // namespace L0 diff --git a/level_zero/tools/source/sysman/vf_management/vf_management.h b/level_zero/tools/source/sysman/vf_management/vf_management.h index 1795b1b329..5ac80ca6d9 100644 --- a/level_zero/tools/source/sysman/vf_management/vf_management.h +++ b/level_zero/tools/source/sysman/vf_management/vf_management.h @@ -6,6 +6,8 @@ */ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" + #include "level_zero/api/sysman/zes_handles_struct.h" #include @@ -30,13 +32,9 @@ class VfManagement : _zes_vf_handle_t { } }; -struct VfManagementHandleContext { +struct VfManagementHandleContext : NEO::NonCopyableAndNonMovableClass { VfManagementHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; ~VfManagementHandleContext(); - VfManagementHandleContext(VfManagementHandleContext &&other) noexcept = delete; - VfManagementHandleContext(const VfManagementHandleContext &other) = delete; - VfManagementHandleContext &operator=(VfManagementHandleContext &&other) noexcept = delete; - VfManagementHandleContext &operator=(const VfManagementHandleContext &other) = delete; ze_result_t init(); @@ -50,4 +48,6 @@ struct VfManagementHandleContext { std::once_flag initVfManagementOnce; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace L0 diff --git a/opencl/source/cl_device/cl_device.h b/opencl/source/cl_device/cl_device.h index cc8614e186..03813dc8d7 100644 --- a/opencl/source/cl_device/cl_device.h +++ b/opencl/source/cl_device/cl_device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "shared/source/helpers/device_bitfield.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/utilities/reference_tracked_object.h" #include "opencl/source/api/cl_types.h" @@ -52,9 +53,6 @@ class ClDevice : public BaseObject<_cl_device_id> { public: static const cl_ulong objectMagic = 0x8055832341AC8D08LL; - ClDevice &operator=(const ClDevice &) = delete; - ClDevice(const ClDevice &) = delete; - explicit ClDevice(Device &device, Platform *platformId); explicit ClDevice(Device &device, ClDevice &rootClDevice, Platform *platformId); ~ClDevice() override; @@ -172,4 +170,6 @@ class ClDevice : public BaseObject<_cl_device_id> { std::string compilerExtensionsWithFeatures; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/command_queue/command_queue.h b/opencl/source/command_queue/command_queue.h index 11162f097f..6ecb4436df 100644 --- a/opencl/source/command_queue/command_queue.h +++ b/opencl/source/command_queue/command_queue.h @@ -74,9 +74,6 @@ class CommandQueue : public BaseObject<_cl_command_queue> { CommandQueue(Context *context, ClDevice *device, const cl_queue_properties *properties, bool internalUsage); - CommandQueue &operator=(const CommandQueue &) = delete; - CommandQueue(const CommandQueue &) = delete; - ~CommandQueue() override; // API entry points @@ -513,6 +510,8 @@ class CommandQueue : public BaseObject<_cl_command_queue> { bool isForceStateless = false; }; +static_assert(NEO::NonCopyableAndNonMovable); + template PtrType CommandQueue::convertAddressWithOffsetToGpuVa(PtrType ptr, InternalMemoryType memoryType, GraphicsAllocation &allocation) { // If this is device or shared USM pointer, it is already a gpuVA and we don't have to do anything. diff --git a/opencl/source/command_queue/resource_barrier.h b/opencl/source/command_queue/resource_barrier.h index 8b207aa7bf..c494cde7a1 100644 --- a/opencl/source/command_queue/resource_barrier.h +++ b/opencl/source/command_queue/resource_barrier.h @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019-2024 Intel Corporation + * Copyright (C) 2019-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/utilities/stackvec.h" #include "opencl/extensions/public/cl_ext_private.h" @@ -13,16 +14,15 @@ namespace NEO { class CommandQueue; -class BarrierCommand { +class BarrierCommand : NEO::NonCopyableAndNonMovableClass { public: BarrierCommand(CommandQueue *commandQueue, const cl_resource_barrier_descriptor_intel *descriptors, uint32_t numDescriptors); ~BarrierCommand() {} - BarrierCommand(BarrierCommand &&other) noexcept = delete; - BarrierCommand(const BarrierCommand &other) = delete; - BarrierCommand &operator=(BarrierCommand &&other) noexcept = delete; - BarrierCommand &operator=(const BarrierCommand &other) = delete; uint32_t numSurfaces = 0; StackVec surfaces; StackVec surfacePtrs; }; + +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/context/context.h b/opencl/source/context/context.h index f3dec1febe..5a84f0735b 100644 --- a/opencl/source/context/context.h +++ b/opencl/source/context/context.h @@ -127,9 +127,6 @@ class Context : public BaseObject<_cl_context> { return pContext; } - Context &operator=(const Context &) = delete; - Context(const Context &) = delete; - ~Context() override; cl_int setDestructorCallback(void(CL_CALLBACK *funcNotify)(cl_context, void *), @@ -321,4 +318,7 @@ class Context : public BaseObject<_cl_context> { bool nonZebinContext = false; bool usmPoolInitialized = false; }; + +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/event/event.h b/opencl/source/event/event.h index fe9c6cc257..fd32726367 100644 --- a/opencl/source/event/event.h +++ b/opencl/source/event/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -91,9 +91,6 @@ class Event : public BaseObject<_cl_event>, public IDNode { Event(CommandQueue *cmdQueue, cl_command_type cmdType, TaskCountType taskLevel, TaskCountType taskCount); - Event(const Event &) = delete; - Event &operator=(const Event &) = delete; - ~Event() override; void setupBcs(aub_stream::EngineType bcsEngineType); @@ -409,4 +406,6 @@ class Event : public BaseObject<_cl_event>, public IDNode { // can be accessed only with updateTaskCount std::atomic taskCount{0}; }; + +static_assert(NEO::NonCopyableAndNonMovable); } // namespace NEO diff --git a/opencl/source/event/event_builder.h b/opencl/source/event/event_builder.h index 2ff0d837ef..c80c17a3fb 100644 --- a/opencl/source/event/event_builder.h +++ b/opencl/source/event/event_builder.h @@ -1,11 +1,12 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/utilities/arrayref.h" #include "shared/source/utilities/stackvec.h" @@ -17,7 +18,7 @@ namespace NEO { class Event; -class EventBuilder { +class EventBuilder : NEO::NonCopyableAndNonMovableClass { public: template void create(ArgsT &&...args) { @@ -25,10 +26,6 @@ class EventBuilder { } EventBuilder() = default; - EventBuilder(const EventBuilder &) = delete; - EventBuilder &operator=(const EventBuilder &) = delete; - EventBuilder(EventBuilder &&) = delete; - EventBuilder &operator=(EventBuilder &&) = delete; ~EventBuilder(); @@ -63,4 +60,7 @@ class EventBuilder { StackVec parentEvents; bool doNotRegister = false; }; + +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/helpers/base_object.h b/opencl/source/helpers/base_object.h index 11357c1e5f..68e32bebec 100644 --- a/opencl/source/helpers/base_object.h +++ b/opencl/source/helpers/base_object.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #pragma once #include "shared/source/helpers/abort.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/utilities/reference_tracked_object.h" #include "opencl/source/api/dispatch.h" @@ -132,7 +133,7 @@ class TakeOwnershipWrapper { // This class should act as a base class for all CL objects. It will handle the // MT safe and reference things for every CL object. template -class BaseObject : public B, public ReferenceTrackedObject> { +class BaseObject : public B, public ReferenceTrackedObject>, NEO::NonCopyableAndNonMovableClass { public: typedef BaseObject ThisType; typedef B BaseType; @@ -141,9 +142,6 @@ class BaseObject : public B, public ReferenceTrackedObject> { const static cl_ulong maskMagic = 0xFFFFFFFFFFFFFFFFLL; const static cl_ulong deadMagic = 0xFFFFFFFFFFFFFFFFLL; - BaseObject(const BaseObject &) = delete; - BaseObject &operator=(const BaseObject &) = delete; - protected: cl_long magic; diff --git a/opencl/source/helpers/dispatch_info.h b/opencl/source/helpers/dispatch_info.h index 00019a113f..2ccfff205f 100644 --- a/opencl/source/helpers/dispatch_info.h +++ b/opencl/source/helpers/dispatch_info.h @@ -1,11 +1,12 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/helpers/registered_method_dispatcher.h" #include "shared/source/helpers/vec.h" #include "shared/source/utilities/stackvec.h" @@ -82,16 +83,13 @@ class DispatchInfo { Vec3 swgs{0, 0, 0}; // start of work groups }; -struct MultiDispatchInfo { +struct MultiDispatchInfo : NEO::NonCopyableAndNonMovableClass { ~MultiDispatchInfo(); explicit MultiDispatchInfo(Kernel *mainKernel) : mainKernel(mainKernel) {} explicit MultiDispatchInfo(const BuiltinOpParams &operationParams) : builtinOpParams(operationParams) {} MultiDispatchInfo() = default; - MultiDispatchInfo &operator=(const MultiDispatchInfo &) = delete; - MultiDispatchInfo(const MultiDispatchInfo &) = delete; - bool empty() const { return dispatchInfos.size() == 0; } @@ -195,4 +193,7 @@ struct MultiDispatchInfo { std::unique_ptr kernelObjsForAuxTranslation; Kernel *mainKernel = nullptr; }; + +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/kernel/kernel.h b/opencl/source/kernel/kernel.h index a98a37cb11..f13b370cfd 100644 --- a/opencl/source/kernel/kernel.h +++ b/opencl/source/kernel/kernel.h @@ -10,6 +10,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/device/device.h" #include "shared/source/helpers/aux_translation.h" +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/helpers/vec.h" #include "shared/source/kernel/implicit_args_helper.h" #include "shared/source/kernel/kernel_execution_type.h" @@ -42,7 +43,7 @@ class PrintfHandler; class MultiDeviceKernel; class LocalIdsCache; -class Kernel : public ReferenceTrackedObject { +class Kernel : public ReferenceTrackedObject, NEO::NonCopyableAndNonMovableClass { public: static const uint32_t kernelBinaryAlignment = 64; @@ -112,9 +113,6 @@ class Kernel : public ReferenceTrackedObject { return pKernel; } - Kernel &operator=(const Kernel &) = delete; - Kernel(const Kernel &) = delete; - ~Kernel() override; static bool isMemObj(KernelArgType kernelArg) { @@ -529,4 +527,6 @@ class Kernel : public ReferenceTrackedObject { bool isDestinationAllocationInSystemMemory = false; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/platform/platform.h b/opencl/source/platform/platform.h index 02835d99be..f2b078dd5b 100644 --- a/opencl/source/platform/platform.h +++ b/opencl/source/platform/platform.h @@ -37,9 +37,6 @@ class Platform : public BaseObject<_cl_platform_id> { Platform(ExecutionEnvironment &executionEnvironment); ~Platform() override; - Platform(const Platform &) = delete; - Platform &operator=(Platform const &) = delete; - cl_int getInfo(cl_platform_info paramName, size_t paramValueSize, void *paramValue, @@ -73,5 +70,8 @@ class Platform : public BaseObject<_cl_platform_id> { std::once_flag oclInitGTPinOnce; }; +static_assert(NEO::NonCopyableAndNonMovable>); +static_assert(NEO::NonCopyableAndNonMovable); + extern std::vector> *platformsImpl; } // namespace NEO diff --git a/opencl/source/program/program.h b/opencl/source/program/program.h index a73ae0ee19..5e071e211d 100644 --- a/opencl/source/program/program.h +++ b/opencl/source/program/program.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -126,9 +126,6 @@ class Program : public BaseObject<_cl_program> { Program(Context *context, bool isBuiltIn, const ClDeviceVector &clDevicesIn); ~Program() override; - Program(const Program &) = delete; - Program &operator=(const Program &) = delete; - cl_int build(const ClDeviceVector &deviceVector, const char *buildOptions); cl_int build(const ClDeviceVector &deviceVector, const char *buildOptions, @@ -397,4 +394,6 @@ class Program : public BaseObject<_cl_program> { } decodedSingleDeviceBinary; }; +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/sharings/gl/gl_buffer.h b/opencl/source/sharings/gl/gl_buffer.h index c407d94d24..f50b6a5885 100644 --- a/opencl/source/sharings/gl/gl_buffer.h +++ b/opencl/source/sharings/gl/gl_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" + #include "opencl/source/sharings/gl/gl_sharing.h" #include "CL/cl_gl.h" @@ -17,7 +19,7 @@ namespace NEO { class Buffer; class Context; -class GlBuffer : public GlSharing { +class GlBuffer : public GlSharing, NEO::NonCopyableAndNonMovableClass { public: static Buffer *createSharedGlBuffer(Context *context, cl_mem_flags flags, unsigned int bufferId, cl_int *errcodeRet); void synchronizeObject(UpdateData &updateData) override; @@ -29,8 +31,6 @@ class GlBuffer : public GlSharing { ~GlBuffer() override { callReleaseResource(true); } - GlBuffer(const GlBuffer &other) = delete; - GlBuffer &operator=(const GlBuffer &other) = delete; void releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) override; void callReleaseResource(bool createOrDestroy); @@ -39,4 +39,7 @@ class GlBuffer : public GlSharing { static GraphicsAllocation *createGraphicsAllocation(Context *context, unsigned int bufferId, _tagCLGLBufferInfo &bufferInfo); }; + +static_assert(NEO::NonCopyableAndNonMovable); + } // namespace NEO diff --git a/opencl/source/tracing/tracing_notify.h b/opencl/source/tracing/tracing_notify.h index b103d8eab7..6ae39f42a6 100644 --- a/opencl/source/tracing/tracing_notify.h +++ b/opencl/source/tracing/tracing_notify.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 Intel Corporation + * Copyright (C) 2019-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/utilities/cpuintrinsics.h" #include "opencl/source/tracing/tracing_handle.h" @@ -29,16 +30,12 @@ namespace HostSideTracing { inline thread_local bool tracingInProgress = false; -class CheckIfExitCalled { +class CheckIfExitCalled : NEO::NonCopyableAndNonMovableClass { public: CheckIfExitCalled() = default; ~CheckIfExitCalled() { UNRECOVERABLE_IF(!tracingExited); } - CheckIfExitCalled(CheckIfExitCalled &&other) noexcept = delete; - CheckIfExitCalled(const CheckIfExitCalled &other) = delete; - CheckIfExitCalled &operator=(CheckIfExitCalled &&other) noexcept = delete; - CheckIfExitCalled &operator=(const CheckIfExitCalled &other) = delete; void exit() { tracingExited = true; @@ -48,6 +45,8 @@ class CheckIfExitCalled { bool tracingExited = false; }; +static_assert(NEO::NonCopyableAndNonMovable); + #define TRACING_ENTER(name, ...) \ bool isHostSideTracingEnabled_##name = false; \ bool currentlyTracedCall = false; \ diff --git a/shared/source/helpers/non_copyable_or_moveable.h b/shared/source/helpers/non_copyable_or_moveable.h index dab5cd091c..d2326b9522 100644 --- a/shared/source/helpers/non_copyable_or_moveable.h +++ b/shared/source/helpers/non_copyable_or_moveable.h @@ -30,16 +30,17 @@ class NonCopyableClass { NonCopyableClass &operator=(NonCopyableClass &&) = default; }; -template -concept NonCopyableAndNonMovable = ! -std::is_copy_constructible_v && - !std::is_copy_assignable_v && - !std::is_move_constructible_v && - !std::is_move_assignable_v; - template concept NonCopyable = ! std::is_copy_constructible_v && !std::is_copy_assignable_v; +template +concept NonMovable = ! +std::is_move_constructible_v && + !std::is_move_assignable_v; + +template +concept NonCopyableAndNonMovable = NonCopyable && NonMovable; + } // namespace NEO