Files
rocm-systems/projects/clr/rocclr/runtime/device/gpu/gpuwavelimiter.hpp
T
foreman 31ec44ded5 P4 to Git Change 1144775 by yaxunl@yaxunl_stg_win50 on 2015/04/27 12:11:07
ECR #304775 - Wave limiter: Fix crash in CompuBenchCL video composition due to profiling data not collected correctly.

	Gpuvirtual.cpp only collects profiling data when all events have profiling enabled. Fixed it by adding a member to indicate at least one event has profiling enabled and collect profiling data.

	Improved adptation by changing waves/simd only when the last change has been enforced. Also detecting discontinuities in measured data and discard them.

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#359 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#129 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuwavelimiter.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuwavelimiter.hpp#2 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#230 edit


[ROCm/clr commit: b5a5c65e53]
2015-04-27 12:21:03 -04:00

93 lines
2.5 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> measure_;
std::vector<ulong> reference_;
std::vector<ulong> trial_;
std::vector<ulong> ratio_;
bool discontinuous_; // Measured data is discontinuous
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_;
mutable bool waveSet_;
uint dataCount_;
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
static uint DscThresh; // Threshold for identifying discontinuities
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