Skip to content

llama-bench : set locale to utf8 - #2832

Merged
slaren merged 1 commit into
masterfrom
llama-bench-utf8
Aug 28, 2023
Merged

slaren merged 1 commit into
masterfrom
llama-bench-utf8

Conversation

@slaren

@slaren slaren commented Aug 27, 2023

Copy link
Copy Markdown
Member

Fixes garbled utf-8 characters in markdown printer under Windows 10 version 1803 and up.


int main(int argc, char ** argv) {
// try to set locale for unicode characters in markdown
setlocale(LC_CTYPE, ".UTF-8");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On non-Windows platforms this is going to fail and return NULL. I think we should wrap this with #ifdef _WIN32.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but if it fails nothing changes anyway, so I don't see the point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but if it fails nothing changes anyway, so I don't see the point.

I can confirm, nothing happens on Linux, locale stays what it was before the setlocale(LC_CTYPE, ".UTF-8"); call, no exceptions, no errors.

@slaren
slaren merged commit 43033b7 into master Aug 28, 2023
@slaren
slaren deleted the llama-bench-utf8 branch August 28, 2023 17:19
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 18, 2026
bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 18, 2026
The 1024-thread tile stages four halves of 32 values into the 64-value window the mma reads, so the
store origin ran to 32*3 + 16 = 112 on a 72-wide row: the Loom verifier refused the range as
unprovable ("vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9")
and the arm never compiled for the shapes Qwen3.8-27B asks for (5120x6144, 5120x17408). An IQ1
packet covers [32p, 32p+32), so two halves tile that window exactly and four do not.

Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, the arm toggled by dispatch name:

  pp512  11.30 +- 0.03 -> 90.15 +- 0.35 t/s   (7.98x)
  tg128  12.74 +- 0.01 -> 12.72 +- 0.02 t/s   (unchanged)
bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 19, 2026
A paired tile stages the gate rows and the up rows from two buffers, but only
the q4_K native decoder ever read %up_weight: the IQ1 arm decoded both halves
from the gate weight, so a swiglu tile would have published gate rows twice.
The IQ1 arm now picks the buffer by %weight_is_up (the q4_K decoder's own
rule), leaving the generated IQ1 motif and its regenerated bytes untouched.

New kernel.def ggml_mul_mat_iq1_s_swiglu_f16_wmma_prefill_wave32 is the q4_K
swiglu prefill schedule with format 26, and the matcher
common.mul_mat_swiglu.iq1_s_prefill_wave32 (priority 305) claims a gate/up pair
of IQ1_S weights, 256..2048 tokens in 256-token steps, input % 256, output % 64.
Both layouts are pinned in the def (staged f16 input, un-packed f16 copy): the
staged geometry is the only one the IQ1 publish is proven at.

Device, gfx1151: the two new rows pass
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.256.4096  1806 ms
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.512.4096  1821 ms
and the full suite is 267 passed, 13 failed - the same 13 flash-attention rows
that engine#2870 tracks.

Qwen3.8-27B UD-IQ1_S pp512 is unchanged (90.37 +- 0.36 with the arm against
90.25 +- 0.27 with it disabled): in the profile the 104 IQ1_S swiglu launches
move to this kernel (692 ms) but the 16 softmax-free pairs whose two weights are
different formats (IQ1_M, IQ2_XS) stay on the generic kernel and hold 2937 ms of
the 12164 ms batch, so the arm's share is too small to move the model.
bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 19, 2026
…ml-org#2832) (#428)

* corpus: select the IQ1_S prefill arm, and key it on the id the dispatcher passes (ggml-org#2832)

The arm added in 831ed61 was keyed on 19, but no dispatcher can pass 19:
the corpus numbers weight formats with common_mul_mat_format_config_value()
(dispatch-mul-mat-weight-format.h), where Q4KRow64 = 44, Q6K = 6 and
IQ1_S = 26; 19 is ggml.h's type id.  @ggml_kquant_grid_fill_for also only
answers 21/22/24/25/26/27/28, so the 4 KiB codebook would have been staged
never and read uninitialised.

It also did not link: the motif calls @ggml_kquant_grid_fill_for, which is
defined in ops/kquant_decode_f32.loom, but no export that compiles the motif
lists that module, so every prefill launch of q4_K/q6_K dies with
"LINK/MATERIALIZE: unresolved exact declaration" and a refused command
(engine#2865, hw-gate 3593/3604 against 3604/3604 on the parent).

- motif: 19 -> 26 in both places, and call @ggml_kquant_iq1s_grid_fill
  (defined by the motif's own library, motifs/kquant_iq1_s.loom) instead of
  the format-dispatching wrapper, so no module has to link the 11k-line
  decode op to resolve it.
- manifest: every export that compiles motifs/mul_mat_quantized_f16_prefill.loom
  (22 of them) now lists motifs/kquant_iq1_s.loom in library_sources and
  compile_dependencies -- the corpus requires one list per primary source,
  and an unresolved declaration fails the Loom link even when the branch is
  dead.
- ops: @ggml_mul_mat_iq1_s_f16_wmma_prefill_wave32, the q4_K prefill schedule
  with 26 baked and the weight bound as stored rows (IQ1_S has no packed row
  layout).
- dispatch: common.mul_mat.iq1_s_prefill_wave32 at priority 294, IQ1_S, no
  alias, tokens 256..2048 step 256 (the kernel's own assume -- the q6_k
  route's 128 floor does not satisfy it), input % 256, output % 64.
- tests: three rows at 9 / 64 / 512 tokens, 4096-wide output; the row helper
  now quantizes IQ types through ggml_quantize_chunk with a dummy importance
  matrix, since they have no from_float_ref.

* corpus: stage both IQ1 packet halves in the f16 prefill publish (ggml-org#2832)

The IQ1 arm pinned the staged weight window offset to 0, so all four
producers of a row wrote the same 32 values at [0,32) and the consumer's
[32,64) half stayed uninitialised LDS: the prefill matmul returned NaN on
the 1024-workgroup tile (n=512 passed through the arm on gfx1151).

* test: cover the IQ1 prefill arm at one block and ten (ggml-org#2832)

* corpus: keep the IQ1 prefill arm on the 512-thread tile (ggml-org#2832)

The 1024-thread tile stages four halves of 32 values into the 64-value window the mma reads, so the
store origin ran to 32*3 + 16 = 112 on a 72-wide row: the Loom verifier refused the range as
unprovable ("vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9")
and the arm never compiled for the shapes Qwen3.8-27B asks for (5120x6144, 5120x17408). An IQ1
packet covers [32p, 32p+32), so two halves tile that window exactly and four do not.

Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, the arm toggled by dispatch name:

  pp512  11.30 +- 0.03 -> 90.15 +- 0.35 t/s   (7.98x)
  tg128  12.74 +- 0.01 -> 12.72 +- 0.02 t/s   (unchanged)

* corpus: stage the IQ1_S swiglu prefill from both weights (ggml-org#2832)

A paired tile stages the gate rows and the up rows from two buffers, but only
the q4_K native decoder ever read %up_weight: the IQ1 arm decoded both halves
from the gate weight, so a swiglu tile would have published gate rows twice.
The IQ1 arm now picks the buffer by %weight_is_up (the q4_K decoder's own
rule), leaving the generated IQ1 motif and its regenerated bytes untouched.

New kernel.def ggml_mul_mat_iq1_s_swiglu_f16_wmma_prefill_wave32 is the q4_K
swiglu prefill schedule with format 26, and the matcher
common.mul_mat_swiglu.iq1_s_prefill_wave32 (priority 305) claims a gate/up pair
of IQ1_S weights, 256..2048 tokens in 256-token steps, input % 256, output % 64.
Both layouts are pinned in the def (staged f16 input, un-packed f16 copy): the
staged geometry is the only one the IQ1 publish is proven at.

Device, gfx1151: the two new rows pass
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.256.4096  1806 ms
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.512.4096  1821 ms
and the full suite is 267 passed, 13 failed - the same 13 flash-attention rows
that engine#2870 tracks.

Qwen3.8-27B UD-IQ1_S pp512 is unchanged (90.37 +- 0.36 with the arm against
90.25 +- 0.27 with it disabled): in the profile the 104 IQ1_S swiglu launches
move to this kernel (692 ms) but the 16 softmax-free pairs whose two weights are
different formats (IQ1_M, IQ2_XS) stay on the generic kernel and hold 2937 ms of
the 12164 ms batch, so the arm's share is too small to move the model.

* corpus: stage IQ2_XXS, IQ2_XS and IQ1_M prefill from the same packet window

IQ1_S was the only format whose prefill staged the f16 weight tile; every
other quantized matmul in a UD-IQ1 model ran the generic one-wave schedule.
On Qwen3.8-27B that left 85% of the prefill matmul work there, the largest
share being IQ2_XXS (34 of the 68 non-IQ1_S tensors whose output dim is
5120), then IQ2_XS and IQ1_M.

All three block formats hold eight 4-value packets per 32-value group, and
motifs/dequant.loom already had a 4-value packet decoder for each, so a pair
helper can decode eight packets and concatenate them into the two 16-value
windows an IQ1_S packet fills -- the window geometry, the row-base math and
the up/gate select are the same as the IQ1_S arm.  Only the block size
differs: 50, 56, 66 and 74 bytes, now one select feeding the row stride.

Four arms, four registrations (iq1_s 294, iq2_xxs 293, iq2_xs 292, iq1_m
291), all gated the same way as the q6_K prefill.

* test: cover the staged IQ2 and IQ1_M arms, and quantize IQ1_M as it ships

make_quantized_rows passed a dummy importance matrix whenever a type had no
from_float_ref; IQ1_M has none and does not require one, so the guard refused
to build the weight at all.  Take the matrix only where the type asks for it.

Adds dense.iq2_xxs.{256,512}, dense.iq2_xs.512 and dense.iq1_m.512 rows at
4096 wide.

---------

Co-authored-by: bcloud <bcloud@localhost>
Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 19, 2026
#427)

* corpus: an IQ1_S producer arm in the f16 prefill publish (engine#2832)

The shared publish weights helper knew two weight layouts (q6 stored and
q6 packed, both 210-byte blocks) and one identical layout, the q4_K native
tile. IQ1_S is neither: 50-byte blocks reading a 4 KiB codebook, and a
packet p owns [32p, 32p+16) and [32p+16, 32p+32) -- 16 apart, where the q6
pair is 32 apart.

So the format test becomes iq1 first, the load offset is pinned to zero for
that arm, k1 becomes k0+16, the 8-wide store branch is suppressed (IQ1 needs
the 16-wide one), and the codebook is staged once per launch in the body,
where each subgroup fills its own chunk. The block size enters only through
the row stride, as the plan predicted.

Every existing format takes the same path as before: the iq1 flag is false,
so the select and the else arm reproduce the previous k0/k1 and store width.
Verified by rebuilding the corpus (ninja ggml-hrx links). No device
measurement yet, and no dispatch registration, so nothing selects format 19
into this op.

* corpus: declare the IQ1 codebook module where the motif is compiled (ggml-org#2865)

The arm added in 831ed61 calls @ggml_iq1s_f16_pair and @ggml_kquant_grid_fill_for,
both of which live in motifs/kquant_iq1_s.loom and ops/kquant_decode_f32.loom,
but no export that compiles motifs/mul_mat_quantized_f16_prefill.loom declares
either module.  The Loom root link resolves declarations from the recipe and
does not care that the new branch is dead for format 44, so every prefill
launch of q4_K and q6_K was refused:

  LINK/MATERIALIZE: unresolved exact declaration '@ggml_kquant_grid_fill_for'
  graph_compute: failed to prepare command 1 kind=Kernel ... bindings=3

That is the 11 hw_gate failures (3593/3604 against 3604/3604 on the parent),
not register pressure.

- motif: call @ggml_kquant_iq1s_grid_fill directly (declared in the motif,
  defined by motifs/kquant_iq1_s.loom) instead of the format-dispatching
  wrapper, so no module has to link the 11k-line decode op to resolve it.
- manifest: all 22 exports that compile the motif list motifs/kquant_iq1_s.loom
  in library_sources and compile_dependencies.  The corpus requires one list
  per primary source (collect_sources) and requires the two lists to be equal
  (generate_corpus_records).

* corpus: select the IQ1_S prefill arm and stage both packet halves (ggml-org#2832) (#428)

* corpus: select the IQ1_S prefill arm, and key it on the id the dispatcher passes (ggml-org#2832)

The arm added in 831ed61 was keyed on 19, but no dispatcher can pass 19:
the corpus numbers weight formats with common_mul_mat_format_config_value()
(dispatch-mul-mat-weight-format.h), where Q4KRow64 = 44, Q6K = 6 and
IQ1_S = 26; 19 is ggml.h's type id.  @ggml_kquant_grid_fill_for also only
answers 21/22/24/25/26/27/28, so the 4 KiB codebook would have been staged
never and read uninitialised.

It also did not link: the motif calls @ggml_kquant_grid_fill_for, which is
defined in ops/kquant_decode_f32.loom, but no export that compiles the motif
lists that module, so every prefill launch of q4_K/q6_K dies with
"LINK/MATERIALIZE: unresolved exact declaration" and a refused command
(engine#2865, hw-gate 3593/3604 against 3604/3604 on the parent).

- motif: 19 -> 26 in both places, and call @ggml_kquant_iq1s_grid_fill
  (defined by the motif's own library, motifs/kquant_iq1_s.loom) instead of
  the format-dispatching wrapper, so no module has to link the 11k-line
  decode op to resolve it.
- manifest: every export that compiles motifs/mul_mat_quantized_f16_prefill.loom
  (22 of them) now lists motifs/kquant_iq1_s.loom in library_sources and
  compile_dependencies -- the corpus requires one list per primary source,
  and an unresolved declaration fails the Loom link even when the branch is
  dead.
- ops: @ggml_mul_mat_iq1_s_f16_wmma_prefill_wave32, the q4_K prefill schedule
  with 26 baked and the weight bound as stored rows (IQ1_S has no packed row
  layout).
- dispatch: common.mul_mat.iq1_s_prefill_wave32 at priority 294, IQ1_S, no
  alias, tokens 256..2048 step 256 (the kernel's own assume -- the q6_k
  route's 128 floor does not satisfy it), input % 256, output % 64.
- tests: three rows at 9 / 64 / 512 tokens, 4096-wide output; the row helper
  now quantizes IQ types through ggml_quantize_chunk with a dummy importance
  matrix, since they have no from_float_ref.

* corpus: stage both IQ1 packet halves in the f16 prefill publish (ggml-org#2832)

The IQ1 arm pinned the staged weight window offset to 0, so all four
producers of a row wrote the same 32 values at [0,32) and the consumer's
[32,64) half stayed uninitialised LDS: the prefill matmul returned NaN on
the 1024-workgroup tile (n=512 passed through the arm on gfx1151).

* test: cover the IQ1 prefill arm at one block and ten (ggml-org#2832)

* corpus: keep the IQ1 prefill arm on the 512-thread tile (ggml-org#2832)

The 1024-thread tile stages four halves of 32 values into the 64-value window the mma reads, so the
store origin ran to 32*3 + 16 = 112 on a 72-wide row: the Loom verifier refused the range as
unprovable ("vector_extent is 16, view_bound is 72, and the maximum legal origin is 56 @ 18540:9")
and the arm never compiled for the shapes Qwen3.8-27B asks for (5120x6144, 5120x17408). An IQ1
packet covers [32p, 32p+32), so two halves tile that window exactly and four do not.

Qwen3.8-27B-UD-IQ1_S, gfx1151, one binary, the arm toggled by dispatch name:

  pp512  11.30 +- 0.03 -> 90.15 +- 0.35 t/s   (7.98x)
  tg128  12.74 +- 0.01 -> 12.72 +- 0.02 t/s   (unchanged)

* corpus: stage the IQ1_S swiglu prefill from both weights (ggml-org#2832)

A paired tile stages the gate rows and the up rows from two buffers, but only
the q4_K native decoder ever read %up_weight: the IQ1 arm decoded both halves
from the gate weight, so a swiglu tile would have published gate rows twice.
The IQ1 arm now picks the buffer by %weight_is_up (the q4_K decoder's own
rule), leaving the generated IQ1 motif and its regenerated bytes untouched.

New kernel.def ggml_mul_mat_iq1_s_swiglu_f16_wmma_prefill_wave32 is the q4_K
swiglu prefill schedule with format 26, and the matcher
common.mul_mat_swiglu.iq1_s_prefill_wave32 (priority 305) claims a gate/up pair
of IQ1_S weights, 256..2048 tokens in 256-token steps, input % 256, output % 64.
Both layouts are pinned in the def (staged f16 input, un-packed f16 copy): the
staged geometry is the only one the IQ1 publish is proven at.

Device, gfx1151: the two new rows pass
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.256.4096  1806 ms
  swiglu.iq1_s.iq1_s.iq1_s_swiglu_f16_wmma_prefill_wave32.512.4096  1821 ms
and the full suite is 267 passed, 13 failed - the same 13 flash-attention rows
that engine#2870 tracks.

Qwen3.8-27B UD-IQ1_S pp512 is unchanged (90.37 +- 0.36 with the arm against
90.25 +- 0.27 with it disabled): in the profile the 104 IQ1_S swiglu launches
move to this kernel (692 ms) but the 16 softmax-free pairs whose two weights are
different formats (IQ1_M, IQ2_XS) stay on the generic kernel and hold 2937 ms of
the 12164 ms batch, so the arm's share is too small to move the model.

* corpus: stage IQ2_XXS, IQ2_XS and IQ1_M prefill from the same packet window

IQ1_S was the only format whose prefill staged the f16 weight tile; every
other quantized matmul in a UD-IQ1 model ran the generic one-wave schedule.
On Qwen3.8-27B that left 85% of the prefill matmul work there, the largest
share being IQ2_XXS (34 of the 68 non-IQ1_S tensors whose output dim is
5120), then IQ2_XS and IQ1_M.

All three block formats hold eight 4-value packets per 32-value group, and
motifs/dequant.loom already had a 4-value packet decoder for each, so a pair
helper can decode eight packets and concatenate them into the two 16-value
windows an IQ1_S packet fills -- the window geometry, the row-base math and
the up/gate select are the same as the IQ1_S arm.  Only the block size
differs: 50, 56, 66 and 74 bytes, now one select feeding the row stride.

Four arms, four registrations (iq1_s 294, iq2_xxs 293, iq2_xs 292, iq1_m
291), all gated the same way as the q6_K prefill.

* test: cover the staged IQ2 and IQ1_M arms, and quantize IQ1_M as it ships

make_quantized_rows passed a dummy importance matrix whenever a type had no
from_float_ref; IQ1_M has none and does not require one, so the guard refused
to build the weight at all.  Take the matrix only where the type asks for it.

Adds dense.iq2_xxs.{256,512}, dense.iq2_xs.512 and dense.iq1_m.512 rows at
4096 wide.

---------

Co-authored-by: bcloud <bcloud@localhost>
Co-authored-by: bong-water-water-bong <[email protected]>

---------

Co-authored-by: bcloud <bcloud@localhost>
Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 20, 2026
The 1024-workgroup tile needs 20480 + 2x36864 bytes of workgroup memory and
this arm stages the 4 KiB codebook on top of that: 73728 against the 64 KiB a
workgroup has, so the arm cannot be selected at those shapes. The tile choice
is folded into the selection that already exists (ggml-org#2832).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants