Skip to content

Commit

Permalink
Improve vISA APIs to support general nbarrier
Browse files Browse the repository at this point in the history
Add the new vISA APIs

   AppendVISANamedBarrierSignal(
      VISA_VectorOpnd *barrierId, VISA_VectorOpnd *barrierType,
      VISA_VectorOpnd *numProducers, VISA_VectorOpnd *numConsumers)

to support general named barrier with both the num of producers and
the number of consumers with the following visaasm syntax:

   nbarrier.signal <id> <barrierType> <num_prods> <num_cons>

The existing API and syntax:
   nbarrier.signal <id> <num_threads>
  • Loading branch information
jgu222 authored and igcbot committed Sep 27, 2024
1 parent ce885f7 commit 65ecf85
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 113 deletions.
3 changes: 3 additions & 0 deletions visa/BuildCISAIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ class CISA_IR_Builder : public VISABuilder {

bool CISA_create_nbarrier(bool isWait, VISA_opnd *barrierId,
VISA_opnd *threadCount, int lineNum);
bool CISA_create_nbarrier_signal(VISA_opnd *barrierId, VISA_opnd *barrierType,
VISA_opnd *numProds, VISA_opnd *numCons,
int lineNum);


bool CISA_create_lsc_typed_block2d_inst(
Expand Down
18 changes: 17 additions & 1 deletion visa/BuildCISAIRImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4192,20 +4192,36 @@ bool CISA_IR_Builder::CISA_create_lsc_fence(LSC_SFID sfid, LSC_FENCE_OP fence,
return true;
}

bool CISA_IR_Builder::CISA_create_nbarrier(bool isWait, VISA_opnd *barrierId,
bool CISA_IR_Builder::CISA_create_nbarrier(bool isWait,
VISA_opnd *barrierId,
VISA_opnd *threadCount,
int lineNum) {
if (isWait) {
// wait
VISA_CALL_TO_BOOL(AppendVISANamedBarrierWait,
static_cast<VISA_VectorOpnd *>(barrierId));
} else {
// signal
VISA_CALL_TO_BOOL(AppendVISANamedBarrierSignal,
static_cast<VISA_VectorOpnd *>(barrierId),
static_cast<VISA_VectorOpnd *>(threadCount));
}
return true;
}

bool CISA_IR_Builder::CISA_create_nbarrier_signal(VISA_opnd *barrierId,
VISA_opnd *barrierType,
VISA_opnd *numProds,
VISA_opnd *numCons,
int lineNum) {
VISA_CALL_TO_BOOL(AppendVISANamedBarrierSignal,
static_cast<VISA_VectorOpnd *>(barrierId),
static_cast<VISA_VectorOpnd *>(barrierType),
static_cast<VISA_VectorOpnd *>(numProds),
static_cast<VISA_VectorOpnd *>(numCons));
return true;
}


bool CISA_IR_Builder::CISA_create_lsc_typed_block2d_inst(
LSC_OP opcode, LSC_CACHE_OPTS caching, LSC_ADDR_TYPE addrModel,
Expand Down
9 changes: 3 additions & 6 deletions visa/BuildIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,6 @@ class IR_Builder {
int status = VISA_SUCCESS;
return translateLscFence(pred, sfid, fenceOp, scope, status);
}
enum class NamedBarrierType { PRODUCER, CONSUMER, BOTH };

////////////////////////////////////////////////////////////////////////
// default barrier functions
Expand All @@ -2320,12 +2319,10 @@ class IR_Builder {
////////////////////////////////////////////////////////////////////////
// named barrier functions
int translateVISANamedBarrierSignal(G4_Predicate *prd, G4_Operand *barrierId,
G4_Operand *threadCount);
G4_Operand *barrierType,
G4_Operand *numProducers,
G4_Operand *numConsumers);
int translateVISANamedBarrierWait(G4_Predicate *prd, G4_Operand *barrierId);
void generateNamedBarrier(G4_Predicate *prd, int numProducer, int numConsumer,
NamedBarrierType type, G4_Operand *barrierId);
void generateNamedBarrier(G4_Predicate *prd, G4_Operand *barrierId,
G4_SrcRegRegion *threadValue);

////////////////////////////////////////////////////////////////////////
// fence etc
Expand Down
18 changes: 15 additions & 3 deletions visa/ByteCodeReaderNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,27 @@ static void readInstructionCommonNG(unsigned &bytePos, const char *buf,
uint32_t mode = readOtherOperandNG(bytePos, buf, ISA_TYPE_UB);
kernelBuilder->AppendVISASplitBarrierInst(mode != 0);
} else if (opcode == ISA_NBARRIER) {
// Still support reading visa binary ?
uint32_t mode = readOtherOperandNG(bytePos, buf, ISA_TYPE_UB);
auto barrierId = readVectorOperandNG(bytePos, buf, container, false);
VISA_VectorOpnd *threadCount =
VISA_VectorOpnd *barrierType =
readVectorOperandNG(bytePos, buf, container, false);
bool isWait = (mode & 1) == 0;
VISA_VectorOpnd *numProds =
readVectorOperandNG(bytePos, buf, container, false);
VISA_VectorOpnd *numCons =
readVectorOperandNG(bytePos, buf, container, false);
bool isWait = (mode == 0);
if (isWait) {
kernelBuilder->AppendVISANamedBarrierWait(barrierId);
} else {
kernelBuilder->AppendVISANamedBarrierSignal(barrierId, threadCount);
const auto &vo = barrierType->_opnd.v_opnd;
if ((vo.tag & 0x7) == OPERAND_IMMEDIATE &&
vo.opnd_val.const_opnd._val.lval == 0 && numProds == numCons) {
kernelBuilder->AppendVISANamedBarrierSignal(barrierId, numProds);
} else {
kernelBuilder->AppendVISANamedBarrierSignal(barrierId, barrierType,
numProds, numCons);
}
}
} else {
bool hasMask = (opcode == ISA_FENCE);
Expand Down
3 changes: 3 additions & 0 deletions visa/CISA.y
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,9 @@ SynchronizationInstruction:
| SBARRIER_WAIT {
pBuilder->CISA_create_sbarrier_instruction(false, CISAlineno);
}
| NBARRIER_SIGNAL VecSrcOperand_G_I_IMM VecSrcOperand_G_I_IMM VecSrcOperand_G_I_IMM VecSrcOperand_G_I_IMM {
pBuilder->CISA_create_nbarrier_signal($2.cisa_gen_opnd, $3.cisa_gen_opnd, $4.cisa_gen_opnd, $5.cisa_gen_opnd, CISAlineno);
}
| NBARRIER_SIGNAL VecSrcOperand_G_I_IMM VecSrcOperand_G_I_IMM {
pBuilder->CISA_create_nbarrier(false, $2.cisa_gen_opnd, $3.cisa_gen_opnd, CISAlineno);
}
Expand Down
6 changes: 4 additions & 2 deletions visa/IsaDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct ISA_Inst_Info ISA_Inst_Table[ISA_OPCODE_ENUM_SIZE] = {
{ISA_RAW_SEND, ISA_Inst_Misc, "raw_send", 0, 0},
{ISA_RESERVED_5E, ISA_Inst_Reserved, "reserved5E", 0, 0},
{ISA_YIELD, ISA_Inst_Sync, "yield", 0, 0},
{ISA_NBARRIER, ISA_Inst_Sync, "nbarrier", 0, 1},
{ISA_NBARRIER, ISA_Inst_Sync, "nbarrier", 4, 0},
{ISA_RESERVED_61, ISA_Inst_Reserved, "reserved61", 0, 0},
{ISA_RESERVED_62, ISA_Inst_Reserved, "reserved62", 0, 0},
{ISA_RESERVED_63, ISA_Inst_Reserved, "reserved63", 0, 0},
Expand Down Expand Up @@ -1828,12 +1828,14 @@ VISA_INST_Desc CISA_INST_table[ISA_NUM_OPCODE] = {
ISA_NBARRIER,
ISA_Inst_Sync,
"nbarrier",
3,
5,
0,
{
{OPND_IMM, ISA_TYPE_UB, 0},
{OPND_VECTOR_SRC_G_I_IMM, ISA_TYPE_UB, 0},
{OPND_VECTOR_SRC_G_I_IMM, ISA_TYPE_UB, 0},
{OPND_VECTOR_SRC_G_I_IMM, ISA_TYPE_UB, 0},
{OPND_VECTOR_SRC_G_I_IMM, ISA_TYPE_UB, 0},
},
},

Expand Down
12 changes: 10 additions & 2 deletions visa/IsaDisassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,19 @@ static std::string printInstructionCommon(const print_format_provider_t *header,
sstr << (mode ? ".signal" : ".wait");
} else if (opcode == ISA_NBARRIER) {
uint8_t mode = getPrimitiveOperand<uint8_t>(inst, i);
bool isSignal = mode & 1;
bool isSignal = (mode > 0);
sstr << (isSignal ? ".signal" : ".wait");
sstr << printOperand(header, inst, 1, opt);
if (isSignal) {
sstr << printOperand(header, inst, 2, opt);
if (mode == 1) {
// nbarrier.signal <id> <num_threads>
sstr << printOperand(header, inst, 3, opt);
} else {
// nbarrier.signal <id> <<type> <num_prods> <num_cons>
sstr << printOperand(header, inst, 2, opt);
sstr << printOperand(header, inst, 3, opt);
sstr << printOperand(header, inst, 4, opt);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions visa/VISAKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,14 @@ class VISAKernelImpl : public VISAFunction {
VISA_BUILDER_API int
AppendVISANamedBarrierWait(VISA_VectorOpnd *barrierId) override;

// Named barrier with the same number of producers and consumers
VISA_BUILDER_API int
AppendVISANamedBarrierSignal(VISA_VectorOpnd *barrierId,
VISA_VectorOpnd *barrierCount) override;
// General producer-consumer named barrier
VISA_BUILDER_API int AppendVISANamedBarrierSignal(
VISA_VectorOpnd *barrierId, VISA_VectorOpnd *barrierType,
VISA_VectorOpnd *numProducers, VISA_VectorOpnd *numConsumers) override;

/********** APPEND INSTRUCTION APIS END ******************/

Expand Down
55 changes: 52 additions & 3 deletions visa/VISAKernelImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8417,19 +8417,29 @@ VISAKernelImpl::AppendVISANamedBarrierSignal(VISA_VectorOpnd *barrierId,

int status = VISA_SUCCESS;

VISA_VectorOpnd *barrierType;
uint16_t value = 0;
status = CreateVISAImmediate(barrierType, &value, ISA_TYPE_UW);
if (status != VISA_SUCCESS)
return status;

if (IS_GEN_BOTH_PATH) {
status = m_builder->translateVISANamedBarrierSignal(
nullptr, barrierId->g4opnd, barrierCount->g4opnd);
nullptr, barrierId->g4opnd, barrierType->g4opnd, barrierCount->g4opnd,
barrierCount->g4opnd);
}
if (IS_VISA_BOTH_PATH) {
VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_NBARRIER];
VISA_opnd *opnd[3];
VISA_opnd *opnd[5];
int num_operands = 0;

uint8_t mode = 1; // signal
// signal 1: nbarrier.signal <id> <num_threads>
uint8_t mode = 1;
ADD_OPND(num_operands, opnd,
CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
ADD_OPND(num_operands, opnd, barrierId);
ADD_OPND(num_operands, opnd, barrierType);
ADD_OPND(num_operands, opnd, barrierCount);
ADD_OPND(num_operands, opnd, barrierCount);

CisaFramework::CisaInst *inst = new (m_mem) CisaFramework::CisaInst(m_mem);
Expand All @@ -8443,6 +8453,45 @@ VISAKernelImpl::AppendVISANamedBarrierSignal(VISA_VectorOpnd *barrierId,
return status;
}

VISA_BUILDER_API int VISAKernelImpl::AppendVISANamedBarrierSignal(
VISA_VectorOpnd *barrierId, VISA_VectorOpnd *barrierType,
VISA_VectorOpnd *numProducers, VISA_VectorOpnd *numConsumers) {
TIME_SCOPE(VISA_BUILDER_APPEND_INST);

AppendVISAInstCommon();

int status = VISA_SUCCESS;

if (IS_GEN_BOTH_PATH) {
status = m_builder->translateVISANamedBarrierSignal(
nullptr, barrierId->g4opnd, barrierType->g4opnd, numProducers->g4opnd,
numConsumers->g4opnd);
}
if (IS_VISA_BOTH_PATH) {
VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_NBARRIER];
VISA_opnd *opnd[5];
int num_operands = 0;

// signal : nbarrier.signal <id> <type> <numProds> <numCons>
uint8_t mode = 2;
ADD_OPND(num_operands, opnd,
CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
ADD_OPND(num_operands, opnd, barrierId);
ADD_OPND(num_operands, opnd, barrierType);
ADD_OPND(num_operands, opnd, numProducers);
ADD_OPND(num_operands, opnd, numConsumers);

CisaFramework::CisaInst *inst = new (m_mem) CisaFramework::CisaInst(m_mem);

inst->createCisaInstruction(ISA_NBARRIER, EXEC_SIZE_1, 0,
PredicateOpnd::getNullPred(), opnd,
num_operands, inst_desc);
addInstructionToEnd(inst);
}

return status;
}

uint32_t VISAKernelImpl::addStringPool(std::string str) {
if (str.empty()) {
return 0;
Expand Down
Loading

0 comments on commit 65ecf85

Please sign in to comment.