|
| 1 | + |
| 2 | +#include "gpu_inst_count.hpp" |
| 3 | + |
| 4 | +using namespace gtpin_prof; |
| 5 | +using namespace gtpin; |
| 6 | + |
| 7 | +/******************** |
| 8 | + * Requered functions - should be implemented |
| 9 | + */ |
| 10 | + |
| 11 | +PROF_STATUS GpuInstCountKernel::Accumulate(std::shared_ptr<ResultData> profilingResult, |
| 12 | + GTPinProfileRecord* record) { |
| 13 | + auto gpuInstCountRec = reinterpret_cast<GpuInstCountRecord*>(record); |
| 14 | + auto gpuInstCountResult = std::dynamic_pointer_cast<GpuInstCountResultData>(profilingResult); |
| 15 | + |
| 16 | + /// Accumulate data from GpuInstCountRec to GpuInstCountResult here. |
| 17 | + /// For each profiling results may be several records, data should be |
| 18 | + /// accumulated, not just transferred |
| 19 | + gpuInstCountResult->count += gpuInstCountRec->count; |
| 20 | + |
| 21 | + return PROF_STATUS_SUCCESS; |
| 22 | +} |
| 23 | + |
| 24 | +PROF_STATUS GpuInstCountKernel::AnalyzeKernel(IGtKernelInstrument& instrumentor) { |
| 25 | + const IGtKernel& kernel = instrumentor.Kernel(); |
| 26 | + const IGtCfg& cfg = instrumentor.Cfg(); |
| 27 | + const IGtGenArch& genArch = GTPin_GetCore()->GenArch(); |
| 28 | + |
| 29 | + SetRecordSize(sizeof(GpuInstCountRecord)); |
| 30 | + SetDefautBuckets(instrumentor); |
| 31 | + |
| 32 | + for (auto bblPtr : cfg.Bbls()) { |
| 33 | + for (auto insPtr : bblPtr->Instructions()) { |
| 34 | + const IGtIns& ins = *insPtr; |
| 35 | + const InstructionOffset offset = cfg.GetInstructionOffset(ins); |
| 36 | + |
| 37 | + bblData.emplace(offset, bblPtr->FirstIns()); |
| 38 | + } |
| 39 | + } |
| 40 | + /// Set number of records and store required data based on information from |
| 41 | + /// instrumentor |
| 42 | + SetRecordsNum(bblData.size()); |
| 43 | + |
| 44 | + return PROF_STATUS_SUCCESS; |
| 45 | +} |
| 46 | + |
| 47 | +PROF_STATUS GpuInstCountKernel::Instrument(IGtKernelInstrument& instrumentor) { |
| 48 | + const IGtKernel& kernel = instrumentor.Kernel(); |
| 49 | + const IGtCfg& cfg = instrumentor.Cfg(); |
| 50 | + const IGtGenCoder& coder = instrumentor.Coder(); |
| 51 | + IGtVregFactory& vregs = coder.VregFactory(); |
| 52 | + IGtInsFactory& insF = coder.InstructionFactory(); |
| 53 | + |
| 54 | + const IGtGenArch& genArch = GTPin_GetCore()->GenArch(); |
| 55 | + uint32_t grfRegSize = insF.GenModel().GrfRegSize(); // bytes |
| 56 | + |
| 57 | + GtGenProcedure proc; |
| 58 | + |
| 59 | + size_t bblIdx = 0; |
| 60 | + for (auto it = bblData.begin(); it != bblData.end(); it++, bblIdx++) { |
| 61 | + GtGenProcedure proc; |
| 62 | + PointOfInterest poi(instrumentor, m_profileArray, bblIdx); |
| 63 | + poi.InstructionCounterAnalysis(offsetof(GpuInstCountRecord, count)); |
| 64 | + poi.ClosePOI(proc); |
| 65 | + instrumentor.InstrumentInstruction(it->second, GtIpoint::Before(), proc); |
| 66 | + } |
| 67 | + |
| 68 | + return PROF_STATUS_SUCCESS; |
| 69 | +} |
| 70 | + |
| 71 | +/******************** |
| 72 | + * Optional functions - may be changed or not, base on tool behaviour |
| 73 | + */ |
| 74 | + |
| 75 | +PROF_STATUS GpuInstCountKernel::InitResultData(std::shared_ptr<InvocationData> invocationData, |
| 76 | + IGtKernelDispatch& dispatcher, |
| 77 | + const GTPinKernelExecDesriptor& execDescr, |
| 78 | + const std::shared_ptr<IToolFactory> factory) { |
| 79 | + auto invData = std::dynamic_pointer_cast<GpuInstCountInvocationData>(invocationData); |
| 80 | + PTI_ASSERT((invData != nullptr) && "Invocation data was wrongly initialized. Check factory."); |
| 81 | + |
| 82 | + size_t idx = 0; |
| 83 | + for (auto it = bblData.begin(); it != bblData.end(); it++, idx++) { |
| 84 | + auto resData = factory->MakeResultData(); |
| 85 | + auto gpuInstCountResult = std::dynamic_pointer_cast<GpuInstCountResultData>(resData); |
| 86 | + gpuInstCountResult->instructionOffset = it->first; |
| 87 | + invData->data.push_back(gpuInstCountResult); |
| 88 | + } |
| 89 | + |
| 90 | + return PROF_STATUS_SUCCESS; |
| 91 | +}; |
| 92 | + |
| 93 | +PROF_STATUS GpuInstCountKernel::PostProcData(std::shared_ptr<InvocationData> invocationData) { |
| 94 | + return PROF_STATUS_SUCCESS; |
| 95 | +} |
| 96 | + |
| 97 | +/** |
| 98 | + * GpuInstCount implementations |
| 99 | + */ |
| 100 | +std::vector<const char*> GpuInstCount::SetGtpinKnobs() const { |
| 101 | + return std::vector<const char*>{"--no_empty_profile_dir"}; |
| 102 | +}; |
| 103 | + |
| 104 | +/** |
| 105 | + * GpuInstCountFactory implementations |
| 106 | + */ |
| 107 | +std::shared_ptr<GTPinProfileKernel> GpuInstCountFactory::MakeKernel( |
| 108 | + IGtKernelInstrument& instrumentor, std::shared_ptr<KernelData> kernelData) { |
| 109 | + return std::make_shared<GpuInstCountKernel>(instrumentor, kernelData); |
| 110 | +} |
| 111 | + |
| 112 | +GTPinProfileRecord* GpuInstCountFactory::MakeRecord() { |
| 113 | + GpuInstCountRecord* rec = new GpuInstCountRecord(); |
| 114 | + return rec; |
| 115 | +}; |
| 116 | + |
| 117 | +std::shared_ptr<ProfilerData> GpuInstCountFactory::MakeProfilerData() { |
| 118 | + return std::make_shared<GpuInstCountProfilerData>(); |
| 119 | +}; |
| 120 | + |
| 121 | +std::shared_ptr<KernelData> GpuInstCountFactory::MakeKernelData(IGtKernelInstrument& instrumentor) { |
| 122 | + return std::make_shared<GpuInstCountKernelData>(instrumentor); |
| 123 | +}; |
| 124 | + |
| 125 | +std::shared_ptr<InvocationData> GpuInstCountFactory::MakeInvocationData( |
| 126 | + const GTPinKernelExecDesriptor& execDescr) { |
| 127 | + return std::make_shared<GpuInstCountInvocationData>(execDescr); |
| 128 | +}; |
| 129 | + |
| 130 | +std::shared_ptr<ResultData> GpuInstCountFactory::MakeResultData() { |
| 131 | + return std::make_shared<GpuInstCountResultData>(); |
| 132 | +}; |
0 commit comments