Skip to content

Commit c5ef049

Browse files
jfuentesigcbot
authored andcommitted
Add vISA verifier when CISA instructions are created
Verify vISA instructions when they are created (CISA instructions). Today the verification is done at the end of the compilation.
1 parent efc6f8e commit c5ef049

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

visa/BuildCISAIRImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ int CISA_IR_Builder::verifyVISAIR()
21262126

21272127
VISAKernel_format_provider fmt(fmtKernel);
21282128

2129-
vISAVerifier verifier(m_header, &fmt, getOptions());
2129+
vISAVerifier verifier(m_header, &fmt, getOptions(), fmtKernel->getIRBuilder());
21302130
verifier.run(kTemp);
21312131

21322132
if (verifier.hasErrors())

visa/Common_ISA_framework.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ int CisaInst::createCisaInstruction(
3636
PredicateOpnd pred,
3737
VISA_opnd** opnd,
3838
int numOpnds,
39-
const VISA_INST_Desc* inst_desc)
39+
const VISA_INST_Desc* inst_desc,
40+
vISAVerifier* verifier)
4041
{
4142
uint8_t subOpcode = 0;
4243
bool hasSubOpcode = false;
@@ -126,6 +127,16 @@ int CisaInst::createCisaInstruction(
126127
m_size += opnd[i]->size;
127128
}
128129

130+
#if defined(_DEBUG) || defined(_INTERNAL)
131+
if (verifier) {
132+
verifier->verifyInstruction(&m_cisa_instruction);
133+
if (verifier->hasErrors()) {
134+
std::cerr << verifier->getLastErrorFound().value_or("");
135+
return VISA_FAILURE;
136+
}
137+
}
138+
#endif
139+
129140
return VISA_SUCCESS;
130141
}
131142

visa/Common_ISA_framework.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SPDX-License-Identifier: MIT
2222
#include "visa_igc_common_header.h"
2323
#include "IsaDescription.h"
2424
#include "Mem_Manager.h"
25+
#include "IsaVerification.h"
2526

2627
#define CISA_INVALID_ADDR_ID -1
2728
#define CISA_INVALID_PRED_ID -1
@@ -81,7 +82,7 @@ class CisaInst
8182
CISA_INST m_cisa_instruction;
8283
const VISA_INST_Desc* m_inst_desc;
8384

84-
int createCisaInstruction(ISA_Opcode opcode, unsigned char exec_size, unsigned char modifier, PredicateOpnd pred, VISA_opnd **opnd, int numOpnds, const VISA_INST_Desc* inst_desc);
85+
int createCisaInstruction(ISA_Opcode opcode, unsigned char exec_size, unsigned char modifier, PredicateOpnd pred, VISA_opnd **opnd, int numOpnds, const VISA_INST_Desc* inst_desc, vISAVerifier* verifier = nullptr);
8586

8687
int getSize() const {return m_size;}
8788

visa/IsaVerification.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class vISAVerifier
2626
const common_isa_header& isaHeader;
2727
const print_format_provider_t* header;
2828
Options* options;
29+
const vISA::IR_Builder* irBuilder = nullptr; // for capability check
2930

3031
std::vector<std::string> kerror_list;
3132
std::vector<std::string> error_list;
@@ -34,26 +35,31 @@ class vISAVerifier
3435
// false -- a label is used in the kernel but not yet defined
3536
std::map<int, bool> labelDefs;
3637

37-
const vISA::IR_Builder* irBuilder = nullptr; // for capability check
3838

3939
public:
4040

41-
vISAVerifier(const common_isa_header& vISAHeader, const print_format_provider_t* kernelHeader, Options* opt) :
42-
isaHeader(vISAHeader), header(kernelHeader), options(opt) {}
41+
vISAVerifier(const common_isa_header& vISAHeader, const print_format_provider_t* kernelHeader, Options* opt, const vISA::IR_Builder* ir_Builder) :
42+
isaHeader(vISAHeader), header(kernelHeader), options(opt), irBuilder(ir_Builder) {}
4343

4444
virtual ~vISAVerifier() = default;
4545

4646
void run(VISAKernelImpl* kernel);
4747

48+
void verifyInstruction(const CISA_INST* inst);
49+
4850
bool hasErrors() const { return kerror_list.size() + error_list.size() > 0; }
4951
size_t getNumErrors() const { return kerror_list.size() + error_list.size(); }
5052

5153
void writeReport(const char* filename);
5254

55+
std::optional<std::string> getLastErrorFound() const {
56+
if (error_list.empty()) return std::nullopt;
57+
return error_list.back();
58+
}
59+
5360
private:
5461

5562
void verifyKernelHeader();
56-
void verifyInstruction(const CISA_INST* inst);
5763

5864
// checks that can only be done once the whole kernel is processed.
5965
void finalize();

visa/VISAKernel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT
1818
//#include "G4_IR.hpp" // for PhyRegPool
1919
#include "Attributes.hpp"
2020
#include "CompilerStats.h"
21+
#include "IsaVerification.h"
2122

2223
#include <list>
2324
#include <map>
@@ -34,8 +35,11 @@ namespace vISA
3435
class G4_Kernel;
3536
class DebugInfoFormat;
3637
class BinaryEncodingBase;
38+
3739
}
3840

41+
class VISAKernel_format_provider;
42+
3943
// Class hierarchy is as follows:
4044
// VISAKernel -> Abstract class that declares virtual functions to build a kernel object
4145
// VISAFunction : VISAKernel -> Abstract class that declares function specific APIs
@@ -1212,6 +1216,10 @@ class VISAKernelImpl : public VISAFunction
12121216

12131217
// Shared with G4_kernel
12141218
vISA::Attributes* m_kernelAttrs;
1219+
1220+
// Instruction verifier that checks CISA instruction creation
1221+
VISAKernel_format_provider* fmt;
1222+
vISAVerifier* verifier;
12151223
};
12161224

12171225
class VISAKernel_format_provider : public print_format_provider_t

visa/VISAKernelImpl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ int VISAKernelImpl::InitializeKernel(const char *kernel_name)
814814

815815
CISABuildPreDefinedDecls();
816816

817+
fmt = new VISAKernel_format_provider(this);
818+
verifier = new vISAVerifier(m_CISABuilder->m_header, fmt, m_options, m_builder);
819+
817820
return status;
818821
}
819822

@@ -8529,8 +8532,8 @@ VISA_BUILDER_API int VISAKernelImpl::AppendVISALscFence(
85298532
unsigned size = EXEC_SIZE_1;
85308533
PACK_EXEC_SIZE(size, vISA_EMASK_M1_NM);
85318534

8532-
inst->createCisaInstruction(
8533-
ISA_LSC_FENCE, (uint8_t)size, 0, PredicateOpnd::getNullPred(), opnds, numOpnds, instDesc);
8535+
status = inst->createCisaInstruction(
8536+
ISA_LSC_FENCE, (uint8_t)size, 0, PredicateOpnd::getNullPred(), opnds, numOpnds, instDesc, verifier);
85348537
addInstructionToEnd(inst);
85358538
}
85368539

@@ -9035,6 +9038,9 @@ VISAKernelImpl::~VISAKernelImpl()
90359038
}
90369039

90379040
destroyKernelAttributes();
9041+
9042+
delete fmt;
9043+
delete verifier;
90389044
}
90399045

90409046
int VISAKernelImpl::GetGenxBinary(void *&buffer, int &size) const

0 commit comments

Comments
 (0)