1 /* 2 * Copyright (C) 2020-2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #pragma once 9 10 #include "shared/source/command_stream/csr_definitions.h" 11 #include "shared/source/command_stream/submissions_aggregator.h" 12 #include "shared/source/helpers/constants.h" 13 #include "shared/source/indirect_heap/indirect_heap.h" 14 15 #include "level_zero/core/source/cmdqueue/cmdqueue.h" 16 17 #include <vector> 18 19 namespace NEO { 20 class LinearStream; 21 class GraphicsAllocation; 22 class MemoryManager; 23 24 } // namespace NEO 25 26 namespace L0 { 27 struct CommandList; 28 struct Kernel; 29 struct CommandQueueImp : public CommandQueue { 30 class CommandBufferManager { 31 public: 32 enum BUFFER_ALLOCATION : uint32_t { 33 FIRST = 0, 34 SECOND, 35 COUNT 36 }; 37 38 ze_result_t initialize(Device *device, size_t sizeRequested); 39 void destroy(Device *device); 40 void switchBuffers(NEO::CommandStreamReceiver *csr); 41 getCurrentBufferAllocationCommandQueueImp42 NEO::GraphicsAllocation *getCurrentBufferAllocation() { 43 return buffers[bufferUse]; 44 } 45 setCurrentFlushStampCommandQueueImp46 void setCurrentFlushStamp(uint32_t taskCount, NEO::FlushStamp flushStamp) { 47 flushId[bufferUse] = std::make_pair(taskCount, flushStamp); 48 } getCurrentFlushStampCommandQueueImp49 std::pair<uint32_t, NEO::FlushStamp> &getCurrentFlushStamp() { 50 return flushId[bufferUse]; 51 } 52 53 private: 54 NEO::GraphicsAllocation *buffers[BUFFER_ALLOCATION::COUNT]; 55 std::pair<uint32_t, NEO::FlushStamp> flushId[BUFFER_ALLOCATION::COUNT]; 56 BUFFER_ALLOCATION bufferUse = BUFFER_ALLOCATION::FIRST; 57 }; 58 static constexpr size_t defaultQueueCmdBufferSize = 128 * MemoryConstants::kiloByte; 59 static constexpr size_t minCmdBufferPtrAlign = 8; 60 static constexpr size_t totalCmdBufferSize = 61 defaultQueueCmdBufferSize + 62 MemoryConstants::cacheLineSize + 63 NEO::CSRequirements::csOverfetchSize; 64 65 CommandQueueImp() = delete; 66 CommandQueueImp(Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc); 67 68 ze_result_t destroy() override; 69 70 ze_result_t synchronize(uint64_t timeout) override; 71 72 ze_result_t initialize(bool copyOnly, bool isInternal); 73 getDeviceCommandQueueImp74 Device *getDevice() { return device; } 75 getTaskCountCommandQueueImp76 uint32_t getTaskCount() { return taskCount; } 77 getCsrCommandQueueImp78 NEO::CommandStreamReceiver *getCsr() { return csr; } 79 80 void reserveLinearStreamSize(size_t size); 81 ze_command_queue_mode_t getSynchronousMode() const; 82 virtual void dispatchTaskCountWrite(NEO::LinearStream &commandStream, bool flushDataCache) = 0; 83 virtual bool getPreemptionCmdProgramming() = 0; 84 85 protected: 86 MOCKABLE_VIRTUAL int submitBatchBuffer(size_t offset, NEO::ResidencyContainer &residencyContainer, void *endingCmdPtr, 87 bool isCooperative); 88 89 ze_result_t synchronizeByPollingForTaskCount(uint64_t timeout); 90 91 void printFunctionsPrintfOutput(); 92 93 void postSyncOperations(); 94 95 CommandBufferManager buffers; 96 NEO::HeapContainer heapContainer; 97 ze_command_queue_desc_t desc; 98 std::vector<Kernel *> printfFunctionContainer; 99 100 Device *device = nullptr; 101 NEO::CommandStreamReceiver *csr = nullptr; 102 NEO::LinearStream *commandStream = nullptr; 103 104 std::atomic<uint32_t> taskCount{0}; 105 106 bool gpgpuEnabled = false; 107 bool useKmdWaitFunction = false; 108 }; 109 110 } // namespace L0 111