Skip to content

Commit 931cc27

Browse files
committed
ngen: downstream nGEN
1 parent 7d418f5 commit 931cc27

19 files changed

+1200
-187
lines changed

src/gpu/intel/ocl/hw_info.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ status_t init_gpu_hw_info(impl::engine_t *engine, cl_device_id device,
6060
int &gpu_product_family, int &stepping_id, uint64_t &native_extensions,
6161
bool &mayiuse_systolic, bool &mayiuse_ngen_kernels) {
6262
using namespace ngen;
63-
HW hw = HW::Unknown;
64-
Product product = {ProductFamily::Unknown, 0};
65-
jit::generator_t<HW::Unknown>::detectHWInfo(context, device, hw, product);
63+
Product product = ngen::OpenCLCodeGenerator<HW::Unknown>::detectHWInfo(
64+
context, device);
6665
bool is_xelpg = (product.family == ngen::ProductFamily::ARL
6766
|| product.family == ngen::ProductFamily::MTL);
6867

69-
gpu_arch = jit::convert_ngen_arch_to_dnnl(hw);
68+
gpu_arch = jit::convert_ngen_arch_to_dnnl(ngen::getCore(product.family));
7069
gpu_product_family = static_cast<int>(product.family);
7170
stepping_id = product.stepping;
7271

src/gpu/intel/sycl/l0/utils.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,10 @@ status_t init_gpu_hw_info(impl::engine_t *engine, ze_device_handle_t device,
386386
int &stepping_id, uint64_t &native_extensions, bool &mayiuse_systolic,
387387
bool &mayiuse_ngen_kernels) {
388388
using namespace ngen;
389-
HW hw = HW::Unknown;
390-
Product product = {ProductFamily::Unknown, 0};
391-
LevelZeroCodeGenerator<HW::Unknown>::detectHWInfo(
392-
context, device, hw, product);
389+
Product product = LevelZeroCodeGenerator<HW::Unknown>::detectHWInfo(
390+
context, device);
393391

394-
gpu_arch = jit::convert_ngen_arch_to_dnnl(hw);
392+
gpu_arch = jit::convert_ngen_arch_to_dnnl(ngen::getCore(product.family));
395393
gpu_product_family = static_cast<int>(product.family);
396394
stepping_id = product.stepping;
397395

third_party/ngen/ngen.hpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#ifndef NGEN_HPP
2828
#define NGEN_HPP
2929

30-
#ifdef ENABLE_LLVM_WCONVERSION
30+
#if defined(__clang__)
3131
#pragma clang diagnostic push
3232
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
3333
#endif
3434

35-
#include "ngen_config.hpp"
35+
#include "ngen_config_internal.hpp"
3636

3737
#include <array>
3838
#include <cstring>
@@ -42,16 +42,13 @@
4242
#include "ngen_core.hpp"
4343
#include "ngen_auto_swsb.hpp"
4444
#include "ngen_debuginfo.hpp"
45-
4645
// -----------------------------------------------------------------------
4746
// Binary formats, split between pre-Gen12 and post-Gen12.
4847
#include "ngen_gen8.hpp"
4948
#include "ngen_gen12.hpp"
5049
// -----------------------------------------------------------------------
5150

52-
#ifdef NGEN_ASM
5351
#include "ngen_asm.hpp"
54-
#endif
5552

5653
namespace NGEN_NAMESPACE {
5754

@@ -299,7 +296,7 @@ class BinaryCodeGenerator
299296
pushStream(rootStream);
300297
}
301298

302-
explicit BinaryCodeGenerator(int stepping_ = 0, DebugConfig debugConfig = {}) : BinaryCodeGenerator({genericProductFamily(hw), stepping_}, debugConfig) {}
299+
explicit BinaryCodeGenerator(int stepping_ = 0, DebugConfig debugConfig = {}) : BinaryCodeGenerator({genericProductFamily(hw), stepping_, PlatformType::Unknown}, debugConfig) {}
303300

304301
~BinaryCodeGenerator() {
305302
for (size_t sn = 1; sn < streamStack.size(); sn++)
@@ -684,7 +681,7 @@ class BinaryCodeGenerator
684681
void halt(const InstructionModifier &mod, Label &jip, SourceLocation loc = {}) {
685682
halt(mod, jip, jip, loc);
686683
}
687-
void if_(InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl = false, SourceLocation loc = {}) {
684+
void if_(InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl, SourceLocation loc = {}) {
688685
mod.setBranchCtrl(branchCtrl);
689686
opBranch(Opcode::if_, mod, null, jip, uip, loc);
690687
}
@@ -1506,10 +1503,15 @@ int getStepping() const { return scope::getStepping(); } \
15061503
void setProduct(NGEN_NAMESPACE::Product product_) { scope::setProduct(product_); } \
15071504
void setProductFamily(NGEN_NAMESPACE::ProductFamily family_) { scope::setProductFamily(family_); } \
15081505
void setStepping(int stepping_) { scope::setStepping(stepping_); } \
1506+
NGEN_FORWARD_SCOPE_EXTRA(scope) \
15091507
NGEN_FORWARD_SCOPE_OP_NAMES(scope) \
15101508
NGEN_FORWARD_SCOPE_MIN_MAX(scope) \
15111509
NGEN_FORWARD_SCOPE_REGISTERS(scope)
15121510

1511+
#define NGEN_FORWARD_SCOPE_EXTRA(scope)
1512+
#define NGEN_FORWARD_SCOPE_EXTRA_ELF_OVERRIDES(hw)
1513+
1514+
15131515
#ifdef NGEN_NO_OP_NAMES
15141516
#define NGEN_FORWARD_SCOPE_OP_NAMES(scope)
15151517
#else
@@ -2798,7 +2800,7 @@ void BinaryCodeGenerator<hw>::opNop(Opcode op, SourceLocation loc)
27982800

27992801
} /* namespace NGEN_NAMESPACE */
28002802

2801-
#ifdef ENABLE_LLVM_WCONVERSION
2803+
#if defined(__clang__)
28022804
#pragma clang diagnostic pop
28032805
#endif
28042806

third_party/ngen/ngen_asm.hpp

+37-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616

1717
#ifndef NGEN_ASM_HPP
1818
#define NGEN_ASM_HPP
19-
#ifdef NGEN_ASM
2019

21-
#include "ngen_config.hpp"
20+
#include "ngen_config_internal.hpp"
21+
22+
#ifdef NGEN_ASM
2223

2324
#include <array>
2425
#include <cstdint>
2526
#include <sstream>
2627
#include <string>
2728

29+
#include "ngen_core.hpp"
30+
#include "ngen_debuginfo.hpp"
2831
#include "ngen_gen12.hpp"
2932

3033
namespace NGEN_NAMESPACE {
@@ -210,6 +213,7 @@ struct AsmInstruction {
210213
explicit AsmInstruction(uint32_t inum_, const std::string &comment_)
211214
: op(Opcode::illegal), ext(0), inum(inum_), mod{}, dst{}, src{}, labelManager{nullptr}, comment{comment_} {}
212215
inline AsmInstruction(const autoswsb::SyncInsertion &si);
216+
inline AsmInstruction(const autoswsb::DummyMovInsertion &mi);
213217

214218
bool isLabel() const { return (op == Opcode::illegal) && (dst.type == AsmOperand::Type::label); }
215219
bool isComment() const { return (op == Opcode::illegal) && !comment.empty(); }
@@ -278,6 +282,21 @@ AsmInstruction::AsmInstruction(const autoswsb::SyncInsertion &si)
278282
src[0] = NullRegister();
279283
}
280284

285+
AsmInstruction::AsmInstruction(const autoswsb::DummyMovInsertion &mi)
286+
{
287+
op = Opcode::mov_gen12;
288+
ext = 0;
289+
mod = 1 | InstructionModifier::createMaskCtrl(true);
290+
mod.setSWSB(mi.swsb);
291+
dst = NullRegister().retype(mi.dt);
292+
for (auto n = 1; n < 4; n++)
293+
src[n] = NoOperand();
294+
if (mi.constant) {
295+
src[0] = Immediate::zero(mi.dt);
296+
} else
297+
src[0] = GRF(mi.grf).sub(0, mi.dt);
298+
}
299+
281300
unsigned AsmInstruction::getTypecode(const AsmOperand &op)
282301
{
283302
DataType dt = DataType::invalid;
@@ -416,7 +435,7 @@ class AsmCodeGenerator {
416435
streamStack.push_back(new InstructionStream());
417436
}
418437

419-
explicit AsmCodeGenerator(HW hardware_, int stepping_ = 0) : AsmCodeGenerator({genericProductFamily(hardware_), 0}) {}
438+
explicit AsmCodeGenerator(HW hardware_, int stepping_ = 0) : AsmCodeGenerator({genericProductFamily(hardware_), 0, PlatformType::Unknown}) {}
420439

421440
AsmCodeGenerator(HW hardware_, std::ostream &defaultOutput_, int stepping_ = 0) : AsmCodeGenerator(hardware_, stepping_) {
422441
defaultOutput = &defaultOutput_;
@@ -488,7 +507,6 @@ class AsmCodeGenerator {
488507
LabelManager labelManager;
489508
std::vector<InstructionStream*> streamStack;
490509

491-
492510
inline void unsupported();
493511

494512
// Output functions.
@@ -555,7 +573,7 @@ class AsmCodeGenerator {
555573
src0.fixup(hardware, 1, 0, defaultType, 0, 3);
556574
src1.fixup(hardware, 1, 0, defaultType, 1, 3);
557575
src2.fixup(hardware, 1, 0, defaultType, 2, 3);
558-
(void) streamStack.back()->append(op, static_cast<uint16_t>((sdepth << 8) | rcount), mod | defaultModifier, &labelManager, dst, src0, src1, src2);
576+
(void) streamStack.back()->append(op, (sdepth << 8) | rcount, mod | defaultModifier, &labelManager, dst, src0, src1, src2);
559577
}
560578
template <typename D, typename S0> void opCall(Opcode op, const InstructionModifier &mod, D dst, S0 src0) {
561579
(void) streamStack.back()->append(op, 0, mod | defaultModifier | NoMask, &labelManager, dst, src0);
@@ -582,7 +600,6 @@ class AsmCodeGenerator {
582600
bool getDefaultNoMask() const { return defaultModifier.isWrEn(); }
583601
bool getDefaultAutoSWSB() const { return defaultModifier.isAutoSWSB(); }
584602

585-
586603
// Stream handling.
587604
void pushStream() { pushStream(new InstructionStream()); }
588605
void pushStream(InstructionStream &s) { pushStream(&s); }
@@ -917,7 +934,7 @@ class AsmCodeGenerator {
917934
void halt(const InstructionModifier &mod, Label &jip, SourceLocation loc = {}) {
918935
halt(mod, jip, jip);
919936
}
920-
void if_(InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl = false, SourceLocation loc = {}) {
937+
void if_(InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl, SourceLocation loc = {}) {
921938
(void) jip.getID(labelManager);
922939
(void) uip.getID(labelManager);
923940
opX(Opcode::if_, DataType::invalid, mod, NoOperand(), jip, uip, NoOperand(), branchCtrl);
@@ -1073,6 +1090,9 @@ class AsmCodeGenerator {
10731090
}
10741091
template <typename DT = void>
10751092
void movi(const InstructionModifier &mod, const RegData &dst, const RegData &src0, SourceLocation loc = {}) {
1093+
#ifdef NGEN_SAFE
1094+
if (!src0.isIndirect()) throw invalid_address_mode_exception();
1095+
#endif
10761096
if (hardware >= HW::Gen10)
10771097
movi<DT>(mod, dst, src0, null);
10781098
else
@@ -1082,6 +1102,7 @@ class AsmCodeGenerator {
10821102
void movi(const InstructionModifier &mod, const RegData &dst, const RegData &src0, const Immediate &src1, SourceLocation loc = {}) {
10831103
#ifdef NGEN_SAFE
10841104
if (hardware < HW::Gen10) throw unsupported_instruction();
1105+
if (!src0.isIndirect()) throw invalid_address_mode_exception();
10851106
#endif
10861107
opX(isGen12 ? Opcode::movi_gen12 : Opcode::movi, getDataType<DT>(), mod, dst, src0, src1);
10871108
}
@@ -1585,17 +1606,24 @@ void AsmCodeGenerator::getCode(std::ostream &out)
15851606

15861607
autoswsb::BasicBlockList analysis = autoswsb::autoSWSB(hardware, declaredGRFs, streamStack.back()->buffer);
15871608
std::multimap<int32_t, autoswsb::SyncInsertion*> syncs; // Syncs inserted by auto-SWSB.
1609+
std::multimap<int32_t, autoswsb::DummyMovInsertion*> movs; // Dummy moves inserted by auto-SWSB.
15881610

1589-
for (auto &bb : analysis)
1590-
for (auto &sync : bb.syncs)
1611+
for (auto &bb : analysis) {
1612+
for (auto &sync: bb.syncs)
15911613
syncs.insert(std::make_pair(sync.inum, &sync));
1614+
for (auto &mov: bb.movs)
1615+
movs.insert(std::make_pair(mov.inum, &mov));
1616+
}
15921617

15931618
auto nextSync = syncs.begin();
1619+
auto nextMov = movs.begin();
15941620
int lineNo = 0;
15951621

15961622
for (auto &i : streamStack.back()->buffer) {
15971623
while ((nextSync != syncs.end()) && (nextSync->second->inum == i.inum))
15981624
outX(out, *(nextSync++)->second, lineNo++);
1625+
while ((nextMov != movs.end()) && (nextMov->second->inum == i.inum))
1626+
outX(out, *(nextMov++)->second, lineNo++);
15991627

16001628
if (i.isLabel()) {
16011629
i.dst.label.outputText(out, PrintDetail::full, labelManager);

third_party/ngen/ngen_auto_swsb.hpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
#ifndef NGEN_AUTO_SWSB_HPP
2222
#define NGEN_AUTO_SWSB_HPP
2323

24-
#ifdef ENABLE_LLVM_WCONVERSION
25-
#pragma clang diagnostic push
26-
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
27-
#endif
28-
2924
#if defined(NGEN_DEBUG) || defined(NGEN_DEBUG_PROPAGATE) || defined(NGEN_DEBUG_BB)
3025
#include <iomanip>
3126
#include <iostream>
@@ -35,6 +30,8 @@
3530
#include <list>
3631
#include <map>
3732

33+
#include "ngen_core.hpp"
34+
3835
namespace NGEN_NAMESPACE {
3936
namespace autoswsb {
4037

@@ -2635,8 +2632,4 @@ inline BasicBlockList autoSWSB(HW hw, int grfCount, Program &program)
26352632
// Instruction operator[](int inum);
26362633
// size_t size() const;
26372634

2638-
#ifdef ENABLE_LLVM_WCONVERSION
2639-
#pragma clang diagnostic pop
2640-
#endif
2641-
26422635
#endif /* NGEN_AUTOSWSB_HPP */
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
#ifndef NGEN_CONFIG_INTERNAL_HPP
18+
#define NGEN_CONFIG_INTERNAL_HPP
19+
20+
// Drop NGEN_CONFIG define once C++11/14 support dropped
21+
#if (defined(__has_include) && __has_include("ngen_config.hpp")) || defined(NGEN_CONFIG)
22+
#include "ngen_config.hpp"
23+
#else
24+
// Default config settings
25+
26+
#ifndef NGEN_NAMESPACE
27+
#define NGEN_NAMESPACE ngen
28+
#endif
29+
30+
#ifndef NGEN_ASM
31+
#define NGEN_ASM
32+
#endif
33+
34+
#if (__cplusplus >= 202002L || _MSVC_LANG >= 202002L)
35+
#if __has_include(<version>)
36+
#include <version>
37+
#if __cpp_lib_source_location >= 201907L
38+
#define NGEN_ENABLE_SOURCE_LOCATION true
39+
#endif
40+
#endif
41+
#endif
42+
43+
#endif
44+
#endif /* header guard */

0 commit comments

Comments
 (0)