/* * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/debugger/debugger.h" #include "shared/source/device/device_info.h" #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/bindless_heaps_helper.h" #include "shared/source/helpers/common_types.h" #include "shared/source/helpers/engine_control.h" #include "shared/source/helpers/engine_node_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/program/sync_buffer_handler.h" #include "opencl/source/os_interface/performance_counters.h" #include "engine_group_types.h" namespace NEO { class OSTime; class SourceLevelDebugger; class Device : public ReferenceTrackedObject { public: Device &operator=(const Device &) = delete; Device(const Device &) = delete; ~Device() override; template static DeviceT *create(ArgsT &&...args) { DeviceT *device = new DeviceT(std::forward(args)...); return createDeviceInternals(device); } virtual void incRefInternal() { ReferenceTrackedObject::incRefInternal(); } virtual unique_ptr_if_unused decRefInternal() { return ReferenceTrackedObject::decRefInternal(); } bool getDeviceAndHostTimer(uint64_t *deviceTimestamp, uint64_t *hostTimestamp) const; bool getHostTimer(uint64_t *hostTimestamp) const; const HardwareInfo &getHardwareInfo() const; const DeviceInfo &getDeviceInfo() const; EngineControl &getEngine(aub_stream::EngineType engineType, EngineUsage engineUsage); std::vector> &getEngineGroups() { return this->engineGroups; } const std::vector *getNonEmptyEngineGroup(size_t index) const; size_t getIndexOfNonEmptyEngineGroup(EngineGroupType engineGroupType) const; EngineControl &getEngine(uint32_t index); EngineControl &getDefaultEngine(); EngineControl &getInternalEngine(); EngineControl *getInternalCopyEngine(); std::atomic &getSelectorCopyEngine(); MemoryManager *getMemoryManager() const; GmmHelper *getGmmHelper() const; GmmClientContext *getGmmClientContext() const; OSTime *getOSTime() const { return osTime.get(); }; double getProfilingTimerResolution(); uint64_t getProfilingTimerClock(); double getPlatformHostTimerResolution() const; bool isSimulation() const; GFXCORE_FAMILY getRenderCoreFamily() const; PerformanceCounters *getPerformanceCounters() { return performanceCounters.get(); } PreemptionMode getPreemptionMode() const { return preemptionMode; } MOCKABLE_VIRTUAL bool isDebuggerActive() const; Debugger *getDebugger() const { return getRootDeviceEnvironment().debugger.get(); } NEO::SourceLevelDebugger *getSourceLevelDebugger(); const std::vector &getEngines() const; const std::string getDeviceName(const HardwareInfo &hwInfo) const; ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; } const RootDeviceEnvironment &getRootDeviceEnvironment() const { return *executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]; } const HardwareCapabilities &getHardwareCapabilities() const { return hardwareCapabilities; } bool isFullRangeSvm() const { return getRootDeviceEnvironment().isFullRangeSvm(); } bool areSharedSystemAllocationsAllowed() const { return this->deviceInfo.sharedSystemAllocationsSupport; } template void setSpecializedDevice(SpecializedDeviceT *specializedDevice) { this->specializedDevice = reinterpret_cast(specializedDevice); } template SpecializedDeviceT *getSpecializedDevice() const { return reinterpret_cast(specializedDevice); } MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface() const; BuiltIns *getBuiltIns() const; void allocateSyncBufferHandler(); virtual uint32_t getRootDeviceIndex() const = 0; virtual uint32_t getNumAvailableDevices() const = 0; virtual Device *getDeviceById(uint32_t deviceId) const = 0; virtual Device *getParentDevice() const = 0; virtual DeviceBitfield getDeviceBitfield() const = 0; virtual BindlessHeapsHelper *getBindlessHeapsHelper() const = 0; static decltype(&PerformanceCounters::create) createPerformanceCountersFunc; std::unique_ptr syncBufferHandler; protected: Device() = delete; Device(ExecutionEnvironment *executionEnvironment); MOCKABLE_VIRTUAL void initializeCaps(); template static T *createDeviceInternals(T *device) { if (false == device->createDeviceImpl()) { delete device; return nullptr; } return device; } virtual bool createDeviceImpl(); virtual bool createEngines(); void addEngineToEngineGroup(EngineControl &engine); bool createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage); MOCKABLE_VIRTUAL std::unique_ptr createCommandStreamReceiver() const; virtual uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const; DeviceInfo deviceInfo = {}; HardwareCapabilities hardwareCapabilities = {}; std::unique_ptr osTime; std::unique_ptr performanceCounters; std::vector> commandStreamReceivers; std::vector engines; std::vector> engineGroups; PreemptionMode preemptionMode; ExecutionEnvironment *executionEnvironment = nullptr; uint32_t defaultEngineIndex = 0; std::atomic selectorCopyEngine{0}; uintptr_t specializedDevice = reinterpret_cast(nullptr); }; inline EngineControl &Device::getDefaultEngine() { return engines[defaultEngineIndex]; } inline MemoryManager *Device::getMemoryManager() const { return executionEnvironment->memoryManager.get(); } inline GmmHelper *Device::getGmmHelper() const { return getRootDeviceEnvironment().getGmmHelper(); } inline CompilerInterface *Device::getCompilerInterface() const { return executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->getCompilerInterface(); } inline BuiltIns *Device::getBuiltIns() const { return executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->getBuiltIns(); } inline std::atomic &Device::getSelectorCopyEngine() { return selectorCopyEngine; } } // namespace NEO