2019-09-17 13:22:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Valve Corporation
|
|
|
|
|
* Copyright © 2018 Google
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Daniel Schürmann (daniel.schuermann@campus.tu-berlin.de)
|
|
|
|
|
* Bas Nieuwenhuizen (bas@basnieuwenhuizen.nl)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "aco_ir.h"
|
2019-09-13 16:41:00 +01:00
|
|
|
#include "util/u_math.h"
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace aco {
|
2020-02-21 20:14:03 +00:00
|
|
|
RegisterDemand get_live_changes(aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
RegisterDemand changes;
|
|
|
|
|
for (const Definition& def : instr->definitions) {
|
|
|
|
|
if (!def.isTemp() || def.isKill())
|
|
|
|
|
continue;
|
|
|
|
|
changes += def.getTemp();
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2020-02-21 20:14:03 +00:00
|
|
|
for (const Operand& op : instr->operands) {
|
|
|
|
|
if (!op.isTemp() || !op.isFirstKill())
|
|
|
|
|
continue;
|
|
|
|
|
changes -= op.getTemp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegisterDemand get_temp_registers(aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
RegisterDemand temp_registers;
|
2020-02-21 15:46:39 +00:00
|
|
|
|
2020-02-21 20:14:03 +00:00
|
|
|
for (Definition def : instr->definitions) {
|
|
|
|
|
if (!def.isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
if (def.isKill())
|
|
|
|
|
temp_registers += def.getTemp();
|
|
|
|
|
}
|
2020-02-21 15:46:39 +00:00
|
|
|
|
|
|
|
|
for (Operand op : instr->operands) {
|
|
|
|
|
if (op.isTemp() && op.isLateKill() && op.isFirstKill())
|
|
|
|
|
temp_registers += op.getTemp();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 20:14:03 +00:00
|
|
|
return temp_registers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegisterDemand get_demand_before(RegisterDemand demand, aco_ptr<Instruction>& instr, aco_ptr<Instruction>& instr_before)
|
|
|
|
|
{
|
|
|
|
|
demand -= get_live_changes(instr);
|
|
|
|
|
demand -= get_temp_registers(instr);
|
|
|
|
|
if (instr_before)
|
|
|
|
|
demand += get_temp_registers(instr_before);
|
|
|
|
|
return demand;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace {
|
2019-09-17 13:22:17 +02:00
|
|
|
void process_live_temps_per_block(Program *program, live& lives, Block* block,
|
|
|
|
|
std::set<unsigned>& worklist, std::vector<uint16_t>& phi_sgpr_ops)
|
|
|
|
|
{
|
|
|
|
|
std::vector<RegisterDemand>& register_demand = lives.register_demand[block->index];
|
|
|
|
|
RegisterDemand new_demand;
|
|
|
|
|
|
|
|
|
|
register_demand.resize(block->instructions.size());
|
|
|
|
|
block->register_demand = RegisterDemand();
|
2020-09-14 16:45:55 +01:00
|
|
|
IDSet live = lives.live_out[block->index];
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
/* add the live_out_exec to live */
|
|
|
|
|
bool exec_live = false;
|
|
|
|
|
if (block->live_out_exec != Temp()) {
|
2020-09-14 16:45:55 +01:00
|
|
|
live.insert(block->live_out_exec.id());
|
2019-09-17 13:22:17 +02:00
|
|
|
exec_live = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 13:39:42 +01:00
|
|
|
/* initialize register demand */
|
2020-09-14 16:45:55 +01:00
|
|
|
for (unsigned t : live)
|
|
|
|
|
new_demand += Temp(t, program->temp_rc[t]);
|
2019-09-17 13:22:17 +02:00
|
|
|
new_demand.sgpr -= phi_sgpr_ops[block->index];
|
|
|
|
|
|
|
|
|
|
/* traverse the instructions backwards */
|
2019-10-29 11:56:09 +01:00
|
|
|
int idx;
|
|
|
|
|
for (idx = block->instructions.size() -1; idx >= 0; idx--) {
|
|
|
|
|
Instruction *insn = block->instructions[idx].get();
|
|
|
|
|
if (is_phi(insn))
|
|
|
|
|
break;
|
|
|
|
|
|
2019-11-27 11:04:47 +01:00
|
|
|
/* substract the 1 or 2 sgprs from exec */
|
2019-09-17 13:22:17 +02:00
|
|
|
if (exec_live)
|
2019-11-27 11:04:47 +01:00
|
|
|
assert(new_demand.sgpr >= (int16_t) program->lane_mask.size());
|
|
|
|
|
register_demand[idx] = RegisterDemand(new_demand.vgpr, new_demand.sgpr - (exec_live ? program->lane_mask.size() : 0));
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
/* KILL */
|
|
|
|
|
for (Definition& definition : insn->definitions) {
|
|
|
|
|
if (!definition.isTemp()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-02-21 12:23:28 +00:00
|
|
|
if ((definition.isFixed() || definition.hasHint()) && definition.physReg() == vcc)
|
|
|
|
|
program->needs_vcc = true;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
const Temp temp = definition.getTemp();
|
2020-09-14 16:45:55 +01:00
|
|
|
const size_t n = live.erase(temp.id());
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
if (n) {
|
|
|
|
|
new_demand -= temp;
|
|
|
|
|
definition.setKill(false);
|
|
|
|
|
} else {
|
2020-02-21 15:46:39 +00:00
|
|
|
register_demand[idx] += temp;
|
2019-09-17 13:22:17 +02:00
|
|
|
definition.setKill(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (definition.isFixed() && definition.physReg() == exec)
|
|
|
|
|
exec_live = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GEN */
|
2019-10-29 11:56:09 +01:00
|
|
|
if (insn->opcode == aco_opcode::p_logical_end) {
|
2019-09-17 13:22:17 +02:00
|
|
|
new_demand.sgpr += phi_sgpr_ops[block->index];
|
|
|
|
|
} else {
|
2020-01-21 14:24:01 +00:00
|
|
|
/* we need to do this in a separate loop because the next one can
|
|
|
|
|
* setKill() for several operands at once and we don't want to
|
|
|
|
|
* overwrite that in a later iteration */
|
|
|
|
|
for (Operand& op : insn->operands)
|
|
|
|
|
op.setKill(false);
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < insn->operands.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
Operand& operand = insn->operands[i];
|
2020-02-21 12:23:28 +00:00
|
|
|
if (!operand.isTemp())
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
2020-02-21 12:23:28 +00:00
|
|
|
if (operand.isFixed() && operand.physReg() == vcc)
|
|
|
|
|
program->needs_vcc = true;
|
2019-09-17 13:22:17 +02:00
|
|
|
const Temp temp = operand.getTemp();
|
2020-09-14 16:45:55 +01:00
|
|
|
const bool inserted = live.insert(temp.id()).second;
|
2019-09-17 13:22:17 +02:00
|
|
|
if (inserted) {
|
|
|
|
|
operand.setFirstKill(true);
|
|
|
|
|
for (unsigned j = i + 1; j < insn->operands.size(); ++j) {
|
|
|
|
|
if (insn->operands[j].isTemp() && insn->operands[j].tempId() == operand.tempId()) {
|
|
|
|
|
insn->operands[j].setFirstKill(false);
|
|
|
|
|
insn->operands[j].setKill(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-21 15:46:39 +00:00
|
|
|
if (operand.isLateKill())
|
|
|
|
|
register_demand[idx] += temp;
|
2019-09-17 13:22:17 +02:00
|
|
|
new_demand += temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (operand.isFixed() && operand.physReg() == exec)
|
|
|
|
|
exec_live = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block->register_demand.update(register_demand[idx]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 11:56:09 +01:00
|
|
|
/* update block's register demand for a last time */
|
|
|
|
|
if (exec_live)
|
2019-11-27 11:04:47 +01:00
|
|
|
assert(new_demand.sgpr >= (int16_t) program->lane_mask.size());
|
|
|
|
|
new_demand.sgpr -= exec_live ? program->lane_mask.size() : 0;
|
2019-10-29 11:56:09 +01:00
|
|
|
block->register_demand.update(new_demand);
|
|
|
|
|
|
|
|
|
|
/* handle phi definitions */
|
|
|
|
|
int phi_idx = idx;
|
|
|
|
|
while (phi_idx >= 0) {
|
|
|
|
|
register_demand[phi_idx] = new_demand;
|
|
|
|
|
Instruction *insn = block->instructions[phi_idx].get();
|
|
|
|
|
|
|
|
|
|
assert(is_phi(insn));
|
|
|
|
|
assert(insn->definitions.size() == 1 && insn->definitions[0].isTemp());
|
|
|
|
|
Definition& definition = insn->definitions[0];
|
2020-02-21 12:23:28 +00:00
|
|
|
if ((definition.isFixed() || definition.hasHint()) && definition.physReg() == vcc)
|
|
|
|
|
program->needs_vcc = true;
|
2019-10-29 11:56:09 +01:00
|
|
|
const Temp temp = definition.getTemp();
|
2020-09-14 16:45:55 +01:00
|
|
|
const size_t n = live.erase(temp.id());
|
2019-10-29 11:56:09 +01:00
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
|
definition.setKill(false);
|
|
|
|
|
else
|
|
|
|
|
definition.setKill(true);
|
|
|
|
|
|
|
|
|
|
phi_idx--;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 13:39:42 +01:00
|
|
|
/* now, we need to merge the live-ins into the live-out sets */
|
2020-09-14 16:45:55 +01:00
|
|
|
for (unsigned t : live) {
|
|
|
|
|
RegClass rc = program->temp_rc[t];
|
|
|
|
|
std::vector<unsigned>& preds = rc.is_linear() ? block->linear_preds : block->logical_preds;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2020-03-10 13:39:42 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
if (preds.empty())
|
2020-09-14 16:45:55 +01:00
|
|
|
aco_err(program, "Temporary never defined or are defined after use: %%%d in BB%d", t, block->index);
|
2020-03-10 13:39:42 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (unsigned pred_idx : preds) {
|
|
|
|
|
auto it = lives.live_out[pred_idx].insert(t);
|
2019-09-17 13:22:17 +02:00
|
|
|
if (it.second)
|
|
|
|
|
worklist.insert(pred_idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 11:56:09 +01:00
|
|
|
/* handle phi operands */
|
|
|
|
|
phi_idx = idx;
|
|
|
|
|
while (phi_idx >= 0) {
|
|
|
|
|
Instruction *insn = block->instructions[phi_idx].get();
|
|
|
|
|
assert(is_phi(insn));
|
|
|
|
|
/* directly insert into the predecessors live-out set */
|
|
|
|
|
std::vector<unsigned>& preds = insn->opcode == aco_opcode::p_phi
|
|
|
|
|
? block->logical_preds
|
|
|
|
|
: block->linear_preds;
|
|
|
|
|
for (unsigned i = 0; i < preds.size(); ++i) {
|
|
|
|
|
Operand &operand = insn->operands[i];
|
2020-02-21 12:23:28 +00:00
|
|
|
if (!operand.isTemp())
|
2019-10-29 11:56:09 +01:00
|
|
|
continue;
|
2020-02-21 12:23:28 +00:00
|
|
|
if (operand.isFixed() && operand.physReg() == vcc)
|
|
|
|
|
program->needs_vcc = true;
|
2019-10-29 11:56:09 +01:00
|
|
|
/* check if we changed an already processed block */
|
2020-09-14 16:45:55 +01:00
|
|
|
const bool inserted = lives.live_out[preds[i]].insert(operand.tempId()).second;
|
2019-10-29 11:56:09 +01:00
|
|
|
if (inserted) {
|
|
|
|
|
operand.setKill(true);
|
|
|
|
|
worklist.insert(preds[i]);
|
|
|
|
|
if (insn->opcode == aco_opcode::p_phi && operand.getTemp().type() == RegType::sgpr)
|
|
|
|
|
phi_sgpr_ops[preds[i]] += operand.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
phi_idx--;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 13:39:42 +01:00
|
|
|
assert(block->index != 0 || (new_demand == RegisterDemand() && live.empty()));
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2019-12-18 16:18:35 +00:00
|
|
|
|
|
|
|
|
unsigned calc_waves_per_workgroup(Program *program)
|
|
|
|
|
{
|
2020-03-12 16:28:48 +01:00
|
|
|
/* When workgroup size is not known, just go with wave_size */
|
|
|
|
|
unsigned workgroup_size = program->workgroup_size == UINT_MAX
|
|
|
|
|
? program->wave_size
|
|
|
|
|
: program->workgroup_size;
|
|
|
|
|
|
2019-12-18 16:18:35 +00:00
|
|
|
return align(workgroup_size, program->wave_size) / program->wave_size;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
} /* end namespace */
|
|
|
|
|
|
2019-09-13 16:41:00 +01:00
|
|
|
uint16_t get_extra_sgprs(Program *program)
|
|
|
|
|
{
|
|
|
|
|
if (program->chip_class >= GFX10) {
|
|
|
|
|
assert(!program->needs_flat_scr);
|
2020-03-27 15:16:39 +01:00
|
|
|
assert(!program->xnack_enabled);
|
2019-09-13 16:41:00 +01:00
|
|
|
return 2;
|
|
|
|
|
} else if (program->chip_class >= GFX8) {
|
|
|
|
|
if (program->needs_flat_scr)
|
|
|
|
|
return 6;
|
2020-03-27 15:16:39 +01:00
|
|
|
else if (program->xnack_enabled)
|
2019-09-13 16:41:00 +01:00
|
|
|
return 4;
|
|
|
|
|
else if (program->needs_vcc)
|
|
|
|
|
return 2;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
2020-03-27 15:16:39 +01:00
|
|
|
assert(!program->xnack_enabled);
|
2019-09-13 16:41:00 +01:00
|
|
|
if (program->needs_flat_scr)
|
|
|
|
|
return 4;
|
|
|
|
|
else if (program->needs_vcc)
|
|
|
|
|
return 2;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t get_sgpr_alloc(Program *program, uint16_t addressable_sgprs)
|
|
|
|
|
{
|
|
|
|
|
assert(addressable_sgprs <= program->sgpr_limit);
|
|
|
|
|
uint16_t sgprs = addressable_sgprs + get_extra_sgprs(program);
|
|
|
|
|
uint16_t granule = program->sgpr_alloc_granule + 1;
|
|
|
|
|
return align(std::max(sgprs, granule), granule);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 14:21:16 +00:00
|
|
|
uint16_t get_vgpr_alloc(Program *program, uint16_t addressable_vgprs)
|
|
|
|
|
{
|
|
|
|
|
assert(addressable_vgprs <= program->vgpr_limit);
|
|
|
|
|
uint16_t granule = program->vgpr_alloc_granule + 1;
|
|
|
|
|
return align(std::max(addressable_vgprs, granule), granule);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 16:41:00 +01:00
|
|
|
uint16_t get_addr_sgpr_from_waves(Program *program, uint16_t max_waves)
|
|
|
|
|
{
|
|
|
|
|
uint16_t sgprs = program->physical_sgprs / max_waves & ~program->sgpr_alloc_granule;
|
|
|
|
|
sgprs -= get_extra_sgprs(program);
|
|
|
|
|
return std::min(sgprs, program->sgpr_limit);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 14:21:16 +00:00
|
|
|
uint16_t get_addr_vgpr_from_waves(Program *program, uint16_t max_waves)
|
|
|
|
|
{
|
aco: fix num_waves on GFX10+
There are half the SIMDs per CU and physical_vgprs should be 512 instead
of 256.
fossil-db (GFX10.3):
Totals from 3622 (2.60% of 139391) affected shaders:
VGPRs: 298192 -> 289732 (-2.84%); split: -3.43%, +0.59%
CodeSize: 29443432 -> 29458388 (+0.05%); split: -0.00%, +0.06%
MaxWaves: 21703 -> 23395 (+7.80%); split: +7.84%, -0.05%
Instrs: 5677920 -> 5681438 (+0.06%); split: -0.01%, +0.07%
Cycles: 280715524 -> 280895676 (+0.06%); split: -0.00%, +0.07%
VMEM: 981142 -> 981894 (+0.08%); split: +0.18%, -0.10%
SMEM: 243315 -> 243454 (+0.06%); split: +0.07%, -0.02%
VClause: 88991 -> 89767 (+0.87%); split: -0.02%, +0.89%
SClause: 200660 -> 200659 (-0.00%); split: -0.00%, +0.00%
Copies: 430729 -> 434160 (+0.80%); split: -0.07%, +0.86%
Branches: 158004 -> 158021 (+0.01%); split: -0.01%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8523>
2021-01-19 11:37:52 +00:00
|
|
|
uint16_t vgprs = program->physical_vgprs / max_waves & ~program->vgpr_alloc_granule;
|
2019-12-03 14:21:16 +00:00
|
|
|
return std::min(vgprs, program->vgpr_limit);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 16:18:35 +00:00
|
|
|
void calc_min_waves(Program* program)
|
|
|
|
|
{
|
|
|
|
|
unsigned waves_per_workgroup = calc_waves_per_workgroup(program);
|
|
|
|
|
/* currently min_waves is in wave64 waves */
|
|
|
|
|
if (program->wave_size == 32)
|
|
|
|
|
waves_per_workgroup = DIV_ROUND_UP(waves_per_workgroup, 2);
|
|
|
|
|
|
aco: fix num_waves on GFX10+
There are half the SIMDs per CU and physical_vgprs should be 512 instead
of 256.
fossil-db (GFX10.3):
Totals from 3622 (2.60% of 139391) affected shaders:
VGPRs: 298192 -> 289732 (-2.84%); split: -3.43%, +0.59%
CodeSize: 29443432 -> 29458388 (+0.05%); split: -0.00%, +0.06%
MaxWaves: 21703 -> 23395 (+7.80%); split: +7.84%, -0.05%
Instrs: 5677920 -> 5681438 (+0.06%); split: -0.01%, +0.07%
Cycles: 280715524 -> 280895676 (+0.06%); split: -0.00%, +0.07%
VMEM: 981142 -> 981894 (+0.08%); split: +0.18%, -0.10%
SMEM: 243315 -> 243454 (+0.06%); split: +0.07%, -0.02%
VClause: 88991 -> 89767 (+0.87%); split: -0.02%, +0.89%
SClause: 200660 -> 200659 (-0.00%); split: -0.00%, +0.00%
Copies: 430729 -> 434160 (+0.80%); split: -0.07%, +0.86%
Branches: 158004 -> 158021 (+0.01%); split: -0.01%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8523>
2021-01-19 11:37:52 +00:00
|
|
|
unsigned simd_per_cu = program->chip_class >= GFX10 ? 2 : 4;
|
2019-12-18 16:18:35 +00:00
|
|
|
bool wgp = program->chip_class >= GFX10; /* assume WGP is used on Navi */
|
|
|
|
|
unsigned simd_per_cu_wgp = wgp ? simd_per_cu * 2 : simd_per_cu;
|
|
|
|
|
|
|
|
|
|
program->min_waves = DIV_ROUND_UP(waves_per_workgroup, simd_per_cu_wgp);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void update_vgpr_sgpr_demand(Program* program, const RegisterDemand new_demand)
|
|
|
|
|
{
|
aco: fix num_waves on GFX10+
There are half the SIMDs per CU and physical_vgprs should be 512 instead
of 256.
fossil-db (GFX10.3):
Totals from 3622 (2.60% of 139391) affected shaders:
VGPRs: 298192 -> 289732 (-2.84%); split: -3.43%, +0.59%
CodeSize: 29443432 -> 29458388 (+0.05%); split: -0.00%, +0.06%
MaxWaves: 21703 -> 23395 (+7.80%); split: +7.84%, -0.05%
Instrs: 5677920 -> 5681438 (+0.06%); split: -0.01%, +0.07%
Cycles: 280715524 -> 280895676 (+0.06%); split: -0.00%, +0.07%
VMEM: 981142 -> 981894 (+0.08%); split: +0.18%, -0.10%
SMEM: 243315 -> 243454 (+0.06%); split: +0.07%, -0.02%
VClause: 88991 -> 89767 (+0.87%); split: -0.02%, +0.89%
SClause: 200660 -> 200659 (-0.00%); split: -0.00%, +0.00%
Copies: 430729 -> 434160 (+0.80%); split: -0.07%, +0.86%
Branches: 158004 -> 158021 (+0.01%); split: -0.01%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8523>
2021-01-19 11:37:52 +00:00
|
|
|
unsigned max_waves_per_simd = program->chip_class == GFX10 ? 20 : 10;
|
|
|
|
|
if (program->chip_class >= GFX10_3)
|
|
|
|
|
max_waves_per_simd = 16;
|
|
|
|
|
else if (program->family >= CHIP_POLARIS10 && program->family <= CHIP_VEGAM)
|
aco: fix max_waves_per_simd on Polaris, VegaM and GFX10.3
fossil-db (Polaris):
Totals from 20263 (14.75% of 137414) affected shaders:
SGPRs: 871407 -> 871679 (+0.03%); split: -0.00%, +0.03%
VGPRs: 513828 -> 550028 (+7.05%); split: -1.68%, +8.72%
CodeSize: 18869680 -> 18828148 (-0.22%); split: -0.23%, +0.01%
MaxWaves: 162012 -> 162030 (+0.01%); split: +0.01%, -0.00%
Instrs: 3629172 -> 3618817 (-0.29%); split: -0.30%, +0.02%
Cycles: 15682244 -> 15638244 (-0.28%); split: -0.30%, +0.02%
VMEM: 10675942 -> 10673344 (-0.02%); split: +0.18%, -0.21%
SMEM: 1209717 -> 1206088 (-0.30%); split: +0.03%, -0.33%
VClause: 81780 -> 81227 (-0.68%); split: -0.73%, +0.06%
SClause: 231724 -> 231561 (-0.07%); split: -0.07%, +0.00%
Copies: 187126 -> 180831 (-3.36%); split: -3.62%, +0.26%
Branches: 26841 -> 26837 (-0.01%); split: -0.03%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5546>
2020-06-18 14:30:51 +01:00
|
|
|
max_waves_per_simd = 8;
|
aco: fix num_waves on GFX10+
There are half the SIMDs per CU and physical_vgprs should be 512 instead
of 256.
fossil-db (GFX10.3):
Totals from 3622 (2.60% of 139391) affected shaders:
VGPRs: 298192 -> 289732 (-2.84%); split: -3.43%, +0.59%
CodeSize: 29443432 -> 29458388 (+0.05%); split: -0.00%, +0.06%
MaxWaves: 21703 -> 23395 (+7.80%); split: +7.84%, -0.05%
Instrs: 5677920 -> 5681438 (+0.06%); split: -0.01%, +0.07%
Cycles: 280715524 -> 280895676 (+0.06%); split: -0.00%, +0.07%
VMEM: 981142 -> 981894 (+0.08%); split: +0.18%, -0.10%
SMEM: 243315 -> 243454 (+0.06%); split: +0.07%, -0.02%
VClause: 88991 -> 89767 (+0.87%); split: -0.02%, +0.89%
SClause: 200660 -> 200659 (-0.00%); split: -0.00%, +0.00%
Copies: 430729 -> 434160 (+0.80%); split: -0.07%, +0.86%
Branches: 158004 -> 158021 (+0.01%); split: -0.01%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8523>
2021-01-19 11:37:52 +00:00
|
|
|
unsigned simd_per_cu = program->chip_class >= GFX10 ? 2 : 4;
|
2019-10-18 19:06:10 +01:00
|
|
|
|
|
|
|
|
bool wgp = program->chip_class >= GFX10; /* assume WGP is used on Navi */
|
|
|
|
|
unsigned simd_per_cu_wgp = wgp ? simd_per_cu * 2 : simd_per_cu;
|
|
|
|
|
unsigned lds_limit = wgp ? program->lds_limit * 2 : program->lds_limit;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* this won't compile, register pressure reduction necessary */
|
2019-10-24 17:34:37 +02:00
|
|
|
if (new_demand.vgpr > program->vgpr_limit || new_demand.sgpr > program->sgpr_limit) {
|
2019-09-17 13:22:17 +02:00
|
|
|
program->num_waves = 0;
|
|
|
|
|
program->max_reg_demand = new_demand;
|
|
|
|
|
} else {
|
2019-09-13 16:41:00 +01:00
|
|
|
program->num_waves = program->physical_sgprs / get_sgpr_alloc(program, new_demand.sgpr);
|
aco: fix num_waves on GFX10+
There are half the SIMDs per CU and physical_vgprs should be 512 instead
of 256.
fossil-db (GFX10.3):
Totals from 3622 (2.60% of 139391) affected shaders:
VGPRs: 298192 -> 289732 (-2.84%); split: -3.43%, +0.59%
CodeSize: 29443432 -> 29458388 (+0.05%); split: -0.00%, +0.06%
MaxWaves: 21703 -> 23395 (+7.80%); split: +7.84%, -0.05%
Instrs: 5677920 -> 5681438 (+0.06%); split: -0.01%, +0.07%
Cycles: 280715524 -> 280895676 (+0.06%); split: -0.00%, +0.07%
VMEM: 981142 -> 981894 (+0.08%); split: +0.18%, -0.10%
SMEM: 243315 -> 243454 (+0.06%); split: +0.07%, -0.02%
VClause: 88991 -> 89767 (+0.87%); split: -0.02%, +0.89%
SClause: 200660 -> 200659 (-0.00%); split: -0.00%, +0.00%
Copies: 430729 -> 434160 (+0.80%); split: -0.07%, +0.86%
Branches: 158004 -> 158021 (+0.01%); split: -0.01%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8523>
2021-01-19 11:37:52 +00:00
|
|
|
program->num_waves = std::min<uint16_t>(program->num_waves, program->physical_vgprs / get_vgpr_alloc(program, new_demand.vgpr));
|
2019-10-18 19:06:10 +01:00
|
|
|
program->max_waves = max_waves_per_simd;
|
|
|
|
|
|
|
|
|
|
/* adjust max_waves for workgroup and LDS limits */
|
2019-12-18 16:18:35 +00:00
|
|
|
unsigned waves_per_workgroup = calc_waves_per_workgroup(program);
|
2019-10-18 19:06:10 +01:00
|
|
|
unsigned workgroups_per_cu_wgp = max_waves_per_simd * simd_per_cu_wgp / waves_per_workgroup;
|
|
|
|
|
if (program->config->lds_size) {
|
|
|
|
|
unsigned lds = program->config->lds_size * program->lds_alloc_granule;
|
|
|
|
|
workgroups_per_cu_wgp = std::min(workgroups_per_cu_wgp, lds_limit / lds);
|
|
|
|
|
}
|
|
|
|
|
if (waves_per_workgroup > 1 && program->chip_class < GFX10)
|
|
|
|
|
workgroups_per_cu_wgp = std::min(workgroups_per_cu_wgp, 16u); /* TODO: is this a SI-only limit? what about Navi? */
|
|
|
|
|
|
|
|
|
|
/* in cases like waves_per_workgroup=3 or lds=65536 and
|
|
|
|
|
* waves_per_workgroup=1, we want the maximum possible number of waves per
|
|
|
|
|
* SIMD and not the minimum. so DIV_ROUND_UP is used */
|
|
|
|
|
program->max_waves = std::min<uint16_t>(program->max_waves, DIV_ROUND_UP(workgroups_per_cu_wgp * waves_per_workgroup, simd_per_cu_wgp));
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-10-18 19:06:10 +01:00
|
|
|
/* incorporate max_waves and calculate max_reg_demand */
|
|
|
|
|
program->num_waves = std::min<uint16_t>(program->num_waves, program->max_waves);
|
2019-12-03 14:21:16 +00:00
|
|
|
program->max_reg_demand.vgpr = get_addr_vgpr_from_waves(program, program->num_waves);
|
2019-09-13 16:41:00 +01:00
|
|
|
program->max_reg_demand.sgpr = get_addr_sgpr_from_waves(program, program->num_waves);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 10:12:58 +02:00
|
|
|
live live_var_analysis(Program* program)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
live result;
|
|
|
|
|
result.live_out.resize(program->blocks.size());
|
|
|
|
|
result.register_demand.resize(program->blocks.size());
|
|
|
|
|
std::set<unsigned> worklist;
|
|
|
|
|
std::vector<uint16_t> phi_sgpr_ops(program->blocks.size());
|
|
|
|
|
RegisterDemand new_demand;
|
|
|
|
|
|
2020-02-21 12:23:28 +00:00
|
|
|
program->needs_vcc = false;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* this implementation assumes that the block idx corresponds to the block's position in program->blocks vector */
|
|
|
|
|
for (Block& block : program->blocks)
|
|
|
|
|
worklist.insert(block.index);
|
|
|
|
|
while (!worklist.empty()) {
|
|
|
|
|
std::set<unsigned>::reverse_iterator b_it = worklist.rbegin();
|
|
|
|
|
unsigned block_idx = *b_it;
|
|
|
|
|
worklist.erase(block_idx);
|
|
|
|
|
process_live_temps_per_block(program, result, &program->blocks[block_idx], worklist, phi_sgpr_ops);
|
|
|
|
|
new_demand.update(program->blocks[block_idx].register_demand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate the program's register demand and number of waves */
|
|
|
|
|
update_vgpr_sgpr_demand(program, new_demand);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|