2018-08-23 23:53:58 +08:00
|
|
|
/*
|
2025-02-11 22:31:01 +08:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2018-08-23 23:53:58 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-08-23 23:53:58 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2021-03-09 02:50:32 +08:00
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
2023-06-29 20:53:36 +08:00
|
|
|
#include "shared/source/helpers/mt_helpers.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/reference_tracked_object.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2021-04-16 00:14:04 +08:00
|
|
|
#include <mutex>
|
2018-08-27 21:48:29 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-08-23 23:53:58 +08:00
|
|
|
class OSInterface;
|
2018-12-10 17:30:39 +08:00
|
|
|
|
2021-02-10 23:13:50 +08:00
|
|
|
struct DirectSubmissionProperties;
|
|
|
|
struct HardwareInfo;
|
|
|
|
|
2018-08-27 21:48:29 +08:00
|
|
|
class OsContext : public ReferenceTrackedObject<OsContext> {
|
2018-08-23 23:53:58 +08:00
|
|
|
public:
|
2022-11-17 03:31:25 +08:00
|
|
|
OsContext(uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor);
|
|
|
|
static OsContext *create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor);
|
2021-04-16 00:14:04 +08:00
|
|
|
|
|
|
|
bool isImmediateContextInitializationEnabled(bool isDefaultEngine) const;
|
|
|
|
bool isInitialized() const { return contextInitialized; }
|
2024-06-06 23:23:40 +08:00
|
|
|
bool ensureContextInitialized(bool allocateInterrupt);
|
2021-04-16 00:14:04 +08:00
|
|
|
|
2018-12-10 17:30:39 +08:00
|
|
|
uint32_t getContextId() const { return contextId; }
|
2023-03-31 19:41:17 +08:00
|
|
|
virtual uint64_t getOfflineDumpContextId(uint32_t deviceIndex) const { return 0; };
|
2019-03-06 01:50:10 +08:00
|
|
|
uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
|
2019-03-13 22:00:07 +08:00
|
|
|
DeviceBitfield getDeviceBitfield() const { return deviceBitfield; }
|
2019-02-27 18:17:17 +08:00
|
|
|
PreemptionMode getPreemptionMode() const { return preemptionMode; }
|
2022-06-28 23:10:24 +08:00
|
|
|
const aub_stream::EngineType &getEngineType() const { return engineType; }
|
2025-04-22 17:09:34 +08:00
|
|
|
EngineUsage getEngineUsage() const { return engineUsage; }
|
2024-07-09 20:15:56 +08:00
|
|
|
void overrideEngineUsage(EngineUsage usage) { engineUsage = usage; }
|
|
|
|
|
2023-12-11 19:02:15 +08:00
|
|
|
bool isRegular() const { return engineUsage == EngineUsage::regular; }
|
|
|
|
bool isLowPriority() const { return engineUsage == EngineUsage::lowPriority; }
|
2024-01-09 01:25:12 +08:00
|
|
|
bool isHighPriority() const { return engineUsage == EngineUsage::highPriority; }
|
2023-12-11 19:02:15 +08:00
|
|
|
bool isInternalEngine() const { return engineUsage == EngineUsage::internal; }
|
|
|
|
bool isCooperativeEngine() const { return engineUsage == EngineUsage::cooperative; }
|
2020-03-04 06:33:31 +08:00
|
|
|
bool isRootDevice() const { return rootDevice; }
|
2023-09-20 21:08:46 +08:00
|
|
|
virtual bool isDirectSubmissionSupported() const { return false; }
|
2020-03-07 02:02:24 +08:00
|
|
|
bool isDefaultContext() const { return defaultContext; }
|
|
|
|
void setDefaultContext(bool value) { defaultContext = value; }
|
2025-02-11 22:31:01 +08:00
|
|
|
bool isDirectSubmissionActive() const { return directSubmissionActive; }
|
2022-09-19 21:34:14 +08:00
|
|
|
bool isDebuggableContext() { return debuggableContext; }
|
2020-10-15 14:48:58 +08:00
|
|
|
void setDirectSubmissionActive() { directSubmissionActive = true; }
|
2018-09-06 21:54:29 +08:00
|
|
|
|
2021-02-10 23:13:50 +08:00
|
|
|
bool isDirectSubmissionAvailable(const HardwareInfo &hwInfo, bool &submitOnInit);
|
|
|
|
bool checkDirectSubmissionSupportsEngine(const DirectSubmissionProperties &directSubmissionProperty,
|
|
|
|
aub_stream::EngineType contextEngineType,
|
|
|
|
bool &startOnInit,
|
|
|
|
bool &startInContext);
|
2021-12-16 10:13:00 +08:00
|
|
|
virtual void reInitializeContext() {}
|
|
|
|
uint8_t getUmdPowerHintValue() { return powerHintValue; }
|
|
|
|
void setUmdPowerHintValue(uint8_t powerHintValue) { this->powerHintValue = powerHintValue; }
|
2021-02-10 23:13:50 +08:00
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
uint32_t getRootDeviceIndex() { return rootDeviceIndex; }
|
|
|
|
|
2023-06-29 20:53:36 +08:00
|
|
|
void setNewResourceBound() {
|
|
|
|
tlbFlushCounter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t peekTlbFlushCounter() const { return tlbFlushCounter.load(); }
|
|
|
|
|
|
|
|
void setTlbFlushed(uint32_t newCounter) {
|
|
|
|
NEO::MultiThreadHelpers::interlockedMax(lastFlushedTlbFlushCounter, newCounter);
|
|
|
|
};
|
|
|
|
bool isTlbFlushRequired() const {
|
|
|
|
return (tlbFlushCounter.load() > lastFlushedTlbFlushCounter.load());
|
|
|
|
};
|
|
|
|
|
2023-11-15 17:01:43 +08:00
|
|
|
void setPrimaryContext(const OsContext *primary) {
|
|
|
|
primaryContext = primary;
|
|
|
|
isContextGroup = true;
|
|
|
|
}
|
|
|
|
const OsContext *getPrimaryContext() const {
|
|
|
|
return primaryContext;
|
|
|
|
}
|
2024-06-25 06:55:08 +08:00
|
|
|
void setIsPrimaryEngine(const bool isPrimaryEngine) {
|
|
|
|
this->isPrimaryEngine = isPrimaryEngine;
|
|
|
|
}
|
|
|
|
bool getIsPrimaryEngine() const {
|
|
|
|
return this->isPrimaryEngine;
|
|
|
|
}
|
|
|
|
void setIsDefaultEngine(const bool isDefaultEngine) {
|
|
|
|
this->isDefaultEngine = isDefaultEngine;
|
|
|
|
}
|
|
|
|
bool getIsDefaultEngine() const {
|
|
|
|
return this->isDefaultEngine;
|
|
|
|
}
|
2023-11-15 17:01:43 +08:00
|
|
|
void setContextGroup(bool value) {
|
|
|
|
isContextGroup = value;
|
|
|
|
}
|
2024-03-26 03:04:34 +08:00
|
|
|
bool isPartOfContextGroup() const {
|
2023-11-15 17:01:43 +08:00
|
|
|
return isContextGroup;
|
|
|
|
}
|
2025-02-11 22:31:01 +08:00
|
|
|
virtual bool isDirectSubmissionLightActive() const { return false; }
|
2023-11-15 17:01:43 +08:00
|
|
|
|
2018-08-23 23:53:58 +08:00
|
|
|
protected:
|
2024-06-06 19:23:55 +08:00
|
|
|
virtual bool initializeContext(bool allocateInterrupt) { return true; }
|
2019-02-27 18:17:17 +08:00
|
|
|
|
2023-06-29 20:53:36 +08:00
|
|
|
std::atomic<uint32_t> tlbFlushCounter{0};
|
|
|
|
std::atomic<uint32_t> lastFlushedTlbFlushCounter{0};
|
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
const uint32_t rootDeviceIndex;
|
2019-02-12 18:31:19 +08:00
|
|
|
const uint32_t contextId;
|
2019-03-13 22:00:07 +08:00
|
|
|
const DeviceBitfield deviceBitfield;
|
2019-02-27 18:17:17 +08:00
|
|
|
const PreemptionMode preemptionMode;
|
2019-03-13 22:00:07 +08:00
|
|
|
const uint32_t numSupportedDevices;
|
2019-03-27 17:06:29 +08:00
|
|
|
aub_stream::EngineType engineType = aub_stream::ENGINE_RCS;
|
2024-07-09 20:15:56 +08:00
|
|
|
EngineUsage engineUsage;
|
2020-03-04 06:33:31 +08:00
|
|
|
const bool rootDevice = false;
|
2020-03-07 02:02:24 +08:00
|
|
|
bool defaultContext = false;
|
2020-10-15 14:48:58 +08:00
|
|
|
bool directSubmissionActive = false;
|
2021-04-16 00:14:04 +08:00
|
|
|
std::once_flag contextInitializedFlag = {};
|
|
|
|
bool contextInitialized = false;
|
2022-09-19 21:34:14 +08:00
|
|
|
bool debuggableContext = false;
|
2021-12-16 10:13:00 +08:00
|
|
|
uint8_t powerHintValue = 0;
|
2023-11-15 17:01:43 +08:00
|
|
|
|
|
|
|
bool isContextGroup = false;
|
|
|
|
const OsContext *primaryContext = nullptr;
|
2024-06-25 06:55:08 +08:00
|
|
|
bool isPrimaryEngine = false;
|
|
|
|
bool isDefaultEngine = false;
|
2018-08-23 23:53:58 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|