Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 0 additions & 168 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_decode.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_decode.hpp

This file was deleted.

13 changes: 1 addition & 12 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_fused.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ void inkling2_fused::add_steps(int j, int stages) {
const app_info I = info(j);
const proj_plan& PP = I.three ? this->pp3 : this->pp1;
const size_t H = I.three ? this->H3 : this->H1;
static const bool same_w = getenv("INKLING2_FUSED_SAMEW") && atoi(getenv("INKLING2_FUSED_SAMEW")); // timing test only
const layer_src& Ls = this->src[same_w ? 0 : I.il];
const layer_src& Ls = this->src[I.il];
const uint64_t wa = Ls.w->bo().address() + 0x80000000ull;
npu_sequence* seq = this->app().seq();
// an MM2S BD at an absolute device address (any buffer): written unpushed, its address patched, then pushed
Expand Down Expand Up @@ -1069,16 +1068,6 @@ bool inkling2_fused::submit(int stages) {
npu_sequence* seq = this->app().seq();
const auto t0 = this->t_build;
seq->cmds2seq();
if (const char* dd = getenv("INKLING2_DUMP_TXN")) { // test only: the first token's streams
static int nd = 0;
if (nd < 49) {
const auto d = seq->dump();
if (FILE* f = fopen((std::string(dd) + "/s" + std::to_string(nd++) + ".txn").c_str(), "wb")) {
fwrite(d.first, 4, d.second, f);
fclose(f);
}
}
}
const auto t1 = std::chrono::steady_clock::now();
xrt::run run = this->app().create_run(this->io, this->wt, this->gl[0], this->gl[1], this->cw);
this->t_create += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t1).count();
Expand Down
40 changes: 0 additions & 40 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,46 +939,6 @@ void moe(float* out, const float* x, int T, const layer_weights& L, int il, mm_o
token_of[r] = i / TOPK;
}
prof_lap(tp, P_ROUTER);
if (T == 1 && offload && offload->dec_experts() > 0) {
// the first nd of the token's experts on the device, the rest on the host meanwhile
const int nd = std::min(offload->dec_experts(), TOPK);
const int* ex = sel.data();
static thread_local std::vector<float> GU_buf((size_t)TOPK * 2 * FF), A_buf((size_t)TOPK * FF_PAD, 0.0f),
Z_buf((size_t)TOPK * D);
float* GU = GU_buf.data();
float* A = A_buf.data();
float* Z = Z_buf.data();
constexpr int rb_per_expert = D / QROWS;
auto act = [&](int k0, int k1) {
#pragma omp parallel for schedule(static)
for (int i = k0 * (FF / 16); i < k1 * (FF / 16); i++) {
const int k = i / (FF / 16), c = i % (FF / 16) * 16;
const float* gu = GU + (size_t)k * 2 * FF;
_mm512_storeu_ps(A + (size_t)k * FF_PAD + c, situ16(_mm512_loadu_ps(gu + c), _mm512_loadu_ps(gu + FF + c)));
}
};
offload->dec_start(il, 0, ex, nd, x);
std::vector<mm_job> jobs;
for (int k = nd; k < TOPK; k++)
jobs.push_back({L.gate_up.rows(ex[k] * rb_per_expert, 2 * FF), x, D, 1, GU + (size_t)k * 2 * FF, 2 * FF});
qmm(jobs);
offload->dec_wait(GU);
act(0, nd);
offload->dec_start(il, 1, ex, nd, A);
act(nd, TOPK);
jobs.clear();
for (int k = nd; k < TOPK; k++)
jobs.push_back({L.down.rows(ex[k] * rb_per_expert, D), A + (size_t)k * FF_PAD, FF_PAD, 1, Z + (size_t)k * D, D});
qmm(jobs);
offload->dec_wait(Z);
for (int c = 0; c < D; c += 16) {
__m512 o = _mm512_setzero_ps();
for (int k = 0; k < TOPK; k++) o = _mm512_fmadd_ps(_mm512_set1_ps(wsel[k]), _mm512_loadu_ps(Z + (size_t)k * D + c), o);
_mm512_storeu_ps(out + c, o);
}
prof_lap(tp, P_EXPERT);
return;
}
if (offload && offload->experts(il, x, T, token_of.data(), count.data(), start.data(), slot_of.data(), wsel.data(), out)) {
prof_lap(tp, P_EXPERT);
return;
Expand Down
8 changes: 0 additions & 8 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,6 @@ class mm_offload {
const float* G, const bf16_rows* Gb, float* O, const std::function<void()>& packed) {
return false;
}
/// \brief decode (one token): how many of a token's TOPK experts the device takes (0: none); the host runs the rest
/// meanwhile
virtual int dec_experts() const { return 0; }
/// \brief start experts ex[0 .. n) of layer il on the device: kind 0 gate_up of in = x [D], kind 1 down of
/// in = [n][FF_PAD] activations
virtual void dec_start(int il, int kind, const int* ex, int n, const float* in) {}
/// \brief wait for dec_start: kind 0 out [n][2 FF] (gate, then up), kind 1 out [n][D]
virtual void dec_wait(float* out) {}
};

/// \brief the model.q4nx tensors, located in place (safetensors container)
Expand Down
31 changes: 1 addition & 30 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_lm_head.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include <stdexcept>
#include <thread>

#if !defined(_WIN32)
#include <sys/mman.h>
#endif

#if !defined(FLM_USE_HRX) // see inkling2_fused.hpp

using namespace inkling2_host;
Expand Down Expand Up @@ -71,26 +67,7 @@ void inkling2_lm_head::init(npu_xclbin_manager* npu, const weights& w) {
this->app = this->mgr->create_app();
const int rb_all = ROWS / QROWS, rb_real = q.row_blocks(), cbs = q.col_blocks();
const size_t wbytes = (size_t)rb_all * cbs * Q80_BYTES;
#if !defined(_WIN32) // 2 MB pages: Linux only
if (getenv("INKLING2_LMH_HUGE") && atoi(getenv("INKLING2_LMH_HUGE"))) {
constexpr size_t HP = (size_t)2 << 20;
this->huge.n = (wbytes + HP - 1) / HP * HP;
void* p = mmap(nullptr, this->huge.n + HP, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) throw std::runtime_error("inkling2 lm_head: mmap failed");
// keep the 2 MB-aligned span, give back the rest
const uintptr_t a = ((uintptr_t)p + HP - 1) / HP * HP;
if (a > (uintptr_t)p) munmap(p, a - (uintptr_t)p);
if ((uintptr_t)p + HP > a) munmap((void*)(a + this->huge.n), (uintptr_t)p + HP - a);
this->huge.p = (void*)a;
madvise(this->huge.p, this->huge.n, MADV_HUGEPAGE);
memset(this->huge.p, 0, this->huge.n);
this->huge_bo = std::make_unique<xrt::ext::bo>(*this->mgr->get_device(), this->huge.p, this->huge.n);
this->wb = buffer<uint8_t>(*this->huge_bo);
} else
#endif
{
this->wb = npu->create_bo_buffer<uint8_t>(wbytes);
}
this->wb = npu->create_bo_buffer<uint8_t>(wbytes);
this->y = npu->create_bo_buffer<uint16_t>(ROWS);
this->x = npu->create_bo_buffer<uint16_t>(2 * D);
// per 4 row blocks (a column's 128 rows): stream a (row blocks 0-1), then stream b (2-3), each column block by
Expand Down Expand Up @@ -156,12 +133,6 @@ void inkling2_lm_head::gen_seq() {
seq->cmds2seq();
}

inkling2_lm_head::huge_mem::~huge_mem() {
#if !defined(_WIN32)
if (this->p) munmap(this->p, this->n);
#endif
}

bool inkling2_lm_head::run(const uint16_t* xv, float* logits) {
using clk = std::chrono::steady_clock;
const auto t0 = clk::now();
Expand Down
7 changes: 0 additions & 7 deletions flm-dev-kit/FLM_DLL/detail/inkling2_npu/inkling2_lm_head.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ class inkling2_lm_head {
npu_app app;
xrt::run run_;
buffer<uint16_t> y, x;
// INKLING2_LMH_HUGE=1: the weights in 2 MB pages (user memory, MADV_HUGEPAGE) instead of a 4 KB-page BO
struct huge_mem {
void* p = nullptr;
size_t n = 0;
~huge_mem();
} huge;
std::unique_ptr<xrt::bo> huge_bo;
buffer<uint8_t> wb;
};
#endif // !FLM_USE_HRX
Loading
Loading