2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-01-12 21:18:53 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/api/cl_types.h"
|
|
|
|
#include "runtime/device/device_info_map.h"
|
|
|
|
#include "runtime/helpers/base_object.h"
|
|
|
|
#include "runtime/helpers/hw_info.h"
|
2017-11-14 18:15:09 +08:00
|
|
|
#include "runtime/helpers/engine_node.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/performance_counters.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
class CommandStreamReceiver;
|
|
|
|
class GraphicsAllocation;
|
|
|
|
class MemoryManager;
|
|
|
|
class OSTime;
|
|
|
|
class DriverInfo;
|
|
|
|
struct HardwareInfo;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OpenCLObjectMapper<_cl_device_id> {
|
|
|
|
typedef class Device DerivedType;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Device : public BaseObject<_cl_device_id> {
|
|
|
|
protected:
|
|
|
|
MemoryManager *memoryManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const cl_ulong objectMagic = 0x8055832341AC8D08LL;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static T *create(const HardwareInfo *pHwInfo,
|
|
|
|
bool isRootDevice = true) {
|
|
|
|
pHwInfo = getDeviceInitHwInfo(pHwInfo);
|
|
|
|
T *device = new T(*pHwInfo);
|
|
|
|
if (false == createDeviceImpl(pHwInfo, isRootDevice, *device)) {
|
|
|
|
delete device;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
Device &operator=(const Device &) = delete;
|
|
|
|
Device(const Device &) = delete;
|
|
|
|
|
|
|
|
~Device() override;
|
|
|
|
|
|
|
|
// API entry points
|
|
|
|
cl_int getDeviceInfo(cl_device_info paramName,
|
|
|
|
size_t paramValueSize,
|
|
|
|
void *paramValue,
|
|
|
|
size_t *paramValueSizeRet);
|
|
|
|
|
|
|
|
bool getDeviceAndHostTimer(uint64_t *deviceTimestamp, uint64_t *hostTimestamp) const;
|
|
|
|
bool getHostTimer(uint64_t *hostTimestamp) const;
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
const HardwareInfo &getHardwareInfo() const;
|
|
|
|
const DeviceInfo &getDeviceInfo() const;
|
|
|
|
DeviceInfo *getMutableDeviceInfo();
|
|
|
|
MOCKABLE_VIRTUAL const WorkaroundTable *getWaTable() const;
|
2018-02-12 18:48:31 +08:00
|
|
|
EngineType getEngineType() const {
|
2018-02-09 05:52:58 +08:00
|
|
|
return engineType;
|
2018-02-12 18:48:31 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void *getSLMWindowStartAddress();
|
|
|
|
void prepareSLMWindow();
|
|
|
|
void setForce32BitAddressing(bool value) {
|
|
|
|
deviceInfo.force32BitAddressess = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandStreamReceiver &getCommandStreamReceiver();
|
2018-01-17 23:23:51 +08:00
|
|
|
CommandStreamReceiver *peekCommandStreamReceiver();
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
volatile uint32_t *getTagAddress() const;
|
|
|
|
|
|
|
|
const char *getProductAbbrev() const;
|
|
|
|
|
|
|
|
// This helper template is meant to simplify getDeviceInfo
|
|
|
|
template <cl_device_info Param>
|
|
|
|
void getCap(const void *&src,
|
|
|
|
size_t &size,
|
|
|
|
size_t &retSize);
|
|
|
|
|
|
|
|
template <cl_device_info Param>
|
|
|
|
void getStr(const void *&src,
|
|
|
|
size_t &size,
|
|
|
|
size_t &retSize);
|
|
|
|
|
|
|
|
MemoryManager *getMemoryManager() const;
|
|
|
|
|
|
|
|
/* We hide the retain and release function of BaseObject. */
|
|
|
|
void retain() override;
|
|
|
|
unique_ptr_if_unused<Device> release() override;
|
|
|
|
bool isRootDevice() const { return isRoot; }
|
|
|
|
OSTime *getOSTime() const { return osTime.get(); };
|
|
|
|
double getProfilingTimerResolution();
|
|
|
|
void increaseProgramCount() { programCount++; }
|
|
|
|
uint64_t getProgramCount() { return programCount; }
|
|
|
|
unsigned int getEnabledClVersion() const { return enabledClVersion; };
|
|
|
|
unsigned int getSupportedClVersion() const;
|
|
|
|
double getPlatformHostTimerResolution() const;
|
|
|
|
bool isSimulation();
|
|
|
|
void checkPriorityHints();
|
|
|
|
GFXCORE_FAMILY getRenderCoreFamily() const;
|
|
|
|
PerformanceCounters *getPerformanceCounters() { return performanceCounters.get(); }
|
|
|
|
static decltype(&PerformanceCounters::create) createPerformanceCountersFunc;
|
2018-01-02 19:10:34 +08:00
|
|
|
PreemptionMode getPreemptionMode() const { return preemptionMode; }
|
2018-01-12 21:18:53 +08:00
|
|
|
GraphicsAllocation *getPreemptionAllocation() const { return preemptionAllocation; }
|
2017-12-21 07:45:38 +08:00
|
|
|
MOCKABLE_VIRTUAL const WhitelistedRegisters &getWhitelistedRegisters() { return hwInfo.capabilityTable.whitelistedRegisters; }
|
|
|
|
std::vector<unsigned int> simultaneousInterops;
|
|
|
|
std::string deviceExtensions;
|
|
|
|
bool getEnabled64kbPages();
|
2018-04-06 20:25:22 +08:00
|
|
|
bool isSourceLevelDebuggerActive();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Device() = delete;
|
|
|
|
Device(const HardwareInfo &hwInfo,
|
|
|
|
bool isRootDevice = true);
|
|
|
|
|
|
|
|
static bool createDeviceImpl(const HardwareInfo *pHwInfo,
|
|
|
|
bool isRootDevice, Device &outDevice);
|
|
|
|
static const HardwareInfo *getDeviceInitHwInfo(const HardwareInfo *pHwInfoIn);
|
|
|
|
void initializeCaps();
|
|
|
|
void appendOSExtensions(std::string &deviceExtensions);
|
|
|
|
|
|
|
|
unsigned int enabledClVersion;
|
|
|
|
|
|
|
|
const HardwareInfo &hwInfo;
|
|
|
|
DeviceInfo deviceInfo;
|
|
|
|
|
|
|
|
const bool isRoot;
|
|
|
|
CommandStreamReceiver *commandStreamReceiver;
|
|
|
|
|
|
|
|
volatile uint32_t *tagAddress;
|
|
|
|
GraphicsAllocation *tagAllocation;
|
2018-01-12 21:18:53 +08:00
|
|
|
GraphicsAllocation *preemptionAllocation;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::unique_ptr<OSTime> osTime;
|
|
|
|
std::unique_ptr<DriverInfo> driverInfo;
|
|
|
|
std::unique_ptr<PerformanceCounters> performanceCounters;
|
|
|
|
uint64_t programCount = 0u;
|
|
|
|
|
|
|
|
void *slmWindowStartAddress;
|
|
|
|
|
|
|
|
std::string exposedBuiltinKernels = "";
|
|
|
|
|
|
|
|
PreemptionMode preemptionMode;
|
2018-02-09 05:52:58 +08:00
|
|
|
EngineType engineType;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <cl_device_info Param>
|
|
|
|
inline void Device::getCap(const void *&src,
|
|
|
|
size_t &size,
|
|
|
|
size_t &retSize) {
|
|
|
|
src = &DeviceInfoTable::Map<Param>::getValue(deviceInfo);
|
|
|
|
retSize = size = DeviceInfoTable::Map<Param>::size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CommandStreamReceiver &Device::getCommandStreamReceiver() {
|
|
|
|
return *commandStreamReceiver;
|
|
|
|
}
|
|
|
|
|
2018-01-17 23:23:51 +08:00
|
|
|
inline CommandStreamReceiver *Device::peekCommandStreamReceiver() {
|
|
|
|
return commandStreamReceiver;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
inline volatile uint32_t *Device::getTagAddress() const {
|
|
|
|
return tagAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline MemoryManager *Device::getMemoryManager() const {
|
|
|
|
return memoryManager;
|
|
|
|
}
|
|
|
|
} // namespace OCLRT
|