493d26db66
ECR #304775 - Implement profile driven wave limiter Part 2/2: OCL changes. Profile driven wave limiter measures kernel execution time in real time and adaptively limits the number of waves per SH. This is to mitigate cache thrashing issues. Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/llvm32/include/llvm/Transforms/IPO/AMDKernelPerfHint.h#2 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm32/lib/Target/AMDIL/AMDILKernelManager.cpp#2 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm32/lib/Transforms/IPO/AMDKernelPerfHint.cpp#2 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#244 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#281 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.hpp#108 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuwavelimiter.cpp#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuwavelimiter.hpp#1 add ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/include/cal/cal.h#35 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp#71 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLContext.h#44 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp#114 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#68 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#74 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#228 edit
89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#ifndef GPUWAVELIMITER_HPP_
|
|
#define GPUWAVELIMITER_HPP_
|
|
|
|
#include "platform/command.hpp"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
|
|
//! \namespace gpu GPU Device Implementation
|
|
namespace gpu {
|
|
|
|
class Kernel;
|
|
|
|
// Adaptively limit the number of waves per SIMD based on kernel execution time
|
|
class WaveLimiter: public amd::ProfilingCallback {
|
|
public:
|
|
explicit WaveLimiter(Kernel*);
|
|
~WaveLimiter();
|
|
uint getWavesPerSH() const;
|
|
amd::ProfilingCallback* getProfilingCallback() const;
|
|
void enable();
|
|
|
|
private:
|
|
enum StateKind {
|
|
WARMUP, ADAPT, RUN
|
|
};
|
|
|
|
class DataDumper {
|
|
public:
|
|
explicit DataDumper(const std::string &kernelName);
|
|
~DataDumper();
|
|
void addData(ulong time, uint wave, char state);
|
|
bool enabled() const { return enable_;}
|
|
private:
|
|
bool enable_;
|
|
std::string fileName_;
|
|
std::vector<ulong> time_;
|
|
std::vector<uint> wavePerSIMD_;
|
|
std::vector<char> state_;
|
|
};
|
|
|
|
std::vector<ulong> counts_;
|
|
std::vector<ulong> sum_;
|
|
std::vector<ulong> average_;
|
|
std::vector<ulong> ratio_;
|
|
|
|
bool enable_;
|
|
uint SIMDPerSH_; // Number of SIMDs per SH
|
|
uint waves_; // waves_ per SIMD
|
|
uint bestWave_; // Optimal waves per SIMD
|
|
uint countAll_; // Number of kernel executions
|
|
uint dynRunCount_;
|
|
StateKind state_;
|
|
Kernel *owner_;
|
|
DataDumper dumper_;
|
|
std::ofstream traceStream_;
|
|
|
|
static uint MaxWave; // Maximum number of waves per SIMD
|
|
static uint WarmUpCount; // Number of kernel executions for warm up
|
|
static uint AdaptCount; // Number of kernel executions for adapting
|
|
static uint RunCount; // Number of kernel executions for normal run
|
|
static uint AbandonThresh; // Threshold to abandon adaptation
|
|
|
|
virtual void callback(ulong duration);
|
|
void updateData(ulong time);
|
|
void outputTrace();
|
|
void clearData();
|
|
|
|
template<class T> void clear(T& A) {
|
|
for (auto &I : A) {
|
|
I = 0;
|
|
}
|
|
}
|
|
template<class T> void output(std::ofstream &ofs, const std::string &prompt,
|
|
T& A) {
|
|
ofs << prompt;
|
|
for (auto &I : A) {
|
|
ofs << ' ' << static_cast<ulong>(I);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
#endif
|