1 // Copyright 2020 Intel Corporation 2 // SPDX-License-Identifier: BSD-3-Clause 3 4 #pragma once 5 #include <stdlib.h> 6 #include <unordered_map> 7 #include <vector> 8 9 #include <level_zero/ze_ddi.h> 10 #include <level_zero/zes_ddi.h> 11 #include <level_zero/zet_ddi.h> 12 13 namespace ispcrt { 14 namespace testing { 15 namespace mock { 16 17 enum class CmdListElem { MemoryCopy, KernelLaunch, Barrier }; 18 19 namespace VendorId { 20 constexpr uint32_t Intel = 0x8086; 21 constexpr uint32_t Nvidia = 0x10DE; 22 constexpr uint32_t AMD = 0x1002; 23 } // namespace VendorId 24 25 namespace DeviceId { 26 constexpr uint32_t Gen9 = 0x9BCA; 27 constexpr uint32_t Gen12 = 0xAABB; // some fake number 28 29 constexpr uint32_t GenericNvidia = 0x1234; 30 constexpr uint32_t GenericAMD = 0x5678; 31 } // namespace DeviceIdIntel 32 33 struct DeviceProperties { 34 uint32_t vendorId; 35 uint32_t deviceId; 36 37 DeviceProperties() = default; DevicePropertiesDeviceProperties38 DeviceProperties(uint32_t vendorId, uint32_t deviceId) : vendorId(vendorId), deviceId(deviceId) {} 39 }; 40 41 struct CallCounters { 42 static void inc(const std::string& fun); 43 static int get(const std::string& fun); 44 static void resetAll(); 45 static void resetOne(const std::string& fun); 46 private: 47 static std::unordered_map<std::string, int> counters; 48 }; 49 50 class Config { 51 public: 52 static void setRetValue(const std::string &fun, ze_result_t result); 53 static ze_result_t getRetValue(const std::string &fun); 54 static void cleanup(); 55 static void addToCmdList(CmdListElem cle); 56 static void resetCmdList(); 57 static void closeCmdList(); 58 static bool isCmdListClosed(); 59 static bool checkCmdList(const std::vector<CmdListElem>& expected); 60 static void setDeviceCount(uint32_t count); 61 static DeviceProperties* getDevicePtr(uint32_t deviceIdx); 62 static uint32_t getDeviceCount(); 63 static void setExpectedDevice(uint32_t deviceIdx); 64 static uint32_t getExpectedDevice(); 65 static void setDeviceProperties(uint32_t deviceIdx, const DeviceProperties& dp); 66 67 private: 68 static std::unordered_map<std::string, ze_result_t> resultsMap; 69 static std::vector<CmdListElem> cmdList; 70 static bool cmdListOpened; 71 static std::vector<DeviceProperties> devices; 72 static uint32_t expectedDevice; 73 }; 74 75 } // namespace mock 76 } // namespace testing 77 } // namespace ispcrt 78