Function bodies 55 total
PrintResult method · cpp · L1270-L1283 (14 LOC)simulator.hpp
void Rater::PrintResult(const GpuSimulator &gpu_sim) const {
std::cerr << "Error Rate: ";
float total_ans = 0;
for (const auto &ans : answers_) {
total_ans += ans->GetSize();
}
std::cerr << std::fixed << std::setprecision(6)
<< GetErrorsCount() / total_ans << std::endl;
std::cerr << "Max GPU HBM used: " << gpu_sim.max_gpu_hbm_size_ << std::endl;
std::cerr << "Max Shared Memory used: " << gpu_sim.max_shared_mem_size_
<< std::endl;
std::cerr << "Total GPU cycles: " << gpu_sim.gpu_sim_cycle_ << std::endl;
}PrintInstruction method · cpp · L1284-L1371 (88 LOC)simulator.hpp
void GpuSimulator::PrintInstruction(
const CalculationInstruction &instruction,
const MatrixMemoryAllocator &matrix_memory_allocator) const {
auto instruction_type = std::get<1>(instruction);
auto matrix1 = std::get<2>(instruction);
auto matrix2 = std::get<3>(instruction);
auto result = std::get<5>(instruction);
switch (instruction_type) {
case InstructionType::kMatAdd: {
std::cerr << "MatAdd: ";
break;
}
case InstructionType::kMatSub: {
std::cerr << "MatSub: ";
break;
}
case InstructionType::kMatmul: {
std::cerr << "MatMul: ";
break;
}
case InstructionType::kMatExp: {
std::cerr << "MatExp: ";
break;
}
case InstructionType::kMatDiv: {
std::cerr << "MatDiv: ";
break;
}
case InstructionType::kAddBias: {
std::cerr << "AddBias: ";
break;
}
case InstructionType::kConcat: {
std::cerr << "Concat: ";
break;
}
case InstructionType::kGetRow: {
std::cerr << "GetRow: ";
break;
}
casPrintInstruction method · cpp · L1372-L1397 (26 LOC)simulator.hpp
void GpuSimulator::PrintInstruction(
const IoInstruction &instruction,
const MatrixMemoryAllocator &matrix_memory_allocator) const {
auto instruction_type = std::get<1>(instruction);
auto matrix = std::get<2>(instruction);
switch (instruction_type) {
case InstructionType::kToGpuHbm: {
std::cerr << "Move to GPU HBM: ";
break;
}
case InstructionType::kToSharedMem: {
std::cerr << "Move to Shared Memory: ";
break;
}
default: {
std::cerr << "Calculation operation should not be in IO queue! please "
"contact TA.";
exit(EXIT_FAILURE);
}
}
if (matrix != nullptr) {
std::cerr << "Matrix: " << matrix_memory_allocator.GetMatrixName(matrix);
}
std::cerr << std::endl;
}Calculate function · cpp · L4-L150 (147 LOC)src.hpp
void Calculate(std::vector<Matrix *> keys, std::vector<Matrix *> values,
Rater &rater, GpuSimulator &gpu_sim,
MatrixMemoryAllocator matrix_memory_allocator) {
assert(keys.size() == values.size());
for (size_t i = 0; i < keys.size(); ++i) {
auto current_query = rater.GetNextQuery();
/*
* Implement your calculation logic here.
* You can use the GpuSimulator instance to perform matrix operations.
* For example:
* gpu_sim.MoveMatrixToGpuHbm(keys[i]);
* When your need a new matrix, to avoid memory leak, you should use
* Matrix* new_matrix =
* matrix_memory_allocator.Allocate(YOUR_MATRIX_NAME(string, which is
* helpful for debugging)); It can manage the memory of matrices
* automatically.
*/
/*
*
*
*
*
*
*
* YOUR CODE HERE
*
*
*
*
*
*
*/
// Move query to SRAM for computation
gpu_sim.MoveMatrixToSharedMem(current_query)Test function · cpp · L151-L157 (7 LOC)src.hpp
void Test(Rater &rater, GpuSimulator &gpu_sim,
MatrixMemoryAllocator &matrix_memory_allocator) {
Calculate(rater.keys_, rater.values_, rater, gpu_sim,
matrix_memory_allocator);
rater.PrintResult(gpu_sim);
}‹ prevpage 2 / 2