mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-12-02 07:37:40 -06:00
Compare commits
98
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7a9208f7b | ||
|
|
02227e87ae | ||
|
|
94f17f659f | ||
|
|
08dc1cea9e | ||
|
|
94be107ac2 | ||
|
|
92f76e5c56 | ||
|
|
509468d5aa | ||
|
|
b9073e5483 | ||
|
|
e5cd6e34ba | ||
|
|
cda9b4113c | ||
|
|
562f4b85b2 | ||
|
|
9452452764 | ||
|
|
06fa894b15 | ||
|
|
30b900181b | ||
|
|
6d0716cff4 | ||
|
|
04586184ce | ||
|
|
2e11b8a8dd | ||
|
|
c9dbfa5779 | ||
|
|
ae2b404f08 | ||
|
|
6fd26a7ea0 | ||
|
|
b7a59f3f54 | ||
|
|
c82b798866 | ||
|
|
386e41466b | ||
|
|
2868ee950f | ||
|
|
441d045986 | ||
|
|
75bfc7de2e | ||
|
|
a3f7cb2b9a | ||
|
|
8f24c2288a | ||
|
|
2efe7f1d41 | ||
|
|
dee778bd0b | ||
|
|
ba16f3f8c9 | ||
|
|
103b19e9ff | ||
|
|
7dca4a8daa | ||
|
|
ce94c097bc | ||
|
|
a1973da637 | ||
|
|
5b1ba66b59 | ||
|
|
713fee7fb0 | ||
|
|
e89795bf78 | ||
|
|
1f1e6cb26a | ||
|
|
db503b89fd | ||
|
|
78c9ca4b06 | ||
|
|
abeb9e7bd7 | ||
|
|
c8476ae546 | ||
|
|
779b413a67 | ||
|
|
7dfa241048 | ||
|
|
49f972e139 | ||
|
|
019951ec44 | ||
|
|
616c931e4b | ||
|
|
e1b9f46453 | ||
|
|
559afe384f | ||
|
|
2d48484127 | ||
|
|
22d68b8ac3 | ||
|
|
7778397892 | ||
|
|
8d0323c856 | ||
|
|
c2d2fc6a10 | ||
|
|
9bb00f98c4 | ||
|
|
3e23348afe | ||
|
|
0f72a8695a | ||
|
|
81a22ceb7b | ||
|
|
a346a49f88 | ||
|
|
2924a0e26b | ||
|
|
808d1fed52 | ||
|
|
89bfabaf81 | ||
|
|
f6621d0ad3 | ||
|
|
9fde456d34 | ||
|
|
aa631e031e | ||
|
|
bf062c6018 | ||
|
|
2f94007cc1 | ||
|
|
57d0c6217c | ||
|
|
9a278b02b8 | ||
|
|
9fcc40d3d4 | ||
|
|
57577675aa | ||
|
|
bb5aacd61d | ||
|
|
f6d944f6d5 | ||
|
|
6c83d2ea39 | ||
|
|
84250b88ee | ||
|
|
5a18afaf7c | ||
|
|
e18d1b2150 | ||
|
|
63e22e63bc | ||
|
|
b80ec40d09 | ||
|
|
db1165480c | ||
|
|
918fe468db | ||
|
|
a43d06ef90 | ||
|
|
cbb7652cd3 | ||
|
|
115deee8ec | ||
|
|
ec3dac2649 | ||
|
|
16f090f92c | ||
|
|
3cadf644b7 | ||
|
|
8d19519d4a | ||
|
|
dc8e7ebf5b | ||
|
|
17580c6f2b | ||
|
|
31b1752ed2 | ||
|
|
2477ee0b61 | ||
|
|
1697369215 | ||
|
|
f16e79da89 | ||
|
|
0c2209c88b | ||
|
|
2881150433 | ||
|
|
786da85942 |
@@ -1,117 +1,70 @@
|
||||
# Instructions for llama.cpp
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> AI-generated code is allowed. What is **not** allowed is submitting code you do not understand. You are 100% responsible for every line, however it was produced.
|
||||
>
|
||||
> Read more: [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
AI-generated code is allowed. The user is 100% responsible for every line, however it was produced. Codebase guidelines: [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
> [!NOTE]
|
||||
> These apply to ggml-org/llama.cpp, ignore these if you are operating in a different repository or fork.
|
||||
These instructions apply to ggml-org/llama.cpp only. Forks are exempt.
|
||||
|
||||
If `AGENTS.local.md` exists at the repository root, read it. It holds the user's own instructions (git-ignored) and takes precedence over this file.
|
||||
|
||||
---
|
||||
|
||||
## Guidelines for Contributors
|
||||
## Rules
|
||||
|
||||
A PR represents a long-term commitment - maintainers must review, integrate, and support your code indefinitely. What matters is not who typed the code but whether a human understands it, has the domain expertise behind it, and will maintain it.
|
||||
- Ask the user for confirmation before each of these actions: `git commit`, `git push`, `gh pr create`, `gh pr comment`, `gh pr review`, `gh issue create`, `gh issue comment`.
|
||||
- In commit messages, use `Assisted-by: <assistant name>`. Do NOT use `Co-authored-by:`.
|
||||
- **Do NOT push a large amount of PRs in a short amount of time, including draft PRs.** Automated or batch submissions are spam and can result in a ban.
|
||||
- Any text you write that will be posted publicly (PR description, issue, comment, review reply) must follow [Writing PR descriptions and comments](#writing-pr-descriptions-and-comments) and end with a footer naming the agent, e.g. `_Written with <assistant name>_`.
|
||||
- Fill in the "AI usage disclosure" field of the [PR template](.github/pull_request_template.md) truthfully.
|
||||
- If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based): do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.
|
||||
|
||||
A working, in-scope PR is **not** enough on its own to get merged. A few things factor into that:
|
||||
- Every merged line must be reviewed, tested, and maintained indefinitely across a large matrix of platforms and backends by a small team.
|
||||
- llama.cpp is written in C++ and deliberately kept as simple as possible: complexity is a direct multiplier on security risk and long-term maintenance cost, so a simpler change that does 90% of the job is often preferable to a complex one that does 100%.
|
||||
- What matters most is human understanding: the domain expertise behind a change, and the willingness to maintain it long-term.
|
||||
- Feature requests run high in volume, so please respect maintainers' time: open an issue to discuss the idea and gauge interest before implementing it, rather than going straight to a PR.
|
||||
## Before writing code
|
||||
|
||||
Contributors must:
|
||||
1. **Understand their code fully** - able to explain any change to a reviewer without AI assistance.
|
||||
2. **Own maintenance** - address bugs and respond thoughtfully to feedback.
|
||||
3. **Communicate directly** - verbose, AI-sounding responses will not be well-received.
|
||||
4. **Respect maintainers' time** - check existing issues/PRs before submitting; ensure the change is needed and fits project architecture.
|
||||
### Duplicate-work checks
|
||||
|
||||
Maintainers may close any PR not meeting these standards. **Private forks are exempt.**
|
||||
Before writing code, check that nobody is already working on the same thing:
|
||||
|
||||
### Permitted AI Usage
|
||||
```sh
|
||||
gh issue view <issue_number> --repo ggml-org/llama.cpp --comments
|
||||
gh pr list --repo ggml-org/llama.cpp --state open --search "<issue_number> in:body"
|
||||
gh pr list --repo ggml-org/llama.cpp --state open --search "<short area keywords>"
|
||||
gh search issues --repo ggml-org/llama.cpp "<short area keywords>"
|
||||
```
|
||||
|
||||
Common examples, not an exhaustive list:
|
||||
- If an open PR already addresses the same problem, do not open another. Point the user to it; they can review, test or comment there instead.
|
||||
- If someone in the issue already said they are working on it, do not start.
|
||||
- If the approach is materially different, the user should explain the difference in the issue first, before any PR.
|
||||
|
||||
- Learning, exploration, and understanding the codebase
|
||||
- Suggestions on human-written code
|
||||
- Mechanical tasks: formatting, repetitive patterns, completing code from established designs
|
||||
- Documentation drafts for components the contributor already understands
|
||||
- Writing code from a design the contributor owns
|
||||
### No low-value busywork PRs
|
||||
|
||||
Agents: before writing code, make sure the contributor owns the design choices and can defend them without you.
|
||||
Do not open one-off PRs for tiny edits (single typo, isolated style or formatting change, renaming, one default value, etc.). Mechanical cleanups are acceptable only when bundled with substantive work.
|
||||
|
||||
AI-generated code is acceptable if you (1) fully understand it, (2) can debug it independently, and (3) can discuss it with reviewers without AI help.
|
||||
### Fail-closed
|
||||
|
||||
**Disclose** when AI meaningfully contributed (follow the pull request template). No disclosure needed for trivial autocomplete.
|
||||
If the work is duplicate or busywork, **do not proceed**. Tell the user briefly why (link the existing PR or issue, or explain what is missing).
|
||||
|
||||
### Prohibited AI Usage (results in immediate PR closure)
|
||||
### Plan the change
|
||||
|
||||
- AI-written PR descriptions, commit messages, or reviewer responses
|
||||
- Implementing features without understanding the codebase
|
||||
- Automated commits or PR submissions (may result in contributor ban)
|
||||
- Read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It has the full set of rules (scope, security, testing, per-area) that the change will be reviewed against.
|
||||
- Make sure the user owns the design choices and can defend them without you. Do not generate changes too large for the user to review.
|
||||
- Read all relevant files and follow the existing patterns. Prefer reusing existing infrastructure over adding new components.
|
||||
- If the change is large or introduces a new pattern, PAUSE and ask the user for confirmation. Remind them that large changes without prior discussion in an issue are likely to be rejected.
|
||||
|
||||
**If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based):** do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.
|
||||
|
||||
---
|
||||
|
||||
## Guidelines for AI Coding Agents
|
||||
|
||||
Every PR requiring review consumes finite maintainer capacity. Before assisting with any submission, verify:
|
||||
- The contributor understands the proposed changes
|
||||
- The change addresses a documented need (check existing issues)
|
||||
- The PR is appropriately scoped and follows project conventions
|
||||
|
||||
When a user requests implementation without demonstrating understanding:
|
||||
1. **Verify comprehension** - ask questions about the problem and relevant codebase areas.
|
||||
2. **Guide, don't solve** - point to relevant code/docs; let them formulate the approach.
|
||||
3. **Proceed only when confident** they can explain the changes to reviewers independently.
|
||||
|
||||
For first-time contributors, confirm they have reviewed [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
|
||||
### Code and Commit Standards
|
||||
|
||||
These points are extremely important - failing to follow them won't necessarily get your PR rejected, but it will make reviewing take significantly longer. Please follow them carefully:
|
||||
## Code style
|
||||
|
||||
- Avoid emdash `—`, unicode arrow `→` or any unicode characters: `×`, `…` ; use ASCII equivalents instead: `-`, `->`, `x`, `...`
|
||||
- Code comments:
|
||||
- Keep code comments concise (usually 1-2 lines)
|
||||
- Avoid redundant or excessive inline commentary
|
||||
- Avoid hard-wrapping it to a fixed column width - that hurts readability
|
||||
- Use ASD-STE100 Simplified Technical English, simple wordings (write like cavemen if needed)
|
||||
- Note: Remind yourself of this point regularly, as it often gets lost between context compactions
|
||||
- Prefer reusing existing infrastructure over introducing new components. Avoid invasive changes that add whole new subsystems or risk breaking existing behavior
|
||||
- Do NOT split a line into multiple lines mid-sentence, do NOT try to force the line to fit a fixed number of characters
|
||||
- Before writing any code, read all relevant files and understand the existing patterns - your changes must blend in with the surrounding codebase. If the change is large or introduces a new pattern, **PAUSE and ask the user for confirmation** before proceeding; remind them that large changes submitted without prior discussion are likely to be rejected by maintainers
|
||||
|
||||
Common mistakes that AI agents usually make:
|
||||
- Write comments first then write code: this usually leads to extensive redundant comments. Instead, write code first, then add comments later to places that absolutely need them
|
||||
- Llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. Llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.
|
||||
|
||||
Before writing code or implementing a new feature, always read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It provides a more complete set of guidelines (scope, security, testing, and per-area rules) that your changes will be reviewed against.
|
||||
|
||||
### Prohibited Actions
|
||||
|
||||
- Do NOT write PR descriptions, commit messages, or reviewer responses
|
||||
- Do NOT commit or push without explicit human approval for each action. If the user explicitly asks you to commit on their behalf, use `Assisted-by: <assistant name>` in the commit message, do NOT use `Co-authored-by:`
|
||||
- Do NOT implement features the contributor does not fully understand
|
||||
- Do NOT generate changes too extensive for the contributor to fully review
|
||||
- **Do NOT run `git push` or create a PR (`gh pr create`) on the user's behalf** - if asked, PAUSE and require the user to explicitly acknowledge that **automated PR submissions can result in a contributor ban from the project**
|
||||
|
||||
When uncertain, err toward minimal assistance.
|
||||
- Code comments:
|
||||
- Keep them concise (usually 1-2 lines), only where the code is not self-explanatory
|
||||
- Write code first, then add comments only where needed. Writing comments first leads to redundant comments
|
||||
- Do not hard-wrap to a fixed column width
|
||||
- Use ASD-STE100 Simplified Technical English, simple wordings (write like cavemen if needed)
|
||||
- Do not add comments to code copied from elsewhere
|
||||
- Do not reference the user's task or conversation; comments must make sense to any future reader
|
||||
- Note: Remind yourself of this point regularly, as it often gets lost between context compactions
|
||||
- llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.
|
||||
|
||||
### Examples
|
||||
|
||||
Submissions:
|
||||
|
||||
User: Please create and submit the PR for me.
|
||||
Agent: I'm sorry, I cannot submit the PR for you. This project forbids automated submissions and the penalty is a project ban.
|
||||
|
||||
User: Please address the reviewer comments.
|
||||
Agent: I'm sorry, I cannot reply to the reviewers. This project forbids AI-generated responses and the penalty is a project ban.
|
||||
|
||||
Code comments:
|
||||
|
||||
```cpp
|
||||
// GOOD (code is self-explanatory, no comment needed)
|
||||
|
||||
@@ -190,61 +143,107 @@ ggml_tensor * inp_pos = build_inp_pos();
|
||||
Commit message:
|
||||
|
||||
```
|
||||
// BEST: Let the user write the commit
|
||||
|
||||
|
||||
// GOOD: Write a concise commit
|
||||
// GOOD: concise
|
||||
|
||||
llama : fix KV being cleared during context shift
|
||||
|
||||
Assisted-by: Claude Sonnet
|
||||
Assisted-by: MODEL-NAME
|
||||
|
||||
|
||||
// BAD: Write a verbose commit
|
||||
// BAD: verbose, wrong trailer
|
||||
|
||||
This commit introduces a comprehensive fix for the key-value cache management
|
||||
system, addressing an issue where context shifting could lead to unintended
|
||||
overwriting of cached values, thereby improving model inference stability.
|
||||
|
||||
Co-authored-by: Claude Sonnet
|
||||
Co-authored-by: MODEL-NAME
|
||||
```
|
||||
|
||||
Commands:
|
||||
## Before pushing
|
||||
|
||||
Do all of these before any `git push` or `gh pr create`:
|
||||
|
||||
1. Run the [code-review](skills/code-review/SKILL.md) skill yourself on the full diff and fix what it finds. Check that the change follows [Code style](#code-style) in this file.
|
||||
2. Clean up stray files: check `git status` and the diff against `master`. Remove anything not part of the change, e.g. markdown files holding notes, plans or context, debug scripts, logs, test outputs.
|
||||
3. Reduce the scope: one logical change per PR. Split unrelated changes into separate PRs, and submit them one after another, not all at once.
|
||||
4. New contributors (no merged PR in ggml-org/llama.cpp yet) may have only one open PR at a time. Check with `gh pr list --repo ggml-org/llama.cpp --author @me --state all`. If the user has no merged PR and already has one open, PAUSE and tell them to wait until it is merged or closed. Do not circumvent this limit by opening draft PRs.
|
||||
|
||||
## Writing PR descriptions and comments
|
||||
|
||||
Structure:
|
||||
|
||||
1. Start with 2 short sentences: what changed, and why.
|
||||
2. Then 1-3 short paragraphs if needed (code blocks do not count).
|
||||
3. Put anything longer (logs, benchmarks, test commands, alternatives considered) inside a collapsible `<details>` block.
|
||||
|
||||
Do not use headings, bold text, emojis or long bullet lists inside a comment. For PR descriptions, follow the sections of the [PR template](.github/pull_request_template.md) and apply the same structure inside each section.
|
||||
|
||||
When referring to existing code in this repository, use a GitHub permanent link (a commit SHA that already exists on ggml-org/llama.cpp, plus the line range). GitHub renders it as a code snippet, e.g.:
|
||||
|
||||
```
|
||||
https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
|
||||
```
|
||||
|
||||
Permanent links to other projects are not rendered as a snippet. Wrap them in a markdown link with a readable name instead, e.g. `[the PyTorch reference code](https://github.com/...)`.
|
||||
|
||||
### Example
|
||||
|
||||
````markdown
|
||||
// GOOD
|
||||
|
||||
Addressed in the latest commit. The retry loop now stops on HTTP 4xx errors instead of retrying them.
|
||||
|
||||
It reuses the existing status check rather than adding a new helper:
|
||||
|
||||
https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
|
||||
|
||||
The backoff values follow [the huggingface_hub implementation](https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95), so the behavior matches `hf download`.
|
||||
|
||||
<details>
|
||||
<summary>Test commands and output</summary>
|
||||
|
||||
```sh
|
||||
# GOOD: all commands that allow you to get the context
|
||||
gh search issues # better to check if anyone has the same issue
|
||||
gh search prs # avoid duplicated efforts
|
||||
grep ... # search the code base
|
||||
|
||||
# BAD: act on the user's behalf
|
||||
git commit -m "..."
|
||||
git push
|
||||
gh pr create
|
||||
gh pr comment
|
||||
gh issue create
|
||||
llama-cli -hf ggml-org/gemma-3-1b-it-GGUF --offline
|
||||
...
|
||||
```
|
||||
|
||||
## Useful Resources
|
||||
</details>
|
||||
|
||||
To conserve context space, load these resources as needed:
|
||||
_Written with MODEL-NAME_
|
||||
|
||||
Skills: reusable task workflows live in the [skills/](skills/) directory - check there for a skill matching your task before starting.
|
||||
|
||||
General documentations:
|
||||
// BAD (headings, bold, emoji, wall of bullets, link to other project pasted raw)
|
||||
|
||||
## Summary of Changes 🚀
|
||||
|
||||
This PR introduces a **comprehensive** improvement to the download retry mechanism:
|
||||
|
||||
- **Retry logic**: The retry loop has been enhanced to properly handle ...
|
||||
- **Error handling**: Comprehensive handling of HTTP 4xx status codes ...
|
||||
- **Consistency**: Aligned with https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95
|
||||
- **Testing**: Thoroughly tested across multiple scenarios ...
|
||||
````
|
||||
|
||||
## Resources
|
||||
|
||||
To conserve context space, load these as needed.
|
||||
|
||||
Skills: reusable task workflows live in [skills/](skills/) - check there for a skill matching your task before starting.
|
||||
|
||||
General:
|
||||
- [Contributing guidelines](CONTRIBUTING.md)
|
||||
- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [Existing PRs](https://github.com/ggml-org/llama.cpp/pulls) - always search here first
|
||||
- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [existing PRs](https://github.com/ggml-org/llama.cpp/pulls)
|
||||
- [How to add a new model](docs/development/HOWTO-add-model.md)
|
||||
- [PR template](.github/pull_request_template.md)
|
||||
|
||||
Server:
|
||||
- [Build documentation](docs/build.md)
|
||||
- [Server usage documentation](tools/server/README.md)
|
||||
- [Server development documentation](tools/server/README-dev.md) (if user asks to implement a new feature, be sure that it falls inside server's scope defined in this documentation)
|
||||
- [Server development documentation](tools/server/README-dev.md) (if the user asks for a new feature, check that it falls inside the server's scope defined there)
|
||||
|
||||
Chat template and parser:
|
||||
- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model's output
|
||||
- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detect model-specific features
|
||||
- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model output
|
||||
- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detects model-specific features
|
||||
- [Jinja engine](common/jinja/README.md)
|
||||
|
||||
Testing:
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# ggml-org/ggml-et : marty1885
|
||||
# ggml-org/ggml-hexagon : lhez, max-krasnyansky
|
||||
# ggml-org/ggml-hip : IMbackK, thelittlefireman
|
||||
# ggml-org/ggml-hrx : AaronStGeorge, Geramy, IMbackK, pwilkin
|
||||
# ggml-org/ggml-metal : forforever73, ggerganov, jhen0409, masterFoad
|
||||
# ggml-org/ggml-opencl : lhez, max-krasnyansky
|
||||
# ggml-org/ggml-openvino : ravi9, wine99
|
||||
@@ -56,6 +57,7 @@
|
||||
/ggml/src/ggml-cuda/vendors/hip.h @IMbackK
|
||||
/ggml/src/ggml-hexagon/ @ggml-org/ggml-hexagon
|
||||
/ggml/src/ggml-hip/ @ggml-org/ggml-hip
|
||||
/ggml/src/ggml-hrx/ @ggml-org/ggml-hrx @AaronStGeorge @Geramy @IMbackK @pwilkin
|
||||
/ggml/src/ggml-et/ @marty1885
|
||||
/ggml/src/ggml-impl.h @ggerganov
|
||||
/ggml/src/ggml-metal/ @ggml-org/ggml-metal
|
||||
|
||||
+7
-37
@@ -6,50 +6,20 @@ The project differentiates between 3 levels of contributors:
|
||||
- Collaborators (Triage): people with significant contributions, who may be responsible for some parts of the code, and are expected to maintain and review contributions for the code they own
|
||||
- Maintainers: responsible for reviewing and merging PRs, after approval from the code owners
|
||||
|
||||
# AI Usage Policy
|
||||
# AI Usage
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> AI-generated code is allowed. You are 100% responsible for every line, however it was produced.
|
||||
>
|
||||
> Undisclosed AI usage may result in your account being permanently banned from contributing to the project.
|
||||
>
|
||||
> Detailed information regarding permissible and restricted uses of AI can be found in the [AGENTS.md](AGENTS.md) file.
|
||||
|
||||
### Requirements
|
||||
|
||||
If AI is used to generate any portion of the code, contributors must adhere to the following requirements:
|
||||
|
||||
1. Explicitly disclose the manner in which AI was employed.
|
||||
2. Check for an existing PR addressing the same change; if one exists, comment there to work with its author instead of opening a duplicate.
|
||||
3. Perform a comprehensive manual review prior to submitting the pull request. A proper code review usually takes something like one hour per 200-400 LOC and you should be spending **at least that much time on code review alone**.
|
||||
4. Be prepared to explain every line of code you submit when asked about it by a maintainer.
|
||||
5. It is strictly prohibited to use AI to write your posts for you (bug reports, feature requests, pull request descriptions, Github discussions, responding to humans, ...).
|
||||
|
||||
### Checklist
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> **If you use AI, do all of the following:**
|
||||
>
|
||||
> 1. **Make sure [AGENTS.md](AGENTS.md) is loaded into your agent's context.** Skipping this step is one of the most common reasons PRs get rejected.
|
||||
> 2. **Search for related discussions, PRs and issues** to get the broader context before writing any code.
|
||||
> 3. **Run a local review pass before pushing anything**, using the [`code-review`](skills/code-review/SKILL.md) skill, once the change is implemented. Fix what it finds.
|
||||
|
||||
For more info, please refer to the [AGENTS.md](AGENTS.md) file.
|
||||
If you use AI tools, see [AGENTS.md](AGENTS.md).
|
||||
|
||||
# Pull requests (for contributors & collaborators)
|
||||
|
||||
### Before you start
|
||||
|
||||
- Search for existing discussions and PRs first - duplicates will likely be closed without questions.
|
||||
- Features must begin with an issue, not a PR - let interest accumulate before writing code; niche features may only land as an example/tool, or on a private fork.
|
||||
- Bug-fix PRs must include a reproducible issue and a regression test that fails before your change and passes after. Fixes without a test may be closed without review.
|
||||
- New CLI or public API additions carry a **higher bar** than internal changes - justify why an existing mechanism doesn't suffice.
|
||||
- Meeting all of the above still doesn't guarantee a merge - see [Pull requests (for maintainers)](#pull-requests-for-maintainers).
|
||||
- Search for existing discussions and PRs first
|
||||
- Bug-fix PRs must include a reproducible issue and usually a regression test that fails before the change
|
||||
- Prefer simple and small PRs when possible
|
||||
- If you are a new contributor
|
||||
- Limit your open PRs to 1
|
||||
- Do not submit trivial fixes (e.g. typos, formatting changes)
|
||||
- Limit your open PRs to 1
|
||||
- Do not submit trivial fixes (e.g. typos, formatting changes)
|
||||
|
||||
### Preparing your PR
|
||||
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
set(TARGET llama-app)
|
||||
|
||||
add_executable(${TARGET} llama.cpp download.cpp)
|
||||
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
OUTPUT_NAME llama
|
||||
PDB_NAME ${TARGET}
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET} PRIVATE
|
||||
llama-server-impl
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
# with OPENVINO support
|
||||
# GG_BUILD_OPENVINO=1 GG_BUILD_LOW_PERF=1 GGML_OPENVINO_DEVICE=CPU bash ./ci/run.sh ./tmp/results ./tmp/mnt
|
||||
#
|
||||
# with HRX support
|
||||
# GG_BUILD_HRX=1 HRX_SDK_PATH=/path/to/hrx-sdk bash ./ci/run.sh ./tmp/results ./tmp/mnt
|
||||
#
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
echo "usage: $0 <output-dir> <mnt-dir>"
|
||||
@@ -99,6 +102,17 @@ if [ ! -z ${GG_BUILD_ROCM} ]; then
|
||||
CMAKE_EXTRA="${CMAKE_EXTRA} -DGPU_TARGETS=${GG_BUILD_AMDGPU_TARGETS}"
|
||||
fi
|
||||
|
||||
if [ ! -z ${GG_BUILD_HRX} ]; then
|
||||
CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_HRX=ON"
|
||||
|
||||
if [ ! -z "${HRX_SDK_PATH}" ]; then
|
||||
export CMAKE_PREFIX_PATH="${HRX_SDK_PATH}${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}}"
|
||||
fi
|
||||
|
||||
# TODO: HRX has no quantized KV cache yet (SET_ROWS into q8_0)
|
||||
CTEST_EXTRA="-E test-llama-context"
|
||||
fi
|
||||
|
||||
if [ ! -z ${GG_BUILD_SYCL} ]; then
|
||||
if [ -z ${ONEAPI_ROOT} ]; then
|
||||
echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
|
||||
@@ -439,10 +453,13 @@ function gg_run_qwen3_0_6b {
|
||||
|
||||
(time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test} -ngl 99 -c 1024 -b 512 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
|
||||
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 10 -c 1024 -fa off --no-op-offload) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 99 -c 1024 -fa off ) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 10 -c 1024 -fa on --no-op-offload) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 99 -c 1024 -fa on ) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
# TODO: HRX has no quantized KV cache yet (SET_ROWS into q8_0)
|
||||
if [ -z ${GG_BUILD_HRX} ]; then
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 10 -c 1024 -fa off --no-op-offload) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 99 -c 1024 -fa off ) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 10 -c 1024 -fa on --no-op-offload) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
(time ./bin/test-llama-context --model ${model_q4_0} -ngl 99 -c 1024 -fa on ) 2>&1 | tee -a $OUT/${ci}-test-llama-context.log
|
||||
fi
|
||||
|
||||
check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")"
|
||||
if [ -z ${GG_BUILD_NO_BF16} ]; then
|
||||
|
||||
+14
-2
@@ -291,13 +291,21 @@ const std::vector<ggml_type> kv_cache_types = {
|
||||
GGML_TYPE_Q5_1,
|
||||
};
|
||||
|
||||
static ggml_type kv_cache_type_from_str(const std::string & s) {
|
||||
ggml_type common_parse_kv_cache_type(const std::string & s) {
|
||||
for (const auto & type : kv_cache_types) {
|
||||
if (ggml_type_name(type) == s) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Unsupported cache type: " + s);
|
||||
return GGML_TYPE_COUNT;
|
||||
}
|
||||
|
||||
static ggml_type kv_cache_type_from_str(const std::string & s) {
|
||||
const ggml_type type = common_parse_kv_cache_type(s);
|
||||
if (type == GGML_TYPE_COUNT) {
|
||||
throw std::runtime_error("Unsupported cache type: " + s);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static std::string get_all_kv_cache_types() {
|
||||
@@ -2253,6 +2261,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
"BNF-like grammar to constrain generations (see samples in grammars/ dir)",
|
||||
[](common_params & params, const std::string & value) {
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_USER, value};
|
||||
params.sampling.json_schema.clear();
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
@@ -2260,6 +2269,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
"file to read grammar from",
|
||||
[](common_params & params, const std::string & value) {
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_USER, read_file(value)};
|
||||
params.sampling.json_schema.clear();
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
@@ -2267,6 +2277,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
"JSON schema to constrain generations (https://json-schema.org/), e.g. `{\"type\": \"object\"}` for any JSON object",
|
||||
[](common_params & params, const std::string & value) {
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(json::parse(value))};
|
||||
params.sampling.json_schema = value;
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
@@ -2284,6 +2295,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
std::back_inserter(schema)
|
||||
);
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(json::parse(schema))};
|
||||
params.sampling.json_schema = schema;
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
// CLI argument parsing
|
||||
//
|
||||
|
||||
ggml_type common_parse_kv_cache_type(const std::string & value);
|
||||
|
||||
struct common_arg {
|
||||
std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON};
|
||||
std::set<enum llama_example> excludes = {};
|
||||
|
||||
@@ -890,6 +890,11 @@ static bool is_vibevoice_asr_template(const std::string & src) {
|
||||
return src.find("transcribes audio input into text output in JSON format") != std::string::npos;
|
||||
}
|
||||
|
||||
// Qwen3-ASR: the template marks the transcript boundary with <asr_text>
|
||||
static bool is_qwen3_asr_template(const std::string & src) {
|
||||
return src.find("<asr_text>") != std::string::npos;
|
||||
}
|
||||
|
||||
// LFM3-Audio: language code -> name
|
||||
static std::string lfm3_language_name(const std::string & language) {
|
||||
static const std::map<std::string, std::string> names = {
|
||||
@@ -936,6 +941,13 @@ common_chat_prompt_preset common_chat_get_asr_prompt(const common_chat_templates
|
||||
}
|
||||
asr_preset.media_first = true;
|
||||
asr_preset.needs_audio_length = true;
|
||||
} else if (is_qwen3_asr_template(src)) {
|
||||
// Context belongs in the system turn and the user turn is audio only.
|
||||
// Language is detected from the audio, so do not append it to the user text.
|
||||
asr_preset.system = context;
|
||||
asr_preset.user = "";
|
||||
asr_preset.has_context = true;
|
||||
asr_preset.has_language = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1365,6 +1377,13 @@ static common_chat_params common_chat_params_init_lfm2_5(const common_chat_templ
|
||||
// Pick the dedicated handler for a template from its source, or null for the autoparser.
|
||||
// Order matters: the first match wins, and later checks assume the earlier ones did not match.
|
||||
static common_chat_params_init_fn common_chat_template_detect_params_init(const std::string & src) {
|
||||
if (src.find("You are Apertus 1.5 Omni") != std::string::npos &&
|
||||
src.find("<|inner_prefix|>") != std::string::npos &&
|
||||
src.find("<|tools_prefix|>") != std::string::npos) {
|
||||
LOG_DBG("Using specialized template: Apertus 1.5\n");
|
||||
return common_chat_params_init_apertus_1_5;
|
||||
}
|
||||
|
||||
// Ministral/Mistral Large 3 - uses special reasoning structure fixes, can't use autoparser
|
||||
// Note: Mistral Small 3.2 uses [CALL_ID] which Ministral doesn't have, so we can distinguish them
|
||||
if (src.find("[SYSTEM_PROMPT]") != std::string::npos && src.find("[TOOL_CALLS]") != std::string::npos &&
|
||||
@@ -2034,6 +2053,9 @@ void common_chat_session::apply_sampling(common_params_sampling & sampling) cons
|
||||
}
|
||||
if (!grammar_text.empty()) {
|
||||
sampling.grammar = {COMMON_GRAMMAR_TYPE_TOOL_CALLS, grammar_text};
|
||||
} else if (sampling.grammar.type == COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT) {
|
||||
// drop the schema grammar when the template does not use it, since it would reject the generation prompt
|
||||
sampling.grammar = {};
|
||||
}
|
||||
sampling.grammar_lazy = grammar_lazy;
|
||||
sampling.generation_prompt = generation_prompt_text;
|
||||
|
||||
+2
-2
@@ -520,8 +520,8 @@ std::optional<common_chat_params> common_chat_try_specialized_template(
|
||||
struct common_chat_prompt_preset {
|
||||
std::string system;
|
||||
std::string user;
|
||||
bool has_language = false; // the preset already names the requested language
|
||||
bool has_context = false; // the user text already holds the context
|
||||
bool has_language = false; // the preset already handles the language, do not append it
|
||||
bool has_context = false; // the preset already handles the context, use preset.user
|
||||
bool media_first = false; // the media goes before the user text
|
||||
bool needs_audio_length = false; // the user text depends on the audio length, call again with it
|
||||
};
|
||||
|
||||
+6
-4
@@ -1170,6 +1170,7 @@ static const std::map<common_decision_type, std::string> COMMON_DECISION_TYPE_NA
|
||||
{ COMMON_DECISION_TYPE_MINICPM_OCR_JEV, "openbmb-minicpm-ocr-jev" },
|
||||
{ COMMON_DECISION_TYPE_LFM3_D1, "lfm3-d1" },
|
||||
{ COMMON_DECISION_TYPE_LFM3_D1_OMNI, "lfm3-d1-omni" },
|
||||
{ COMMON_DECISION_TYPE_CLEF_OMNI, "cloudflare-clef-omni" },
|
||||
// for future models, ALWAYS add org name prefix to avoid name collisions, e.g. "orgname-modelname"
|
||||
};
|
||||
|
||||
@@ -1298,6 +1299,7 @@ common_init_result::common_init_result(common_params & params, bool model_only)
|
||||
const auto decision_type = common_get_decision_type(model);
|
||||
// minicpm-ocr-jev reads its class scores from the pooled output, the pooling type is the one of the GGUF
|
||||
if (decision_type == COMMON_DECISION_TYPE_LAYA || decision_type == COMMON_DECISION_TYPE_KEV || decision_type == COMMON_DECISION_TYPE_CLEF ||
|
||||
decision_type == COMMON_DECISION_TYPE_CLEF_OMNI ||
|
||||
decision_type == COMMON_DECISION_TYPE_LFM2_D1_OMNI || decision_type == COMMON_DECISION_TYPE_VLLM_DECISION2 ||
|
||||
decision_type == COMMON_DECISION_TYPE_MINICPM_OCR_JEV) {
|
||||
const auto pooling_type = decision_type == COMMON_DECISION_TYPE_MINICPM_OCR_JEV ? LLAMA_POOLING_TYPE_UNSPECIFIED : LLAMA_POOLING_TYPE_NONE;
|
||||
@@ -2336,11 +2338,11 @@ llama_batch_ext * common_batch::get_sub_batch(int32_t off, int32_t n) {
|
||||
if (t.state_row >= 0 && !llama_batch_ext_set_embd_state_row(res, idx, t.state_row)) {
|
||||
GGML_ABORT("%s: failed to set the state row of the entry at index %d\n", __func__, i);
|
||||
}
|
||||
if (t.decision_order != 0) {
|
||||
llama_batch_ext_set_decision_order(res, idx, (llama_decision_order) t.decision_order);
|
||||
if (t.span != 0 && !(llama_batch_ext_set_pool_span(res, idx, t.span) && llama_batch_ext_set_pool_span_type(res, t.span, (llama_pool_span_type) t.span_type))) {
|
||||
GGML_ABORT("%s: failed to set the span of the entry at index %d\n", __func__, i);
|
||||
}
|
||||
if (t.decision_group != 0 && !llama_batch_ext_set_decision_group(res, idx, t.decision_group)) {
|
||||
GGML_ABORT("%s: failed to set the decision group of the entry at index %d\n", __func__, i);
|
||||
if (t.attn_scope != 0 && !llama_batch_ext_set_attn_scope(res, idx, t.attn_scope)) {
|
||||
GGML_ABORT("%s: failed to set the attention scope of the entry at index %d\n", __func__, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -280,6 +280,7 @@ struct common_params_sampling {
|
||||
common_grammar grammar; // optional grammar constraint (user / output-format / tool-calls)
|
||||
bool grammar_lazy = false;
|
||||
std::vector<common_grammar_trigger> grammar_triggers; // optional triggers (for lazy grammars)
|
||||
std::string json_schema; // schema the output-format grammar was built from, applied through the chat template
|
||||
std::set<llama_token> preserved_tokens;
|
||||
|
||||
std::vector<llama_logit_bias> logit_bias; // logit biases to apply
|
||||
@@ -1001,6 +1002,7 @@ enum common_decision_type {
|
||||
COMMON_DECISION_TYPE_MINICPM_OCR_JEV, // one score per class, the pooled embeddings output of the last token
|
||||
COMMON_DECISION_TYPE_LFM3_D1, // same as lfm2-d1, non-causal, label codes A..Z then AA, AB..
|
||||
COMMON_DECISION_TYPE_LFM3_D1_OMNI, // same as lfm3-d1
|
||||
COMMON_DECISION_TYPE_CLEF_OMNI, // same as clef, with audio input and no video input
|
||||
COMMON_DECISION_TYPE_UNKNOWN, // a decision model of a type that is not supported
|
||||
};
|
||||
|
||||
@@ -1121,8 +1123,9 @@ struct common_batch {
|
||||
llama_embd embd; // non-owning view of the data passed to add_embd()/set_embd(), data == NULL if none
|
||||
llama_embd state; // non-owning view of the data passed to set_embd_state(), data == NULL if none
|
||||
std::vector<llama_seq_id> seq_ids_extra; // see add_seq()
|
||||
int32_t decision_order = 0; // see llama_batch_ext_set_decision_order()
|
||||
int32_t decision_group = 0; // see llama_batch_ext_set_decision_group()
|
||||
int32_t span = 0; // see llama_batch_ext_set_pool_span()
|
||||
int32_t span_type = 0; // see llama_batch_ext_set_pool_span_type()
|
||||
int32_t attn_scope = 0; // see llama_batch_ext_set_attn_scope()
|
||||
int32_t embd_row = -1; // see add_embd_row(), -1 if none
|
||||
int32_t state_row = -1; // see set_embd_state_row(), -1 if none
|
||||
};
|
||||
|
||||
+54
-10
@@ -216,14 +216,33 @@ static value exec_binary_op(context & ctx, const token & op, value left_val, val
|
||||
}
|
||||
return mk_val<value_float>(std::floor(a / b));
|
||||
} else if (op.value == "%") {
|
||||
double rem = std::fmod(a, b);
|
||||
JJ_DEBUG("Modulo operation: %f %% %f = %f", a, b, rem);
|
||||
bool is_float = is_val<value_float>(left_val) || is_val<value_float>(right_val);
|
||||
if (is_float) {
|
||||
return mk_val<value_float>(rem);
|
||||
} else {
|
||||
return mk_val<value_int>(float_to_int(rem));
|
||||
// python semantics: result has the sign of the divisor
|
||||
if (is_val<value_int>(left_val) && is_val<value_int>(right_val)) {
|
||||
const int64_t x = left_val->as_int();
|
||||
const int64_t y = right_val->as_int();
|
||||
if (y == 0) {
|
||||
throw std::runtime_error("integer modulo by zero");
|
||||
}
|
||||
if (y == -1) {
|
||||
// INT64_MIN % -1 is UB
|
||||
return mk_val<value_int>(0);
|
||||
}
|
||||
int64_t r = x % y;
|
||||
if (r != 0 && (r < 0) != (y < 0)) {
|
||||
r += y;
|
||||
}
|
||||
return mk_val<value_int>(r);
|
||||
}
|
||||
double rem = std::fmod(a, b);
|
||||
if (rem != 0) {
|
||||
if ((rem < 0) != (b < 0)) {
|
||||
rem += b;
|
||||
}
|
||||
} else {
|
||||
rem = std::copysign(0.0, b);
|
||||
}
|
||||
JJ_DEBUG("Modulo operation: %f %% %f = %f", a, b, rem);
|
||||
return mk_val<value_float>(rem);
|
||||
} else if (op.value == "<") {
|
||||
JJ_DEBUG("Comparison operation: %f < %f is %d", a, b, a < b);
|
||||
return mk_val<value_bool>(a < b);
|
||||
@@ -537,10 +556,25 @@ value for_statement::execute_impl(context & ctx) const {
|
||||
iterable_val = mk_val<value_array>();
|
||||
}
|
||||
|
||||
if (!is_val<value_array>(iterable_val) && !is_val<value_object>(iterable_val)) {
|
||||
if (!is_val<value_array>(iterable_val) && !is_val<value_object>(iterable_val) && !is_val<value_string>(iterable_val)) {
|
||||
throw std::runtime_error("Expected iterable or object type in for loop: got " + iterable_val->type());
|
||||
}
|
||||
|
||||
if (is_val<value_string>(iterable_val)) {
|
||||
// FIXME: byte-based iteration splits UTF-8 codepoints in multibyte strings
|
||||
// iterable_val is rebound below, so hold an explicit reference to the source
|
||||
const value str_owner = iterable_val;
|
||||
const auto * str_val = cast_val<value_string>(str_owner);
|
||||
std::vector<value> chars;
|
||||
chars.reserve(str_val->val_str.length());
|
||||
for (size_t i = 0; i < str_val->val_str.length(); ++i) {
|
||||
if (auto byte = str_val->val_str.byte_at(i)) {
|
||||
chars.push_back(mk_val<value_string>(std::string(1, *byte)));
|
||||
}
|
||||
}
|
||||
iterable_val = mk_val<value_array>(std::move(chars));
|
||||
}
|
||||
|
||||
std::vector<value> items;
|
||||
if (is_val<value_object>(iterable_val)) {
|
||||
JJ_DEBUG("%s", "For loop over object keys");
|
||||
@@ -951,8 +985,18 @@ value member_expression::execute_impl(context & ctx) const {
|
||||
val = arr->as_array().at(static_cast<size_t>(index));
|
||||
}
|
||||
} else { // value_string
|
||||
if (index >= 0) {
|
||||
const auto byte = cast_val<value_string>(object)->val_str.byte_at(static_cast<size_t>(index));
|
||||
// FIXME: byte-based indexing splits UTF-8 codepoints in multibyte strings
|
||||
const auto * str = cast_val<value_string>(object);
|
||||
const auto len = str->val_str.length();
|
||||
if (index < 0) {
|
||||
// Avoid negating INT64_MIN.
|
||||
const uint64_t distance = static_cast<uint64_t>(-(index + 1)) + 1;
|
||||
index = distance <= len
|
||||
? static_cast<int64_t>(len - distance)
|
||||
: -1;
|
||||
}
|
||||
if (index >= 0 && static_cast<uint64_t>(index) < len) {
|
||||
const auto byte = str->val_str.byte_at(static_cast<size_t>(index));
|
||||
if (byte) {
|
||||
val = mk_val<value_string>(std::string(1, *byte));
|
||||
}
|
||||
|
||||
+84
-33
@@ -1,5 +1,6 @@
|
||||
#include "jinja/string.h"
|
||||
#include "jinja/value.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
@@ -205,53 +206,103 @@ string string::titlecase() {
|
||||
return res;
|
||||
});
|
||||
}
|
||||
// mirrors Python str.isspace() (CPython Py_UNICODE_ISSPACE)
|
||||
static bool is_unicode_whitespace(uint32_t cp) {
|
||||
return (cp >= 0x0009 && cp <= 0x000D) ||
|
||||
(cp >= 0x001C && cp <= 0x0020) ||
|
||||
cp == 0x0085 ||
|
||||
cp == 0x00A0 ||
|
||||
cp == 0x1680 ||
|
||||
(cp >= 0x2000 && cp <= 0x200A) ||
|
||||
cp == 0x2028 ||
|
||||
cp == 0x2029 ||
|
||||
cp == 0x202F ||
|
||||
cp == 0x205F ||
|
||||
cp == 0x3000;
|
||||
}
|
||||
|
||||
static std::vector<uint32_t> decode_utf8_cpts(std::string_view s) {
|
||||
std::vector<uint32_t> cpts;
|
||||
size_t pos = 0;
|
||||
while (pos < s.size()) {
|
||||
auto parsed = common_parse_utf8_codepoint(s, pos);
|
||||
if (parsed.status == utf8_parse_result::SUCCESS) {
|
||||
cpts.push_back(parsed.codepoint);
|
||||
pos += parsed.bytes_consumed;
|
||||
} else {
|
||||
// skip invalid UTF-8 bytes so they never match non-strippable raw bytes in the input
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
return cpts;
|
||||
}
|
||||
|
||||
string string::strip(bool left, bool right, std::optional<const std::string_view> chars) {
|
||||
static auto strip_part = [](const std::string & s, bool left, bool right, std::optional<const std::string_view> chars) -> std::string {
|
||||
size_t start = 0;
|
||||
size_t end = s.length();
|
||||
auto match_char = [&chars](unsigned char c) -> bool {
|
||||
return chars ? (*chars).find(c) != std::string::npos : isspace(c);
|
||||
};
|
||||
if (left) {
|
||||
while (start < end && match_char(static_cast<unsigned char>(s[start]))) {
|
||||
++start;
|
||||
}
|
||||
}
|
||||
if (right) {
|
||||
while (end > start && match_char(static_cast<unsigned char>(s[end - 1]))) {
|
||||
--end;
|
||||
}
|
||||
}
|
||||
return s.substr(start, end - start);
|
||||
};
|
||||
if (parts.empty()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> char_cpts;
|
||||
if (chars) {
|
||||
char_cpts = decode_utf8_cpts(*chars);
|
||||
}
|
||||
|
||||
auto match_cp = [&](uint32_t cp) -> bool {
|
||||
if (chars) {
|
||||
return std::find(char_cpts.begin(), char_cpts.end(), cp) != char_cpts.end();
|
||||
}
|
||||
return is_unicode_whitespace(cp);
|
||||
};
|
||||
|
||||
const std::string full = str();
|
||||
size_t start = 0;
|
||||
size_t end = full.size();
|
||||
|
||||
if (left) {
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
parts[i].val = strip_part(parts[i].val, true, false, chars);
|
||||
if (parts[i].val.empty()) {
|
||||
// remove empty part
|
||||
parts.erase(parts.begin() + i);
|
||||
--i;
|
||||
continue;
|
||||
} else {
|
||||
while (start < end) {
|
||||
auto parsed = common_parse_utf8_codepoint(full, start);
|
||||
if (parsed.status != utf8_parse_result::SUCCESS || !match_cp(parsed.codepoint)) {
|
||||
break;
|
||||
}
|
||||
start += parsed.bytes_consumed;
|
||||
}
|
||||
}
|
||||
|
||||
if (right) {
|
||||
for (size_t i = parts.size(); i-- > 0;) {
|
||||
parts[i].val = strip_part(parts[i].val, false, true, chars);
|
||||
if (parts[i].val.empty()) {
|
||||
// remove empty part
|
||||
parts.erase(parts.begin() + i);
|
||||
continue;
|
||||
size_t new_end = start;
|
||||
size_t pos = start;
|
||||
while (pos < end) {
|
||||
auto parsed = common_parse_utf8_codepoint(full, pos);
|
||||
if (parsed.status != utf8_parse_result::SUCCESS) {
|
||||
pos += 1;
|
||||
new_end = pos;
|
||||
} else {
|
||||
break;
|
||||
pos += parsed.bytes_consumed;
|
||||
if (!match_cp(parsed.codepoint)) {
|
||||
new_end = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
end = new_end;
|
||||
}
|
||||
|
||||
std::vector<string_part> new_parts;
|
||||
size_t offset = 0;
|
||||
for (const auto & part : parts) {
|
||||
const size_t part_start = offset;
|
||||
const size_t part_end = offset + part.val.size();
|
||||
offset = part_end;
|
||||
|
||||
const size_t keep_start = std::max(part_start, start);
|
||||
const size_t keep_end = std::min(part_end, end);
|
||||
if (keep_start < keep_end) {
|
||||
new_parts.push_back({
|
||||
part.is_input,
|
||||
part.val.substr(keep_start - part_start, keep_end - keep_start)
|
||||
});
|
||||
}
|
||||
}
|
||||
parts = std::move(new_parts);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
+29
-27
@@ -739,6 +739,24 @@ static bool string_endswith(const std::string & str, const std::string & suffix)
|
||||
throw not_implemented_exception("String join builtin not implemented");
|
||||
}
|
||||
|
||||
static value string_strip_impl(const func_args & args, bool left, bool right) {
|
||||
args.ensure_kwargs({"chars"});
|
||||
args.ensure_count(1, 2);
|
||||
const std::string & name = args.func_name;
|
||||
value val_input = args.get_pos(0);
|
||||
if (!is_val<value_string>(val_input)) {
|
||||
throw raised_exception(name + "() first argument must be a string");
|
||||
}
|
||||
value val_chars = args.get_kwarg_or_pos("chars", 1);
|
||||
if (val_chars->is_undefined() || is_val<value_none>(val_chars)) {
|
||||
return mk_val<value_string>(val_input->as_string().strip(left, right));
|
||||
}
|
||||
if (!is_val<value_string>(val_chars)) {
|
||||
throw raised_exception(name + "() argument must be None or str");
|
||||
}
|
||||
return mk_val<value_string>(val_input->as_string().strip(left, right, val_chars->as_string().str()));
|
||||
}
|
||||
|
||||
const func_builtins & value_string_t::get_builtins() const {
|
||||
static const func_builtins builtins = {
|
||||
{"default", default_value},
|
||||
@@ -757,36 +775,13 @@ const func_builtins & value_string_t::get_builtins() const {
|
||||
return mk_val<value_string>(str);
|
||||
}},
|
||||
{"strip", [](const func_args & args) -> value {
|
||||
args.ensure_kwargs({"chars"});
|
||||
args.ensure_count(1, 2);
|
||||
value val_input = args.get_pos(0);
|
||||
if (!is_val<value_string>(val_input)) {
|
||||
throw raised_exception("strip() first argument must be a string");
|
||||
}
|
||||
value val_chars = args.get_kwarg_or_pos("chars", 1);
|
||||
if (val_chars->is_undefined()) {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(true, true));
|
||||
} else {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(true, true, val_chars->as_string().str()));
|
||||
}
|
||||
return string_strip_impl(args, true, true);
|
||||
}},
|
||||
{"rstrip", [](const func_args & args) -> value {
|
||||
args.ensure_vals<value_string>();
|
||||
value val_chars = args.get_kwarg_or_pos("chars", 1);
|
||||
if (val_chars->is_undefined()) {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(false, true));
|
||||
} else {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(false, true, val_chars->as_string().str()));
|
||||
}
|
||||
return string_strip_impl(args, false, true);
|
||||
}},
|
||||
{"lstrip", [](const func_args & args) -> value {
|
||||
args.ensure_vals<value_string>();
|
||||
value val_chars = args.get_kwarg_or_pos("chars", 1);
|
||||
if (val_chars->is_undefined()) {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(true, false));
|
||||
} else {
|
||||
return mk_val<value_string>(args.get_pos(0)->as_string().strip(true, false, val_chars->as_string().str()));
|
||||
}
|
||||
return string_strip_impl(args, true, false);
|
||||
}},
|
||||
{"title", [](const func_args & args) -> value {
|
||||
args.ensure_kwargs();
|
||||
@@ -883,7 +878,7 @@ const func_builtins & value_string_t::get_builtins() const {
|
||||
if (count > 0) {
|
||||
throw not_implemented_exception("String replace with count argument not implemented");
|
||||
}
|
||||
if (old_str != new_str) {
|
||||
if (count != 0 && old_str != new_str) {
|
||||
size_t pos = 0;
|
||||
if (old_str.empty()) {
|
||||
std::string new_res;
|
||||
@@ -1016,6 +1011,7 @@ const func_builtins & value_string_t::get_builtins() const {
|
||||
throw raised_exception("slice step cannot be zero");
|
||||
}
|
||||
auto input = args.get_pos(0);
|
||||
// FIXME: byte-based slicing splits UTF-8 codepoints in multibyte strings
|
||||
auto sliced = slice(input->as_string().str(), start, stop, step);
|
||||
auto res = mk_val<value_string>(sliced);
|
||||
res->val_str.mark_input_based_on(input->as_string());
|
||||
@@ -1571,6 +1567,12 @@ const func_builtins & value_undefined_t::get_builtins() const {
|
||||
return builtins;
|
||||
}
|
||||
|
||||
const func_builtins & value_func_t::get_builtins() const {
|
||||
// no attributes, so func.foo and func['foo'] are undefined
|
||||
static const func_builtins no_builtins = {};
|
||||
return no_builtins;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
|
||||
@@ -770,7 +770,9 @@ struct value_func_t : public value_t {
|
||||
return val_func(new_args);
|
||||
}
|
||||
virtual std::string type() const override { return "Function"; }
|
||||
virtual bool as_bool() const override { return true; } // like python, a function is truthy
|
||||
virtual std::string as_repr() const override { return type() + "<" + name + ">(" + (arg0 ? arg0->as_repr() : "") + ")"; }
|
||||
virtual const func_builtins & get_builtins() const override;
|
||||
virtual bool is_hashable() const override { return false; }
|
||||
virtual hasher unique_hash() const noexcept override {
|
||||
// Note: this is unused for now, we don't support function as object keys
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
using json = common_json;
|
||||
|
||||
static std::string build_repetition(const std::string & item_rule, int min_items, int max_items, const std::string & separator_rule = "") {
|
||||
if (min_items > max_items) {
|
||||
max_items = min_items;
|
||||
}
|
||||
auto has_max = max_items != std::numeric_limits<int>::max();
|
||||
|
||||
if (max_items == 0) {
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
#include "parsers.h"
|
||||
|
||||
// Normalize assistant history to content.blocks: the template rejects mixed string and block formats.
|
||||
static json apertus_1_5_adjust_messages(const json & messages) {
|
||||
json adjusted = json::array();
|
||||
|
||||
for (const auto & message : messages) {
|
||||
if (message.value("role", "") != "assistant") {
|
||||
adjusted.push_back(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
json blocks = json::array();
|
||||
|
||||
if (message.contains("reasoning_content") && message.at("reasoning_content").is_string()) {
|
||||
const auto reasoning = message.at("reasoning_content").get<std::string>();
|
||||
if (!reasoning.empty()) {
|
||||
blocks.push_back({
|
||||
{ "type", "thoughts" },
|
||||
{ "text", reasoning },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (message.contains("content") && message.at("content").is_string()) {
|
||||
const auto content = message.at("content").get<std::string>();
|
||||
if (!content.empty()) {
|
||||
blocks.push_back({
|
||||
{ "type", "response" },
|
||||
{ "text", content },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (message.contains("tool_calls") && message.at("tool_calls").is_array() &&
|
||||
!message.at("tool_calls").empty()) {
|
||||
blocks.push_back({
|
||||
{ "type", "tool_calls" },
|
||||
{ "calls", message.at("tool_calls") },
|
||||
});
|
||||
}
|
||||
|
||||
json converted = message;
|
||||
converted["content"] = {
|
||||
{ "blocks", std::move(blocks) },
|
||||
};
|
||||
converted.erase("reasoning_content");
|
||||
converted.erase("tool_calls");
|
||||
adjusted.push_back(std::move(converted));
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
// Apertus 1.5 format:
|
||||
// - reasoning: <|inner_prefix|>{reasoning}<|inner_suffix|>
|
||||
// - tool calls: <|tools_prefix|>[{"function_name": { ... }}]<|tools_suffix|>
|
||||
common_chat_params common_chat_params_init_apertus_1_5(
|
||||
const common_chat_template & tmpl,
|
||||
const autoparser::generation_params & inputs) {
|
||||
static const std::string ASSISTANT_START = "<|assistant_start|>";
|
||||
static const std::string INNER_START = "<|inner_prefix|>";
|
||||
static const std::string INNER_END = "<|inner_suffix|>";
|
||||
static const std::string TOOLS_START = "<|tools_prefix|>";
|
||||
static const std::string TOOLS_END = "<|tools_suffix|>";
|
||||
|
||||
common_chat_params data;
|
||||
|
||||
auto adjusted_messages = apertus_1_5_adjust_messages(inputs.messages);
|
||||
data.prompt = common_chat_template_direct_apply_impl(tmpl, inputs, adjusted_messages);
|
||||
data.generation_prompt = common_chat_template_generation_prompt_impl(tmpl, inputs, adjusted_messages);
|
||||
data.format = COMMON_CHAT_FORMAT_PEG_NATIVE;
|
||||
data.supports_thinking = true;
|
||||
data.thinking_start_tag = INNER_START;
|
||||
data.thinking_end_tags = {INNER_END};
|
||||
data.preserved_tokens = {
|
||||
INNER_START,
|
||||
INNER_END,
|
||||
TOOLS_START,
|
||||
TOOLS_END,
|
||||
};
|
||||
data.message_delimiters = {
|
||||
{ COMMON_CHAT_ROLE_ASSISTANT, ASSISTANT_START },
|
||||
{ COMMON_CHAT_ROLE_TOOL, "<|tool_output_start|>" },
|
||||
{ COMMON_CHAT_ROLE_USER, "<|user_start|>" },
|
||||
{ COMMON_CHAT_ROLE_SYSTEM, "<|system_start|>" },
|
||||
};
|
||||
|
||||
if (inputs.has_continuation()) {
|
||||
const auto & message = inputs.continue_msg;
|
||||
|
||||
data.generation_prompt = ASSISTANT_START;
|
||||
if (!message.reasoning_content.empty()) {
|
||||
data.generation_prompt += INNER_START + message.reasoning_content;
|
||||
if (inputs.continue_final_message == COMMON_CHAT_CONTINUATION_CONTENT) {
|
||||
data.generation_prompt += INNER_END;
|
||||
}
|
||||
}
|
||||
if (inputs.continue_final_message == COMMON_CHAT_CONTINUATION_CONTENT) {
|
||||
data.generation_prompt += message.render_content();
|
||||
}
|
||||
|
||||
data.prompt.append(data.generation_prompt);
|
||||
}
|
||||
|
||||
const bool has_tools = inputs.tools.is_array() && !inputs.tools.empty() &&
|
||||
inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE;
|
||||
const bool has_response_format = inputs.json_schema.is_object() && !inputs.json_schema.empty();
|
||||
const bool extract_reasoning = inputs.reasoning_format != COMMON_REASONING_FORMAT_NONE;
|
||||
const bool include_grammar = has_response_format || has_tools;
|
||||
|
||||
data.parser = build_chat_peg_parser([&](common_chat_peg_builder & p) {
|
||||
auto generation_prompt = p.literal(ASSISTANT_START);
|
||||
auto end = p.end();
|
||||
|
||||
auto reasoning = p.eps();
|
||||
if (extract_reasoning) {
|
||||
reasoning = p.optional(
|
||||
p.literal(INNER_START) + p.reasoning(p.until(INNER_END)) + p.literal(INNER_END));
|
||||
}
|
||||
|
||||
if (has_response_format) {
|
||||
return generation_prompt + reasoning +
|
||||
p.content(p.schema(p.json(), "response-format-schema", inputs.json_schema)) + end;
|
||||
}
|
||||
|
||||
if (!has_tools) {
|
||||
return generation_prompt + reasoning + p.content(p.rest()) + end;
|
||||
}
|
||||
|
||||
auto tool_choice = p.choice();
|
||||
foreach_function(inputs.tools, [&](size_t, const json & tool) {
|
||||
const auto & function = tool.at("function");
|
||||
const auto name = function.at("name").get<std::string>();
|
||||
// Do not emit a prefix name before the complete JSON key arrives.
|
||||
auto key = p.atomic(p.tool_open(p.literal("{")) + p.space() + p.literal("\"") +
|
||||
p.tool_name(p.literal(name)) + p.literal("\"") + p.space() + p.literal(":"));
|
||||
tool_choice |= p.rule("tool-" + name, p.tool(key + p.space() +
|
||||
p.tool_args(p.schema(p.json(), "tool-" + name + "-schema", common_chat_tool_parameters(function))) +
|
||||
p.space() + p.tool_close(p.literal("}"))));
|
||||
});
|
||||
auto tool_calls = tool_choice;
|
||||
if (inputs.parallel_tool_calls) {
|
||||
tool_calls += p.zero_or_more(p.space() + p.literal(",") + p.space() + tool_choice);
|
||||
}
|
||||
// Allow the EOG token once the tool-call JSON is complete.
|
||||
auto suffix = p.optional(p.literal(TOOLS_END));
|
||||
auto tool_section = p.trigger_rule("tool-call", p.literal(TOOLS_START) + p.space() +
|
||||
p.literal("[") + p.space() + tool_calls + p.space() + p.literal("]") + p.space() + suffix);
|
||||
|
||||
auto content_before = p.content(p.until(TOOLS_START));
|
||||
auto content_after = p.content(p.rest());
|
||||
auto tools = inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_REQUIRED ? tool_section : p.optional(tool_section);
|
||||
return generation_prompt + reasoning + content_before + tools + content_after + end;
|
||||
});
|
||||
|
||||
if (include_grammar) {
|
||||
data.grammar_lazy = !(has_response_format || inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_REQUIRED);
|
||||
data.grammar = build_grammar([&](const common_grammar_builder & builder) {
|
||||
data.parser.build_grammar(builder, data.grammar_lazy);
|
||||
});
|
||||
|
||||
if (has_tools && data.grammar_lazy) {
|
||||
data.grammar_triggers = {
|
||||
{ COMMON_GRAMMAR_TRIGGER_TYPE_WORD, TOOLS_START },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -71,6 +71,10 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
|
||||
auto extract_reasoning = inputs.reasoning_format != COMMON_REASONING_FORMAT_NONE;
|
||||
auto include_grammar = has_response_format || (has_tools && inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE);
|
||||
|
||||
// A tool call may start before the thought is closed, the real closers stay first, the budget sampler forces them
|
||||
const auto think_closers = data.thinking_end_tags;
|
||||
data.thinking_end_tags.push_back(SECTION_START);
|
||||
|
||||
if (inputs.has_continuation()) {
|
||||
const auto & msg = inputs.continue_msg;
|
||||
|
||||
@@ -86,12 +90,13 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
|
||||
auto generation_prompt = p.literal(GEN_PREFIX);
|
||||
|
||||
auto think_end = p.choice();
|
||||
for (const auto & tag : data.thinking_end_tags) {
|
||||
for (const auto & tag : think_closers) {
|
||||
think_end |= p.literal(tag);
|
||||
}
|
||||
auto think_body = p.until_one_of(data.thinking_end_tags);
|
||||
auto think_block = [&](const common_peg_parser & body) {
|
||||
return p.optional(THINK_START + p.space() + p.through(body, think_end));
|
||||
// Peek only, because the tool call rule will consume <ifm|tool_calls>
|
||||
return p.optional(THINK_START + p.space() + body + (think_end | p.peek(p.literal(SECTION_START))));
|
||||
};
|
||||
auto reasoning = extract_reasoning ? think_block(p.reasoning(think_body)) : p.eps();
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ bool is_lfm2_template(const std::string & src);
|
||||
|
||||
bool is_inkling_template(const std::string & src);
|
||||
|
||||
common_chat_params common_chat_params_init_apertus_1_5(const common_chat_template & tmpl, const autoparser::generation_params & inputs);
|
||||
|
||||
common_chat_params common_chat_params_init_cohere2moe(const common_chat_template & tmpl, const autoparser::generation_params & inputs);
|
||||
|
||||
common_chat_params common_chat_params_init_deepseek_v3_2(const common_chat_template & tmpl, const autoparser::generation_params & inputs);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
set(LLAMA_CHAT_PARSERS_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/parsers.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/parsers.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/apertus.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/cohere2moe.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/deepseek.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/functionary-v3-2.cpp
|
||||
|
||||
@@ -22,7 +22,9 @@ TEXT_MODEL_MAP: dict[str, str] = {
|
||||
"LagunaForCausalLM": "laguna",
|
||||
"RicursiveForCausalLM": "ricursive",
|
||||
"FlintForCausalLM": "flint",
|
||||
"ApertusForCausalLM": "llama",
|
||||
"ApertusForCausalLM": "apertus",
|
||||
"Apertus1p5ForConditionalGeneration": "apertus",
|
||||
"Apertus1p5TextForCausalLM": "apertus",
|
||||
"ArceeForCausalLM": "llama",
|
||||
"ArcticForCausalLM": "arctic",
|
||||
"AudioFlamingo3ForConditionalGeneration": "qwen",
|
||||
@@ -48,6 +50,7 @@ TEXT_MODEL_MAP: dict[str, str] = {
|
||||
"ChatGLMModel": "chatglm",
|
||||
"ChatterboxModel": "chatterbox",
|
||||
"ClefModel": "clef",
|
||||
"ClefOmniModel": "clef",
|
||||
"CloverMoeModelLM": "clover",
|
||||
"CodeShellForCausalLM": "codeshell",
|
||||
"CogVLMForCausalLM": "cogvlm",
|
||||
@@ -215,6 +218,7 @@ TEXT_MODEL_MAP: dict[str, str] = {
|
||||
"MiMoV2FlashForCausalLM": "mimo",
|
||||
"MiMoV2ForCausalLM": "mimo",
|
||||
"MiniCPM3ForCausalLM": "minicpm",
|
||||
"MiniCPM5MoEForCausalLM": "minicpm",
|
||||
"MiniCPMForCausalLM": "minicpm",
|
||||
"MiniCPMV4_6ForConditionalGeneration": "minicpm",
|
||||
"MiniCPMV4_7ForConditionalGeneration": "minicpm",
|
||||
@@ -358,6 +362,7 @@ MMPROJ_MODEL_MAP: dict[str, str] = {
|
||||
"AudioFlamingo3ForConditionalGeneration": "ultravox",
|
||||
"ChatterboxModel": "chatterbox",
|
||||
"ClefModel": "clef",
|
||||
"ClefOmniModel": "clef",
|
||||
"CogVLMForCausalLM": "cogvlm",
|
||||
"Cohere2VisionForConditionalGeneration": "command_r",
|
||||
"PplxDeciderModel": "pplx_decider",
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .base import ModelBase, gguf
|
||||
from .llama import LlamaModel
|
||||
|
||||
|
||||
@ModelBase.register("ApertusForCausalLM")
|
||||
@ModelBase.example("swiss-ai/Apertus-8B-Instruct-2509")
|
||||
class ApertusModel(LlamaModel):
|
||||
model_arch = gguf.MODEL_ARCH.APERTUS
|
||||
undo_permute = False
|
||||
|
||||
_alpha_n = {}
|
||||
_alpha_p = {}
|
||||
_beta = {}
|
||||
_eps = {}
|
||||
|
||||
def modify_tensors(self, data_torch, name, bid):
|
||||
# Handle xIELU activation parameters
|
||||
n_layers = self.hparams["num_hidden_layers"]
|
||||
if name.endswith(".act_fn.alpha_n"):
|
||||
self._alpha_n[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._alpha_n) == n_layers):
|
||||
self.gguf_writer.add_xielu_alpha_n([self._alpha_n[k] for k in sorted(self._alpha_n)])
|
||||
return
|
||||
if name.endswith(".act_fn.alpha_p"):
|
||||
self._alpha_p[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._alpha_p) == n_layers):
|
||||
self.gguf_writer.add_xielu_alpha_p([self._alpha_p[k] for k in sorted(self._alpha_p)])
|
||||
return
|
||||
if name.endswith(".act_fn.beta"):
|
||||
self._beta[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._beta) == n_layers):
|
||||
self.gguf_writer.add_xielu_beta([self._beta[k] for k in sorted(self._beta)])
|
||||
return
|
||||
if name.endswith(".act_fn.eps"):
|
||||
self._eps[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._eps) == n_layers):
|
||||
self.gguf_writer.add_xielu_eps([self._eps[k] for k in sorted(self._eps)])
|
||||
return
|
||||
|
||||
yield from super().modify_tensors(data_torch, name, bid)
|
||||
|
||||
|
||||
@ModelBase.register(
|
||||
"Apertus1p5ForConditionalGeneration",
|
||||
"Apertus1p5TextForCausalLM",
|
||||
)
|
||||
@ModelBase.example("swiss-ai/Apertus-v1.5-8B", "swiss-ai/Apertus-v1.5-70B")
|
||||
class Apertus1p5Model(ApertusModel):
|
||||
model_arch = gguf.MODEL_ARCH.APERTUS
|
||||
|
||||
def set_vocab(self):
|
||||
super().set_vocab()
|
||||
|
||||
with open(self.dir_model / "tokenizer.json", encoding="utf-8") as f:
|
||||
tokenizer_json = json.load(f)
|
||||
added_tokens = {token["content"]: token["id"] for token in tokenizer_json["added_tokens"]}
|
||||
|
||||
self.gguf_writer.add_eot_token_id(added_tokens["<|assistant_end|>"])
|
||||
self.gguf_writer.add_eom_token_id(added_tokens["<|tools_suffix|>"])
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
|
||||
n_vocab = self.hparams["vocab_size"]
|
||||
n_vocab_out = self.hparams.get("output_vocab_size")
|
||||
if n_vocab_out is None:
|
||||
n_vocab_out = n_vocab
|
||||
if type(n_vocab_out) is not int or not 0 < n_vocab_out <= n_vocab:
|
||||
raise ValueError(f"Invalid output vocabulary size {n_vocab_out} for input vocabulary size {n_vocab}")
|
||||
self.gguf_writer.add_vocab_size_out(n_vocab_out)
|
||||
@@ -719,6 +719,7 @@ class ModelBase:
|
||||
channel_scales: dict[str, tuple[Tensor, ...]] = {}
|
||||
weight_dtypes: dict[str, torch.dtype] = {}
|
||||
scaled_weights: set[str] = set()
|
||||
channel_scale_fallback: list[str] = []
|
||||
expert_pattern = re.compile(r"(\.[^.]*experts)\.(\d+)\.")
|
||||
scale_types = {
|
||||
gguf.MODEL_TENSOR.ATTN_Q, gguf.MODEL_TENSOR.ATTN_K, gguf.MODEL_TENSOR.ATTN_V,
|
||||
@@ -778,10 +779,14 @@ class ModelBase:
|
||||
transformed = self._transform_fp8_scale(weight_name, scale.reshape(-1, 1)) if weight.ndim == 2 else None
|
||||
if transformed is None or len(transformed) != len(new_names):
|
||||
self._fp8_e4m3_preserved.discard(weight_name)
|
||||
channel_scale_fallback.append(weight_name)
|
||||
continue
|
||||
channel_scales[weight_name] = transformed
|
||||
candidates[weight_name] = (scale_name, scale, new_names, weight.shape)
|
||||
|
||||
if channel_scale_fallback:
|
||||
logger.warning(f"{len(channel_scale_fallback)} FP8 weights will be dequantized, {type(self).__name__} cannot keep their per-channel scales (first: {channel_scale_fallback[0]})")
|
||||
|
||||
expert_groups: dict[str, list[str]] = {}
|
||||
for name in self.model_tensors:
|
||||
if (match := expert_pattern.search(name)) and name.endswith(".weight"):
|
||||
@@ -1066,6 +1071,7 @@ class ModelBase:
|
||||
gguf.MODEL_ARCH.QWEN35,
|
||||
gguf.MODEL_ARCH.QWEN35MOE,
|
||||
gguf.MODEL_ARCH.QWEN3NEXT,
|
||||
gguf.MODEL_ARCH.LFM3,
|
||||
}
|
||||
if self.model_arch not in _HADAMARD_ARCHS:
|
||||
raise ValueError(
|
||||
@@ -1080,6 +1086,7 @@ class ModelBase:
|
||||
r"|ffn_gate_exps|ffn_up_exps|ffn_down_exps|ffn_gate_up_exps"
|
||||
r"|ffn_gate_shexp|ffn_up_shexp|ffn_down_shexp"
|
||||
r"|ssm_out"
|
||||
r"|shortconv\.in_proj|shortconv\.out_proj"
|
||||
r")\.weight"
|
||||
)
|
||||
weight_names: list[str] = []
|
||||
|
||||
@@ -37,6 +37,23 @@ class BertModel(TextModel):
|
||||
if self.cls_out_labels:
|
||||
self.gguf_writer.add_classifier_output_labels([v for k, v in sorted(self.cls_out_labels.items())])
|
||||
|
||||
def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
|
||||
dense_dir = self.dir_model / "2_Dense"
|
||||
if not self.sentence_transformers_dense_modules or self.model_arch != gguf.MODEL_ARCH.BERT or not dense_dir.is_dir():
|
||||
return
|
||||
|
||||
from safetensors.torch import load_file
|
||||
|
||||
config = json.loads((dense_dir / "config.json").read_text(encoding="utf-8"))
|
||||
if config.get("bias") is not False or config.get("activation_function") not in (
|
||||
"torch.nn.Identity", "torch.nn.modules.linear.Identity",
|
||||
):
|
||||
raise NotImplementedError("BERT dense export requires a bias-free projection with identity activation")
|
||||
|
||||
weight = load_file(str(dense_dir / "model.safetensors"))["linear.weight"]
|
||||
self.gguf_writer.add_embedding_length_out(config["out_features"])
|
||||
yield self.format_tensor_name(gguf.MODEL_TENSOR.DENSE_2_OUT), weight
|
||||
|
||||
def set_vocab(self):
|
||||
tokens, toktypes, tokpre = self.get_vocab_base()
|
||||
self.vocab_size = len(tokens)
|
||||
|
||||
+53
-13
@@ -4,7 +4,7 @@ import json
|
||||
import math
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable, Iterator, TYPE_CHECKING
|
||||
from typing import Any, Callable, Iterable, Iterator, TYPE_CHECKING
|
||||
|
||||
import torch
|
||||
|
||||
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
||||
|
||||
from .base import ModelBase, gguf, logger
|
||||
from .qwen import Qwen3_5TextModel
|
||||
from .qwen3vl import Qwen3VLVisionModel
|
||||
from .qwen3vl import Qwen3OmniMmprojModel, Qwen3OmniMoeTextModel, Qwen3VLVisionModel
|
||||
|
||||
|
||||
def _is_clef_checkpoint(dir_model: Path) -> bool:
|
||||
@@ -24,16 +24,16 @@ def _is_clef_checkpoint(dir_model: Path) -> bool:
|
||||
def _load_clef_hparams(dir_model: Path) -> dict[str, Any]:
|
||||
logger.info("gguf: detected Clef checkpoint")
|
||||
hparams = ModelBase.load_hparams(dir_model, False, guess=False)
|
||||
hparams["architectures"] = ["ClefModel"]
|
||||
# clef-omni has the same head on the Qwen3-Omni thinker
|
||||
is_omni = "thinker_config" in hparams
|
||||
hparams["architectures"] = ["ClefOmniModel" if is_omni else "ClefModel"]
|
||||
with open(dir_model / "joint_head_config.json", encoding="utf-8") as f:
|
||||
hparams["decision"] = json.load(f)
|
||||
return hparams
|
||||
|
||||
|
||||
@ModelBase.register("ClefModel")
|
||||
class ClefModel(Qwen3_5TextModel):
|
||||
model_arch = gguf.MODEL_ARCH.CLEF
|
||||
no_mtp = True # the checkpoint has no MTP head
|
||||
class _ClefHeadMixin:
|
||||
# the joint schema head, on top of the text model of the class that uses this mixin
|
||||
|
||||
# prompt follows joint_schema_model.py of the model repo
|
||||
_SYSTEM_PROMPT = (
|
||||
@@ -42,6 +42,17 @@ class ClefModel(Qwen3_5TextModel):
|
||||
)
|
||||
# torch.nn.LayerNorm default, used by the head
|
||||
_HEAD_NORM_EPS = 1e-5
|
||||
# clef-omni puts a newline after each image, clef after all of them
|
||||
_NEWLINE_PER_IMAGE = False
|
||||
_DECISION_TYPE = gguf.DecisionType.CLEF
|
||||
|
||||
model_arch: gguf.MODEL_ARCH
|
||||
hparams: dict[str, Any]
|
||||
block_count: int
|
||||
gguf_writer: gguf.GGUFWriter
|
||||
dir_model: Path
|
||||
format_tensor_name: Callable[..., str]
|
||||
map_tensor_name: Callable[..., str]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -52,7 +63,7 @@ class ClefModel(Qwen3_5TextModel):
|
||||
self._scales: dict[str, float] = {}
|
||||
|
||||
def set_vocab(self):
|
||||
super().set_vocab()
|
||||
super().set_vocab() # ty: ignore[missing-attribute]
|
||||
self.gguf_writer.add_chat_template([{"name": "systemone", "template": self._systemone_template()}])
|
||||
|
||||
@classmethod
|
||||
@@ -75,9 +86,13 @@ class ClefModel(Qwen3_5TextModel):
|
||||
"{% endif %}"
|
||||
"{{ ({'option_id': o.key} if d is none else {'description': d, 'option_id': o.key}) | tojson(separators=[',', ':']) }}"
|
||||
)
|
||||
if cls._NEWLINE_PER_IMAGE:
|
||||
images = "{% for image in images %}{{ image }}" + text("\n") + "{% endfor %}"
|
||||
else:
|
||||
images = "{% for image in images %}{{ image }}{% endfor %}" + text("\n")
|
||||
return (
|
||||
text(f"<|im_start|>system\n{cls._SYSTEM_PROMPT}<|im_end|>\n<|im_start|>user\nSTATE:\n")
|
||||
+ "{% if images %}{{ sep }}{% for image in images %}{{ image }}{% endfor %}" + text("\n") + "{% endif %}"
|
||||
+ "{% if images %}{{ sep }}" + images + "{% endif %}"
|
||||
+ "{{ sep }}" + render("state")
|
||||
+ "{{ sep }}" + text("\n\nSCHEMA FIELDS:\n")
|
||||
+ "{% for q in questions %}"
|
||||
@@ -96,23 +111,23 @@ class ClefModel(Qwen3_5TextModel):
|
||||
)
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
super().set_gguf_parameters() # ty: ignore[missing-attribute]
|
||||
head = self.hparams["decision"]
|
||||
self.gguf_writer.add_decision_type(gguf.DecisionType.CLEF)
|
||||
self.gguf_writer.add_decision_type(self._DECISION_TYPE)
|
||||
self.gguf_writer.add_decision_routing_block_count(head["routing_layers"])
|
||||
self.gguf_writer.add_decision_block_count(head["layers"])
|
||||
self.gguf_writer.add_decision_head_count(head["heads"])
|
||||
self.gguf_writer.add_layer_norm_eps(self._HEAD_NORM_EPS)
|
||||
|
||||
def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
|
||||
yield from super().get_tensors()
|
||||
yield from super().get_tensors() # ty: ignore[missing-attribute]
|
||||
from safetensors.torch import load_file
|
||||
for name, data in load_file(self.dir_model / "joint_head.safetensors").items():
|
||||
yield "joint_head." + name, data
|
||||
|
||||
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
|
||||
if not name.startswith("joint_head."):
|
||||
yield from super().modify_tensors(data_torch, name, bid)
|
||||
yield from super().modify_tensors(data_torch, name, bid) # ty: ignore[missing-attribute]
|
||||
return
|
||||
|
||||
parts = name.split(".")
|
||||
@@ -145,6 +160,31 @@ class ClefModel(Qwen3_5TextModel):
|
||||
yield self.map_tensor_name(name), data_torch
|
||||
|
||||
|
||||
@ModelBase.register("ClefModel")
|
||||
class ClefModel(_ClefHeadMixin, Qwen3_5TextModel):
|
||||
model_arch = gguf.MODEL_ARCH.CLEF
|
||||
no_mtp = True # the checkpoint has no MTP head
|
||||
|
||||
|
||||
@ModelBase.register("ClefModel")
|
||||
class ClefVisionModel(Qwen3VLVisionModel):
|
||||
pass
|
||||
|
||||
|
||||
@ModelBase.register("ClefOmniModel")
|
||||
class ClefOmniModel(_ClefHeadMixin, Qwen3OmniMoeTextModel):
|
||||
model_arch = gguf.MODEL_ARCH.CLEF_OMNI
|
||||
_NEWLINE_PER_IMAGE = True
|
||||
_DECISION_TYPE = gguf.DecisionType.CLEF_OMNI
|
||||
|
||||
|
||||
@ModelBase.register("ClefOmniModel")
|
||||
class ClefOmniMmprojModel(Qwen3OmniMmprojModel):
|
||||
# IMAGE_SIZE of joint_schema_model.py, the image budget is set there and not in the processor config
|
||||
_IMAGE_MIN_PIXELS = 65_536
|
||||
_IMAGE_MAX_PIXELS = 1_048_576
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
self.gguf_writer.add_vision_min_pixels(self._IMAGE_MIN_PIXELS)
|
||||
self.gguf_writer.add_vision_max_pixels(self._IMAGE_MAX_PIXELS)
|
||||
|
||||
+11
-15
@@ -62,23 +62,19 @@ class GptOssModel(TextModel):
|
||||
self.gguf_writer.add_tensor(new_name, new_data, raw_dtype=gguf.GGMLQuantizationType.MXFP4)
|
||||
|
||||
def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
|
||||
blocks0: Tensor = torch.zeros(1)
|
||||
blocks1: Tensor = torch.zeros(1)
|
||||
# we assume that tensors are loaded in the correct order
|
||||
for name, data_torch in self.get_tensors():
|
||||
if "mlp.experts.down_proj_blocks" in name:
|
||||
blocks0 = data_torch
|
||||
elif "mlp.experts.down_proj_scales" in name:
|
||||
new_name = self.map_tensor_name(name.replace("_scales", ".weight"))
|
||||
self.repack_mxfp4(new_name, blocks0, data_torch)
|
||||
elif "mlp.experts.gate_up_proj_blocks" in name:
|
||||
blocks0, blocks1 = data_torch[:, ::2, :, :], data_torch[:, 1::2, :, :]
|
||||
elif "mlp.experts.gate_up_proj_scales" in name:
|
||||
scales0, scales1 = data_torch[:, ::2, :], data_torch[:, 1::2, :]
|
||||
for name, get_scales in self.model_tensors.items():
|
||||
if not name.endswith(("mlp.experts.down_proj_scales", "mlp.experts.gate_up_proj_scales")):
|
||||
continue
|
||||
proj = name.removesuffix("_scales")
|
||||
blocks = self.model_tensors[proj + "_blocks"]()
|
||||
scales = get_scales()
|
||||
if proj.endswith("down_proj"):
|
||||
self.repack_mxfp4(self.map_tensor_name(proj + ".weight"), blocks, scales)
|
||||
else:
|
||||
new_name_gate = self.map_tensor_name(name.replace("gate_up_proj_scales", "gate_proj.weight"))
|
||||
new_name_up = self.map_tensor_name(name.replace("gate_up_proj_scales", "up_proj.weight"))
|
||||
self.repack_mxfp4(new_name_gate, blocks0, scales0)
|
||||
self.repack_mxfp4(new_name_up, blocks1, scales1)
|
||||
self.repack_mxfp4(new_name_gate, blocks[:, ::2, :, :], scales[:, ::2, :])
|
||||
self.repack_mxfp4(new_name_up, blocks[:, 1::2, :, :], scales[:, 1::2, :])
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -439,41 +439,3 @@ class LlamaEmbedNemotronModel(LlamaModel):
|
||||
@ModelBase.example("HuggingFaceTB/SmolLM3-3B")
|
||||
class SmolLM3Model(LlamaModel):
|
||||
model_arch = gguf.MODEL_ARCH.SMOLLM3
|
||||
|
||||
|
||||
@ModelBase.register("ApertusForCausalLM")
|
||||
@ModelBase.example("swiss-ai/Apertus-8B-Instruct-2509")
|
||||
class ApertusModel(LlamaModel):
|
||||
model_arch = gguf.MODEL_ARCH.APERTUS
|
||||
undo_permute = False
|
||||
|
||||
_alpha_n = {}
|
||||
_alpha_p = {}
|
||||
_beta = {}
|
||||
_eps = {}
|
||||
|
||||
def modify_tensors(self, data_torch, name, bid):
|
||||
# Handle xIELU activation parameters
|
||||
n_layers = self.hparams["num_hidden_layers"]
|
||||
if name.endswith(".act_fn.alpha_n"):
|
||||
self._alpha_n[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._alpha_n) == n_layers):
|
||||
self.gguf_writer.add_xielu_alpha_n([self._alpha_n[k] for k in sorted(self._alpha_n)])
|
||||
return
|
||||
if name.endswith(".act_fn.alpha_p"):
|
||||
self._alpha_p[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._alpha_p) == n_layers):
|
||||
self.gguf_writer.add_xielu_alpha_p([self._alpha_p[k] for k in sorted(self._alpha_p)])
|
||||
return
|
||||
if name.endswith(".act_fn.beta"):
|
||||
self._beta[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._beta) == n_layers):
|
||||
self.gguf_writer.add_xielu_beta([self._beta[k] for k in sorted(self._beta)])
|
||||
return
|
||||
if name.endswith(".act_fn.eps"):
|
||||
self._eps[bid] = data_torch.to("cpu").float().item()
|
||||
if (len(self._eps) == n_layers):
|
||||
self.gguf_writer.add_xielu_eps([self._eps[k] for k in sorted(self._eps)])
|
||||
return
|
||||
|
||||
yield from super().modify_tensors(data_torch, name, bid)
|
||||
|
||||
@@ -61,6 +61,56 @@ class MiniCPMModel(TextModel):
|
||||
yield from super().modify_tensors(data_torch, name, bid)
|
||||
|
||||
|
||||
@ModelBase.register("MiniCPM5MoEForCausalLM")
|
||||
class MiniCPM5MoEModel(TextModel):
|
||||
model_arch = gguf.MODEL_ARCH.MINICPM5_MOE
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not self.hparams.get("use_gated_attention", False):
|
||||
raise ValueError("MiniCPM5 MoE requires gated attention")
|
||||
self._experts: list[dict[str, Tensor]] = [{} for _ in range(self.block_count)]
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
self.gguf_writer.add_vocab_size(self.hparams["vocab_size"])
|
||||
head_dim = self.hparams.get("head_dim", self.hparams["hidden_size"] // self.hparams["num_attention_heads"])
|
||||
self.gguf_writer.add_rope_dimension_count(head_dim)
|
||||
self.gguf_writer.add_expert_feed_forward_length(self.hparams["moe_intermediate_size"])
|
||||
self.gguf_writer.add_expert_shared_count(self.hparams["n_shared_experts"])
|
||||
self.gguf_writer.add_leading_dense_block_count(self.hparams["first_k_dense_replace"])
|
||||
self.gguf_writer.add_expert_weights_norm(self.hparams.get("norm_topk_prob", True))
|
||||
self.gguf_writer.add_expert_weights_scale(self.hparams["routed_scaling_factor"])
|
||||
|
||||
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
|
||||
if name.endswith("self_attn.q_proj.weight"):
|
||||
n_head = self.hparams["num_attention_heads"]
|
||||
head_dim = self.hparams.get("head_dim", self.hparams["hidden_size"] // n_head)
|
||||
# Each HF head stores its query rows followed by its gate rows.
|
||||
query, gate = data_torch.reshape(n_head, 2 * head_dim, -1).chunk(2, dim=1)
|
||||
query = query.reshape(n_head * head_dim, -1)
|
||||
gate = gate.reshape(n_head * head_dim, -1)
|
||||
yield self.format_tensor_name(gguf.MODEL_TENSOR.ATTN_Q, bid), query
|
||||
yield self.format_tensor_name(gguf.MODEL_TENSOR.ATTN_GATE, bid), gate
|
||||
return
|
||||
|
||||
if ".mlp.experts." in name:
|
||||
n_experts = self.hparams["n_routed_experts"]
|
||||
assert bid is not None
|
||||
self._experts[bid][name] = data_torch
|
||||
if len(self._experts[bid]) == n_experts * 3:
|
||||
for projection in ("gate_proj", "up_proj", "down_proj"):
|
||||
tensors = [
|
||||
self._experts[bid].pop(f"model.layers.{bid}.mlp.experts.{eid}.{projection}.weight")
|
||||
for eid in range(n_experts)
|
||||
]
|
||||
merged = torch.stack(tensors, dim=0)
|
||||
yield from super().modify_tensors(merged, f"model.layers.{bid}.mlp.experts.{projection}.weight", bid)
|
||||
return
|
||||
|
||||
yield from super().modify_tensors(data_torch, name, bid)
|
||||
|
||||
|
||||
@ModelBase.register("MiniCPM3ForCausalLM")
|
||||
@ModelBase.example("openbmb/MiniCPM3-4B")
|
||||
class MiniCPM3Model(TextModel):
|
||||
|
||||
+9
-11
@@ -14,6 +14,13 @@ from .qwen import Qwen3Model, Qwen3MoeModel
|
||||
from .qwenvl import Qwen25AudioModel
|
||||
|
||||
|
||||
def _vision_config(hparams: dict[str, Any]) -> dict[str, Any]:
|
||||
# the vision config lives under thinker_config for omni models, at top level for plain VL
|
||||
if "thinker_config" in hparams:
|
||||
return hparams["thinker_config"].get("vision_config", {})
|
||||
return hparams.get("vision_config", {})
|
||||
|
||||
|
||||
@ModelBase.register("Qwen3VLForConditionalGeneration", "Qwen3VLMoeForConditionalGeneration", "Qwen3_5ForConditionalGeneration", "Qwen3_5MoeForConditionalGeneration", "OpenJevModel")
|
||||
@ModelBase.example("Qwen/Qwen3-VL-4B-Instruct", "Qwen/Qwen3-VL-30B-A3B-Instruct", "Qwen/Qwen3.5-9B", "Qwen/Qwen3.5-35B-A3B")
|
||||
class Qwen3VLVisionModel(MmprojModel):
|
||||
@@ -295,11 +302,7 @@ class Qwen3VLTextModel(Qwen3Model):
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
if "thinker_config" in self.hparams:
|
||||
vision_config = self.hparams["thinker_config"].get("vision_config", {})
|
||||
else:
|
||||
vision_config = self.hparams.get("vision_config", {})
|
||||
deepstack_layer_num = len(vision_config.get("deepstack_visual_indexes", []))
|
||||
deepstack_layer_num = len(_vision_config(self.hparams).get("deepstack_visual_indexes", []))
|
||||
self.gguf_writer.add_num_deepstack_layers(deepstack_layer_num)
|
||||
|
||||
@classmethod
|
||||
@@ -318,8 +321,7 @@ class Qwen3VLMoeTextModel(Qwen3MoeModel):
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
vision_config = self.hparams.get("vision_config", {})
|
||||
deepstack_layer_num = len(vision_config.get("deepstack_visual_indexes", []))
|
||||
deepstack_layer_num = len(_vision_config(self.hparams).get("deepstack_visual_indexes", []))
|
||||
self.gguf_writer.add_num_deepstack_layers(deepstack_layer_num)
|
||||
|
||||
@classmethod
|
||||
@@ -378,10 +380,6 @@ class Qwen3OmniMoeTextModel(Qwen3VLMoeTextModel):
|
||||
self.gguf_writer.add_eos_token_id(int(token_id))
|
||||
break
|
||||
|
||||
def set_gguf_parameters(self):
|
||||
super().set_gguf_parameters()
|
||||
self.gguf_writer.add_num_deepstack_layers(0)
|
||||
|
||||
|
||||
@ModelBase.register("Qwen3ASRForConditionalGeneration")
|
||||
@ModelBase.example("Qwen/Qwen3-ASR-0.6B-hf")
|
||||
|
||||
@@ -72,6 +72,8 @@ However, A6x GPUs in phones are likely not supported due to the outdated driver
|
||||
| MXFP4 | Support |
|
||||
| IQ4_NL | Support |
|
||||
|
||||
`MUL_MAT` supports F32 weight scales per tensor or per output channel. `MUL_MAT_ID` supports F32 weight scales per tensor, per expert, or per output channel of each expert.
|
||||
|
||||
`MUL_MAT_ID` accepts an expert id of `-1` and writes zeros to that slot. `ADD_ID` adds no bias for `-1`, including in fused MoE operations.
|
||||
|
||||
## Model Preparation
|
||||
|
||||
@@ -309,16 +309,25 @@ on 4 physical NPUs, or `--devices 'HTP0[0-1:0],HTP1[0-1:1]'` on 2 physical NPUs
|
||||
By default, the Hexagon backend is tuned for higher NPU throughput and lower memory bandwidth while preserving strong
|
||||
end-to-end accuracy across typical models. Specifically, batched matrix multiplications default to `W8A8` integer HMX
|
||||
(`--hex-mm-select 3`), which dynamically quantizes activations into 8-bit (`uint8` x `int8`) blocks with a 2048-element
|
||||
`K`-group scale (using HVX when `M <= 4`),
|
||||
and internal `FP32` activation tensors within each HTP subgraph are automatically lowered in-place to `FP16`
|
||||
(`--hex-oplower 1`). If a particular model or workload exhibits accuracy degradation (for example due to large activation
|
||||
outliers or `FP16` residual overflow), try stepping down to higher-precision configurations in the following order:
|
||||
`K`-group scale (using HVX when `M <= 4`), and internal `FP32` activation tensors within each HTP subgraph are automatically
|
||||
lowered in-place to `FP16` (`--hex-oplower 1`).
|
||||
|
||||
1. `--hex-mm-select 4 --hex-oplower 1`: pure `W8A8` INT HMX everywhere + internal `FP16` lowering (maximum prefill speed)
|
||||
2. `--hex-mm-select 3 --hex-oplower 1` (default): hybrid `W8A8` INT HMX (FP16 HMX on post-GLU / `GGML_PREC_F32` projections) + internal `FP16` lowering
|
||||
3. `--hex-mm-select 3 --hex-oplower 0`: hybrid `W8A8` INT HMX + `FP32` intermediate activations
|
||||
4. `--hex-mm-select 2 --hex-oplower 1`: `FP16` HMX everywhere + internal `FP16` lowering
|
||||
5. `--hex-mm-select 2 --hex-oplower 0`: `FP16` HMX everywhere + `FP32` intermediate activations
|
||||
If a particular model or workload exhibits accuracy degradation (for example due to large activation outliers or `FP16` residual overflow),
|
||||
try stepping down to higher-precision configurations in the following order:
|
||||
|
||||
| MMSEL | FWHT | OPLWR | Matmul | Intermediates | Notes |
|
||||
| :---: | :--: | :---: | --------------- | :-----------: | ----------------------------------------------------------------------------------- |
|
||||
| 3 | 0 | 1 | `W8A8` HMX | `FP16` | Default; maximum prefill speed |
|
||||
| 3 | 1 | 1 | `W8A8` HMX+FWHT | `FP16` | Higher accuracy on models with activation outliers |
|
||||
| 3 | 1 | 0 | `W8A8` HMX+FWHT | `FP32` | Avoids `FP16` activation/residual overflow while keeping `W8A8` HMX (higher DDR BW) |
|
||||
| 2 | - | 1 | `FP16` HMX | `FP16` | Higher matmul precision without `W8A8` quantization |
|
||||
| 2 | - | 0 | `FP16` HMX | `FP32` | Maximum HMX precision (`FP16` HMX + `FP32` intermediates) |
|
||||
|
||||
Notes:
|
||||
- `MMSEL`: `GGML_HEXAGON_MM_SELECT` (`--hex-mm-select` in `run.py`); see `GGML_HEXAGON_MM_SELECT` below for `W8A8` integer HMX mode details
|
||||
- `FWHT`: `GGML_HEXAGON_MM_FWHT` (`--hex-mm-fwht` in `run.py`)
|
||||
- `OPLWR`: `GGML_HEXAGON_OPLOWER` (`--hex-oplower` in `run.py`)
|
||||
- Under `MMSEL=3`, projections tagged with `GGML_PREC_F32` automatically use `FP16` HMX.
|
||||
|
||||
## Environment variables
|
||||
|
||||
@@ -369,14 +378,8 @@ outliers or `FP16` residual overflow), try stepping down to higher-precision con
|
||||
|
||||
Unknown values are logged as a warning and fall back to `burst`.
|
||||
|
||||
This must be set in the environment before the process initializes the backend registry, so
|
||||
there is no `llama-*` CLI flag for it. The `run.py` runner exposes it as `--hex-power-mode`.
|
||||
|
||||
Examples:
|
||||
|
||||
`GGML_HEXAGON_POWER_MODE=balanced llama-completion ...`
|
||||
`./scripts/snapdragon/run.py --hex-power-mode sustained_high_performance ...`
|
||||
|
||||
This must be set in the environment before the process initializes the backend registry.
|
||||
The `run.py` runner exposes it as `--hex-power-mode`.
|
||||
|
||||
- `GGML_HEXAGON_VERBOSE=1`
|
||||
Enables verbose logging of Ops from the backend. Example output:
|
||||
@@ -426,9 +429,16 @@ outliers or `FP16` residual overflow), try stepping down to higher-precision con
|
||||
|
||||
- `0`: Disabled (falls back to CPU or GPU)
|
||||
- `1`: HVX vector kernels only
|
||||
- `2`: FP16 HMX matrix engine (`M > 4`) with HVX decode (`M <= 4`)
|
||||
- `3`: Hybrid INT HMX `W8A8` (`uint8` activations x `int8` weights) with FP16 HMX fallback on post-GLU / `GGML_PREC_F32` projections and HVX decode (`M <= 4`) (default; automatically defaults to 2 on multi-session v73 hardware unless overridden)
|
||||
- `4`: Pure INT HMX `W8A8` everywhere (`M > 4`) with HVX decode (`M <= 4`)
|
||||
- `2`: `FP16` HMX matrix engine
|
||||
- `3`: `W8A8` integer HMX matrix engine (default)
|
||||
|
||||
All HMX modes fall back to HVX vector kernels for small batch sizes (`M <= 4`).
|
||||
|
||||
- `GGML_HEXAGON_MM_FWHT=0|1`
|
||||
Enables online block-32 Fast Walsh-Hadamard Transform (FWHT) rotation along `K` in `W8A8` HMX matmul (configurable via `--hex-mm-fwht` in `run.py`):
|
||||
|
||||
- `0`: Disabled (default)
|
||||
- `1`: Enabled - higher accuracy on models with activation outliers
|
||||
|
||||
- `GGML_HEXAGON_OPPOLL=N`
|
||||
Controls host polling while waiting for HTP opbatch completion (configurable via `--hex-oppoll` in `run.py`):
|
||||
@@ -437,4 +447,5 @@ outliers or `FP16` residual overflow), try stepping down to higher-precision con
|
||||
- `1`: Full polling (keeps the host CPU awake for minimum wakeup latency; best for peak benchmarking and profiling)
|
||||
- `> 1`: Hybrid polling budget in milliseconds - polls for up to `N` ms per opbatch before falling back to a blocking wait (default: `50` when supported by the FastRPC driver, `0` otherwise)
|
||||
|
||||
The default (`50`) is tuned for general performance and thermal/power balance (covers decode batches while letting the CPU sleep during longer prefills). For benchmarking, consider more aggressive settings like `10`-`20` or `1` for full polling.
|
||||
The default (`50`) is tuned for general performance and thermal/power balance (covers decode batches while letting the CPU sleep during longer prefills).
|
||||
For benchmarking, consider more aggressive settings like `10`-`20` or `1` for full polling.
|
||||
|
||||
@@ -119,6 +119,13 @@ columns `k = 0..31` are split into 8 groups `g = k / 4` of 4 consecutive columns
|
||||
- **Scales** (bytes 512..575): UE4M3 bytes, `tile[512 + 32*u + row]` for sub-block `u = 0..1` of the k-tile.
|
||||
- The per-tensor F32 scale is not part of the tile.
|
||||
|
||||
- **F8_E4M3** (1024 bytes per tile, `HTP_TENSOR_TILE_SIZE_F8_E4M3`, lossless tiling with same size as flat FP8):
|
||||
- **Values** (bytes 0..1023, 8 HVX vectors `p = 0..7`):
|
||||
Contains 32 rows x 32 columns of signed 8-bit E4M3 floating-point values (`S:1, E:4 bias 7, M:3`; `0x7F`/`0xFF` = NaN decoded as 0).
|
||||
Vector `p` holds column group `p` (`k = 4*p .. 4*p + 3`) in 4-K-grouped (`vrmpy`) byte order:
|
||||
`tile[p * 128 + row * 4 + j] = W[row][4*p + j]` for `row = 0..31`, `j = 0..3`.
|
||||
- Optional F32 weight scale (per-tensor, per-channel, or per-expert) is passed separately and folded in-kernel.
|
||||
|
||||
- **Q4_1** (640 bytes per tile, `HTP_TENSOR_TILE_SIZE_Q4_1`):
|
||||
- **Quants** (bytes 0..511, 512 bytes):
|
||||
Same 4-K-grouped nibble layout as `Q4_0`.
|
||||
|
||||
@@ -20,6 +20,7 @@ The following sections describe how to build with different backends and options
|
||||
* [CUDA](#cuda)
|
||||
* [MUSA](#musa)
|
||||
* [HIP](#hip)
|
||||
* [HRX](#hrx)
|
||||
* [Vulkan](#vulkan)
|
||||
* [CANN](#cann)
|
||||
* [ZenDNN](#zendnn)
|
||||
@@ -316,6 +317,8 @@ Currently supported values: `auto`, `q8`, `q4`.
|
||||
|
||||
NVFP4 and MXFP4 layers marked as W4A16 request 8-bit activations, so on Blackwell those layers run through the W4A8 path instead of the native W4A4 path. Set `q4` to keep the native W4A4 path for faster prompt processing at the cost of accuracy, or `q8` to use the W4A8 path for every layer, `auto` uses per-tensor prec metadata (this is the same behavior as when the environment variable is not set).
|
||||
|
||||
For dense NVFP4 layers with batches of up to 24 tokens on Blackwell GPUs with compute capability 12.x (RTX 50xx, RTX PRO Blackwell, DGX Spark), the few-row MMQ path uses W4A8 at every batch size, so that the precision of a decode batch does not depend on how many sequences or draft tokens it holds. With `q4` it uses W4A4 from 6 tokens (DGX Spark: 8 tokens). MoE experts and the dense layers that the few-row MMQ path does not support keep MMVQ (W4A8) up to 8 tokens and MMQ above.
|
||||
|
||||
### Unified Memory
|
||||
|
||||
The environment variable `GGML_CUDA_ENABLE_UNIFIED_MEMORY=1` can be used to enable unified memory in Linux. This allows swapping to system RAM instead of crashing when the GPU VRAM is exhausted. In Windows this setting is available in the NVIDIA control panel as `System Memory Fallback`.
|
||||
@@ -434,6 +437,39 @@ If your GPU is not officially supported you can use the environment variable [`H
|
||||
|
||||
On Linux it is possible to use unified memory architecture (UMA) to share main memory between the CPU and integrated GPU by setting environment variable `GGML_CUDA_ENABLE_UNIFIED_MEMORY=1`. However, this hurts performance for non-integrated GPUs (but enables working with integrated GPUs).
|
||||
|
||||
## HRX
|
||||
|
||||
This provides GPU acceleration on AMD RDNA3, RDNA3.5 and RDNA4 GPUs (gfx1100, gfx1101, gfx1102, gfx1103, gfx1150, gfx1151, gfx1152, gfx1200, gfx1201) through the HRX runtime. The backend is experimental. Kernels are written in Loom and compiled for the GPU at first use, so ROCm is not required.
|
||||
|
||||
Build and install the HRX SDK v0.2.0 from the [hrx-system release](https://github.com/ROCm/hrx-system/releases/tag/v0.2.0) source:
|
||||
|
||||
```bash
|
||||
curl -L https://github.com/ROCm/hrx-system/archive/refs/tags/v0.2.0.tar.gz | tar xz
|
||||
cd hrx-system-0.2.0
|
||||
python3 dev.py cmake setup
|
||||
source .venv/bin/activate
|
||||
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=OFF -DIREE_ENABLE_WERROR_FLAG=OFF \
|
||||
-DLIBHRX_BUILD=ON -DLIBHRX_BUILD_HIP_BINDING=OFF -DLIBHRX_BUILD_PASSTHROUGH=OFF -DLIBHRX_BUILD_CTS=OFF
|
||||
cmake --build build --target hrx hrx-info loomc_shared
|
||||
cmake --install build --prefix /path/to/hrx-sdk --component HrxPublicDist
|
||||
```
|
||||
|
||||
Then build llama.cpp with:
|
||||
|
||||
```bash
|
||||
cmake -B build -DGGML_HRX=ON -DCMAKE_PREFIX_PATH=/path/to/hrx-sdk
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
The devices are named `HRX0`, `HRX1`, ... Use `--list-devices` to show them and `--device HRX0` to select one.
|
||||
|
||||
This version of the backend targets TinyStories-15M (`stories15M-q4_0.gguf`, the model of the llama.cpp tests). It supports only these ops:
|
||||
|
||||
* `MUL_MAT` with Q4_0 weights and F32 activations
|
||||
* `SET_ROWS`, `CPY`, `DUP` and `CONT` (F32 to F32 or F16) and `FILL` (F32 and F16). llama.cpp runs these ops in place on the KV cache and the recurrent state in GPU memory. The CPU cannot run them there.
|
||||
|
||||
All other ops and types run on the CPU.
|
||||
|
||||
## Vulkan
|
||||
|
||||
### For Windows Users:
|
||||
|
||||
+126
-124
@@ -12,127 +12,129 @@ Legend:
|
||||
- 🟡 Partially supported by this backend
|
||||
- ❌ Not supported by this backend
|
||||
|
||||
| Operation | BLAS | CANN | CPU | CUDA | ET | HTP | MTL | OPENVINO | OpenCL | SYCL | Vulkan | WebGPU | ZenDNN | zDNN |
|
||||
|-----------|------|------|------|------|------|------|------|------|------|------|------|------|------|------|
|
||||
| ABS | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ACC | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ADD | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ADD1 | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| ADD_ID | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARANGE | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARGMAX | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARGSORT | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CEIL | ❌ | ❌ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CLAMP | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| COL2IM_1D | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONCAT | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONT | ❌ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONV_1D_DW | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| CONV_2D | ❌ | ❌ | 🟡 | ✅ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ❌ | ❌ |
|
||||
| CONV_2D_DW | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CONV_3D | ❌ | ❌ | ✅ | ✅ | ❌ | 🟡 | ✅ | 🟡 | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CONV_TRANSPOSE_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CONV_TRANSPOSE_2D | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| COS | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| COUNT_EQUAL | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CPY | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| CROSS_ENTROPY_LOSS | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CROSS_ENTROPY_LOSS_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CUMSUM | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DIAG | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DIV | ❌ | ✅ | ✅ | ✅ | ❌ | 🟡 | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DSV4_HC_COMB | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DSV4_HC_POST | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DSV4_HC_PRE | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DUP | ❌ | ✅ | ✅ | ✅ | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| EXP | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| EXPM1 | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| FILL | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| FLASH_ATTN_EXT | ❌ | 🟡 | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| FLOOR | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GATED_DELTA_NET | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GATED_LINEAR_ATTN | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| GEGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GEGLU_ERF | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GEGLU_QUICK | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU_ERF | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU_QUICK | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GET_ROWS | ❌ | 🟡 | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | ❌ | ❌ |
|
||||
| GET_ROWS_BACK | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ |
|
||||
| GROUP_NORM | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| HARDSIGMOID | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| HARDSWISH | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| IM2COL | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| IM2COL_3D | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| L2_NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| LEAKY_RELU | ❌ | ✅ | ✅ | ✅ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| LIGHTNING_INDEXER | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | ❌ | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| LOG | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| MEAN | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | 🟡 | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| MUL | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| MUL_MAT | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
|
||||
| MUL_MAT_HADAMARD | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | 🟡 |
|
||||
| MUL_MAT_ID | ❌ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | 🟡 | ❌ |
|
||||
| MUL_MAT_ID_W4A4 | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_ID_W4A8 | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_BF16 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_BF16_SRC0 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_F32 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_W4A4 | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_W4A8 | ❌ | ❌ | ✅ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| NEG | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| OPT_STEP_ADAMW | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| OPT_STEP_SGD | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| OUT_PROD | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ |
|
||||
| PAD | ❌ | 🟡 | ✅ | 🟡 | ❌ | ✅ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| PAD_REFLECT_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ |
|
||||
| POOL_1D | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| POOL_2D | ❌ | 🟡 | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| REGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| REPEAT | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| REPEAT_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| RMS_NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RMS_NORM_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ROLL | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ROPE | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ROPE_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ROUND | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RWKV_WKV6 | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| RWKV_WKV7 | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| SCALE | ❌ | 🟡 | ✅ | ✅ | ✅ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SET | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SET_ROWS | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| SGN | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SIGMOID | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SIGMOID_BACK | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SILU | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SILU_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
||||
| SIN | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SLEEP | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SOFTPLUS | ❌ | ❌ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SOFT_MAX | ❌ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SOFT_MAX_BACK | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | ✅ | ❌ | ❌ | ❌ |
|
||||
| SOLVE_TRI | ❌ | ❌ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ❌ | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SQR | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SQRT | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SSM_CONV | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SSM_SCAN | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | 🟡 | 🟡 | 🟡 | ✅ | ❌ | ❌ |
|
||||
| STEP | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SUB | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SUM | ❌ | 🟡 | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| SUM_ROWS | ❌ | ✅ | ✅ | 🟡 | ❌ | 🟡 | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SWIGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SWIGLU_CLAMP | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SWIGLU_OAI | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TANH | ❌ | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TIMESTEP_EMBEDDING | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TOP_K | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | 🟡 | ✅ | ❌ | ❌ |
|
||||
| TOP_K_MASK | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
||||
| TRI | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TRUNC | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| UPSCALE | ❌ | 🟡 | ✅ | ✅ | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| XIELU | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| Operation | BLAS | CANN | CPU | CUDA | ET | HRX | HTP | MTL | OPENVINO | OpenCL | SYCL | Vulkan | WebGPU | ZenDNN | zDNN |
|
||||
|-----------|------|------|------|------|------|------|------|------|------|------|------|------|------|------|------|
|
||||
| ABS | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ACC | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ADD | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ADD1 | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| ADD_ID | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARANGE | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARGMAX | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ARGSORT | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CEIL | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CLAMP | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| COL2IM_1D | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONCAT | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONT | ❌ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| CONV_1D_DW | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| CONV_2D | ❌ | ❌ | 🟡 | ✅ | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ❌ | ❌ |
|
||||
| CONV_2D_DW | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CONV_3D | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | 🟡 | ✅ | 🟡 | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CONV_TRANSPOSE_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CONV_TRANSPOSE_2D | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| COS | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| COUNT_EQUAL | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| CPY | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| CROSS_ENTROPY_LOSS | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CROSS_ENTROPY_LOSS_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| CUMSUM | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DIAG | ❌ | ❌ | ✅ | ✅ | 🟡 | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DIV | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | 🟡 | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| DSV4_HC_COMB | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DSV4_HC_POST | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DSV4_HC_PRE | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| DUP | ❌ | ✅ | ✅ | ✅ | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| EXP | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| EXPM1 | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| FILL | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| FLASH_ATTN_EXT | ❌ | 🟡 | ✅ | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| FLOOR | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GATED_DELTA_NET | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GATED_LINEAR_ATTN | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| GEGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GEGLU_ERF | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GEGLU_QUICK | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU_ERF | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GELU_QUICK | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| GET_ROWS | ❌ | 🟡 | ✅ | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | ❌ | ❌ |
|
||||
| GET_ROWS_BACK | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ |
|
||||
| GROUP_NORM | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| HARDSIGMOID | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| HARDSWISH | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| IM2COL | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| IM2COL_3D | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| L2_NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| LEAKY_RELU | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| LIGHTNING_INDEXER | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | ❌ | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| LOG | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| MEAN | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | 🟡 | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| MUL | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| MUL_MAT | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
|
||||
| MUL_MAT_HADAMARD | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | 🟡 |
|
||||
| MUL_MAT_ID | ❌ | 🟡 | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | 🟡 | 🟡 | ❌ |
|
||||
| MUL_MAT_ID_PREC_SRC1_BF16 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_ID_PREC_SRC1_F32 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_ID_W4A4 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_ID_W4A8 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_BF16 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_BF16_SRC0 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_PREC_SRC1_F32 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_W4A4 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| MUL_MAT_W4A8 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | 🟡 | ❌ | 🟡 | 🟡 | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| NEG | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| OPT_STEP_ADAMW | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| OPT_STEP_SGD | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| OUT_PROD | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ |
|
||||
| PAD | ❌ | 🟡 | ✅ | 🟡 | ❌ | ❌ | ✅ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| PAD_REFLECT_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ |
|
||||
| POOL_1D | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| POOL_2D | ❌ | 🟡 | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| REGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RELU | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| REPEAT | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | 🟡 | ❌ | ❌ |
|
||||
| REPEAT_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| RMS_NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RMS_NORM_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ROLL | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ROPE | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| ROPE_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| ROUND | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RWKV_WKV6 | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| RWKV_WKV7 | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| SCALE | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | 🟡 | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SET | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SET_ROWS | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| SGN | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SIGMOID | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SIGMOID_BACK | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SILU | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SILU_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
||||
| SIN | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SLEEP | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SOFTPLUS | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SOFT_MAX | ❌ | 🟡 | ✅ | ✅ | 🟡 | ❌ | 🟡 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SOFT_MAX_BACK | ❌ | ❌ | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | 🟡 | ✅ | ❌ | ❌ | ❌ |
|
||||
| SOLVE_TRI | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | ❌ | ✅ | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SQR | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SQRT | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SSM_CONV | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SSM_SCAN | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | 🟡 | 🟡 | 🟡 | ✅ | ❌ | ❌ |
|
||||
| STEP | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SUB | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SUM | ❌ | 🟡 | ✅ | 🟡 | ❌ | ❌ | 🟡 | 🟡 | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | ❌ | ❌ |
|
||||
| SUM_ROWS | ❌ | ✅ | ✅ | 🟡 | ❌ | ❌ | 🟡 | ✅ | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ❌ | ❌ |
|
||||
| SWIGLU | ❌ | ✅ | ✅ | ✅ | 🟡 | ❌ | 🟡 | 🟡 | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| SWIGLU_CLAMP | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| SWIGLU_OAI | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TANH | ❌ | ✅ | ✅ | 🟡 | 🟡 | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TIMESTEP_EMBEDDING | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TOP_K | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | 🟡 | ✅ | ❌ | ❌ |
|
||||
| TOP_K_MASK | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
||||
| TRI | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| TRUNC | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ❌ | ✅ | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| UPSCALE | ❌ | 🟡 | ✅ | ✅ | ❌ | ❌ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| XIELU | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
|
||||
+24215
File diff suppressed because it is too large
Load Diff
+16
-9
@@ -8979,10 +8979,14 @@
|
||||
"OpenCL","SCALE","type=bf16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=0,v=0","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=bf16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=1,v=0","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=bf16,ne=[100,10,10,10],scale=0.500000,bias=0.000000,inplace=0,v=0","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=0.000000,inplace=0,v=1","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=0,v=1","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=1,v=1","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=f16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=0,v=0","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=f16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=1,v=0","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=f16,ne=[100,10,10,10],scale=0.500000,bias=0.000000,inplace=0,v=0","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=0.000000,inplace=0,v=1","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=0,v=1","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=f32,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=1,v=1","support","1","yes","OpenCL"
|
||||
"OpenCL","SCALE","type=bf16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=1,v=1","support","0","no","OpenCL"
|
||||
"OpenCL","SCALE","type=f16,ne=[10,10,10,10],scale=2.000000,bias=1.000000,inplace=0,v=1","support","1","yes","OpenCL"
|
||||
"OpenCL","SILU_BACK","type=f32,ne=[64,5,4,3],eps=0.000001","support","0","no","OpenCL"
|
||||
"OpenCL","NORM","type=f32,ne=[64,5,4,3],v=0,eps=0.000000,noncontig_rows=0","support","1","yes","OpenCL"
|
||||
"OpenCL","RMS_NORM","type=f32,ne=[64,5,4,3],v=0,eps=0.000000,inplace=0","support","1","yes","OpenCL"
|
||||
@@ -14821,7 +14825,7 @@
|
||||
"OpenCL","ADD_ID","type_a=f32,type_b=f32,n_embd=129,n_experts=8,n_experts_used=4,n_token=129,skip=1","support","1","yes","OpenCL"
|
||||
"OpenCL","SQR","type=f16,ne=[10,5,4,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f16,ne=[10,3,3,2]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[10,5,4,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[10,5,4,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SIN","type=f16,ne=[10,2,2,2]","support","0","no","OpenCL"
|
||||
"OpenCL","COS","type=f16,ne=[10,2,2,2]","support","0","no","OpenCL"
|
||||
"OpenCL","CLAMP","type=f16,ne=[10,5,4,3],min=-0.500000,max=0.500000,v=0","support","0","no","OpenCL"
|
||||
@@ -14835,8 +14839,8 @@
|
||||
"OpenCL","SQR","type=f16,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f16,ne=[7,1,5,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f16,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[1024,1024,1,1]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[7,1,5,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f16,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","SIN","type=f16,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
"OpenCL","SIN","type=f16,ne=[1024,1024,1,1]","support","0","no","OpenCL"
|
||||
"OpenCL","COS","type=f16,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
@@ -14855,7 +14859,7 @@
|
||||
"OpenCL","TRUNC","type=f16,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQR","type=f32,ne=[10,5,4,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f32,ne=[10,3,3,2]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[10,5,4,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[10,5,4,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SIN","type=f32,ne=[10,2,2,2]","support","0","no","OpenCL"
|
||||
"OpenCL","COS","type=f32,ne=[10,2,2,2]","support","0","no","OpenCL"
|
||||
"OpenCL","CLAMP","type=f32,ne=[10,5,4,3],min=-0.500000,max=0.500000,v=0","support","1","yes","OpenCL"
|
||||
@@ -14869,8 +14873,11 @@
|
||||
"OpenCL","SQR","type=f32,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f32,ne=[7,1,5,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","SQRT","type=f32,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[1024,1024,1,1]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[7,1,5,3]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=f32,ne=[1024,1024,1,1]","support","1","yes","OpenCL"
|
||||
"OpenCL","LOG","type=bf16,ne=[10,5,4,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=bf16,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
"OpenCL","LOG","type=bf16,ne=[1024,1024,1,1]","support","0","no","OpenCL"
|
||||
"OpenCL","SIN","type=f32,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
"OpenCL","SIN","type=f32,ne=[1024,1024,1,1]","support","0","no","OpenCL"
|
||||
"OpenCL","COS","type=f32,ne=[7,1,5,3]","support","0","no","OpenCL"
|
||||
|
||||
|
Can't render this file because it is too large.
|
+118
-116
@@ -5502,122 +5502,124 @@
|
||||
"WebGPU: WebGPU","CONV_3D","N=2,IC=3,ID=18,IH=22,IW=20,OC=4,KD=3,KH=3,KW=3,s0=2,s1=2,s2=2,p0=1,p1=1,p2=1,d0=2,d1=2,d2=2,type_kernel=f16","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_3D","N=2,IC=3,ID=18,IH=22,IW=20,OC=4,KD=3,KH=1,KW=5,s0=2,s1=1,s2=1,p0=2,p1=0,p2=1,d0=1,d1=1,d2=2,type_kernel=f16","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_3D","N=1,IC=4,ID=8,IH=8,IW=8,OC=8,KD=1,KH=1,KW=1,s0=1,s1=1,s2=1,p0=0,p1=0,p2=0,d0=1,d1=1,d2=1,type_kernel=f16","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[197,32,1,1],ne_kernel=[16,32,32,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,1,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[197,32,1,1],ne_kernel=[16,32,32,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,1,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[33,32,1,1],ne_kernel=[20,24,32,1],s0=10,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[35,33,1,1],ne_kernel=[11,17,33,1],s0=5,p0=0,d0=1","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=16,OC=32,T_in=197,s0=8,p0=0,view=0","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=4,OC=3,T_in=7,s0=2,p0=0,view=0","support","1","yes","WebGPU"
|
||||
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=1,OC=5,T_in=13,s0=1,p0=0,view=0","support","1","yes","WebGPU"
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -217,6 +217,7 @@ option(GGML_HIP "ggml: use HIP"
|
||||
option(GGML_HIP_GRAPHS "ggml: use HIP graph" ON)
|
||||
option(GGML_HIP_RCCL "ggml: use ROCm Collective Comm. Library" OFF)
|
||||
option(GGML_HIP_NO_VMM "ggml: do not try to use HIP VMM" ON)
|
||||
option(GGML_HRX "ggml: use HRX (experimental)" OFF)
|
||||
option(GGML_HIP_MMQ_MFMA "ggml: enable MFMA MMA for CDNA in MMQ" ON)
|
||||
option(GGML_HIP_EXPORT_METRICS "ggml: enable kernel perf metrics output" OFF)
|
||||
option(GGML_MUSA_GRAPHS "ggml: use MUSA graph, experimental, unstable" OFF)
|
||||
|
||||
@@ -410,9 +410,9 @@ extern "C" {
|
||||
|
||||
GGML_BACKEND_SPLIT_AXIS_MIRRORED = 10, // all values on all backends
|
||||
GGML_BACKEND_SPLIT_AXIS_PARTIAL = 11, // each backend has a partial sum
|
||||
GGML_BACKEND_SPLIT_AXIS_NONE = 98, // the entire data is on a single device, effectively running without parallelization
|
||||
|
||||
// for internal bookkeeping only:
|
||||
GGML_BACKEND_SPLIT_AXIS_NONE = 98,
|
||||
GGML_BACKEND_SPLIT_AXIS_UNKNOWN = 99,
|
||||
};
|
||||
GGML_API const char * ggml_backend_meta_split_axis_name(enum ggml_backend_meta_split_axis split_axis);
|
||||
@@ -433,6 +433,11 @@ extern "C" {
|
||||
// that each need to be split individually across devices so that each device gets a slice of Q, K, and V,
|
||||
// the Q matrix can be larger than the K and V matrices so this can either be expressed as 3 segments or as 2 segments
|
||||
// where the segment for K/V repeats twice
|
||||
// for tensors with axis == MIRRORED || axis == PARTIAL || axis == NONE:
|
||||
// - n_segments == 1
|
||||
// - nr[0] == 1
|
||||
// for tensors with axis == NONE:
|
||||
// - ne[i] is nonzero if and only if the ith device holds the data
|
||||
int64_t ne[16*GGML_BACKEND_META_MAX_DEVICES];
|
||||
uint32_t nr[16];
|
||||
uint32_t n_segments;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "ggml-backend.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
#define GGML_HRX_NAME "HRX"
|
||||
|
||||
GGML_BACKEND_API ggml_backend_t ggml_backend_hrx_init(size_t device);
|
||||
GGML_BACKEND_API bool ggml_backend_is_hrx(ggml_backend_t backend);
|
||||
GGML_BACKEND_API int ggml_backend_hrx_get_device_count(void);
|
||||
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_hrx_buffer_type(size_t device);
|
||||
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_hrx_reg(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
+22
-8
@@ -2309,18 +2309,32 @@ extern "C" {
|
||||
struct ggml_tensor * a,
|
||||
int32_t n_kv_max);
|
||||
|
||||
GGML_API void ggml_flash_attn_ext_add_sinks(
|
||||
GGML_API void ggml_flash_attn_ext_set_sinks(
|
||||
struct ggml_tensor * a,
|
||||
struct ggml_tensor * sinks);
|
||||
|
||||
GGML_API bool ggml_flash_attn_ext_has_indexed_bias(const struct ggml_tensor * a);
|
||||
|
||||
// Add table[indices[key, query], head, query] to the mask, in F32.
|
||||
// Queries from all streams are flattened in stream order. Indices must be in [0, table->ne[0]).
|
||||
GGML_API void ggml_flash_attn_ext_add_indexed_bias(
|
||||
GGML_DEPRECATED(GGML_API void ggml_flash_attn_ext_add_sinks(
|
||||
struct ggml_tensor * a,
|
||||
struct ggml_tensor * table,
|
||||
struct ggml_tensor * indices);
|
||||
struct ggml_tensor * sinks),
|
||||
"use ggml_flash_attn_ext_set_sinks instead");
|
||||
|
||||
// Add bias[bias_idxs[key, query], head, query] to the mask, in F32.
|
||||
// The bias is added after the KQ scaling.
|
||||
// Queries from all streams are flattened in stream order. Indices must be in [0, bias->ne[0]).
|
||||
// If bias_idxs is NULL, bias is a dense K*Q bias with shape [n_kv, n_batch, n_head_kv, n_stream].
|
||||
GGML_API void ggml_flash_attn_ext_set_bias(
|
||||
struct ggml_tensor * a,
|
||||
struct ggml_tensor * bias,
|
||||
struct ggml_tensor * bias_idxs);
|
||||
|
||||
GGML_DEPRECATED(GGML_API bool ggml_flash_attn_ext_has_indexed_bias(const struct ggml_tensor * a),
|
||||
"use ggml_flash_attn_ext_bias_is_indexed instead");
|
||||
|
||||
GGML_DEPRECATED(GGML_API void ggml_flash_attn_ext_add_indexed_bias(
|
||||
struct ggml_tensor * a,
|
||||
struct ggml_tensor * bias,
|
||||
struct ggml_tensor * bias_idxs),
|
||||
"use ggml_flash_attn_ext_set_bias instead");
|
||||
|
||||
// TODO: needs to be adapted to ggml_flash_attn_ext
|
||||
GGML_API struct ggml_tensor * ggml_flash_attn_back(
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
// 7. The tensor data binary blob (optional, aligned).
|
||||
//
|
||||
// Strings are serialized as the string length (uint64_t) followed by the C string without the null terminator.
|
||||
// Keys and tensor names must not contain null bytes, string values can.
|
||||
// All enums are stored as int32_t.
|
||||
// All bool values are stored as int8_t.
|
||||
// If the special key "general.alignment" (uint32_t) is defined it is used for alignment,
|
||||
|
||||
@@ -601,6 +601,7 @@ ggml_add_backend(CANN)
|
||||
ggml_add_backend(CUDA)
|
||||
ggml_add_backend(ET)
|
||||
ggml_add_backend(HIP)
|
||||
ggml_add_backend(HRX)
|
||||
ggml_add_backend(METAL)
|
||||
ggml_add_backend(MUSA)
|
||||
ggml_add_backend(RPC)
|
||||
|
||||
+151
-19
@@ -153,7 +153,7 @@ static ggml_backend_buffer_type_t ggml_backend_meta_device_get_buffer_type(ggml_
|
||||
static ggml_backend_buffer_type_t ggml_backend_meta_device_get_host_buffer_type(ggml_backend_dev_t dev);
|
||||
|
||||
static bool ggml_backend_meta_device_supports_op(ggml_backend_dev_t dev, const ggml_tensor * op) {
|
||||
if (ggml_flash_attn_ext_has_indexed_bias(op)) {
|
||||
if (ggml_flash_attn_ext_has_bias(op)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -534,6 +534,14 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
|
||||
if (a.axis != b.axis) {
|
||||
return false;
|
||||
}
|
||||
if (a.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
if ((a.ne[j] == 0) != (b.ne[j] == 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
int64_t sum_a = 0;
|
||||
for (size_t s = 0; s < a.n_segments; s++) {
|
||||
@@ -551,21 +559,22 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
|
||||
};
|
||||
|
||||
auto handle_generic = [&](const std::vector<ggml_backend_meta_split_state> & src_ss, bool scalar_only) -> ggml_backend_meta_split_state {
|
||||
ggml_backend_meta_split_state ret = {GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1};
|
||||
ggml_backend_meta_split_state ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
|
||||
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
|
||||
continue;
|
||||
}
|
||||
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
// The first valid source sets the split state from the UNKNOWN default:
|
||||
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_UNKNOWN) {
|
||||
ret = src_ss[i];
|
||||
} else if (!split_states_equal(src_ss[i], ret)) {
|
||||
continue;
|
||||
}
|
||||
// If after the first source there is an inconsistency, restore the UNKNOWN default and terminate the loop:
|
||||
if (!split_states_equal(src_ss[i], ret)) {
|
||||
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
}
|
||||
if (scalar_only && ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
|
||||
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
}
|
||||
@@ -915,30 +924,89 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
|
||||
if (ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
|
||||
const int64_t granularity = ret.axis == GGML_BACKEND_SPLIT_AXIS_0 ? ggml_blck_size(tensor->type) : 1;
|
||||
int64_t ne_sum = 0;
|
||||
int64_t ne_dev[GGML_BACKEND_META_MAX_DEVICES] = {0};
|
||||
for (size_t s = 0; s < ret.n_segments; s++) {
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
GGML_ASSERT(ret.ne[s*n_bufs + j] % granularity == 0);
|
||||
ne_sum += ret.ne[s*n_bufs + j] * ret.nr[s];
|
||||
const int64_t ne_sj = ret.ne[s*n_bufs + j] * ret.nr[s];
|
||||
ne_sum += ne_sj;
|
||||
ne_dev[j] += ne_sj;
|
||||
}
|
||||
}
|
||||
GGML_ASSERT(ne_sum == tensor->ne[ret.axis]);
|
||||
} else if (ret.axis == GGML_BACKEND_SPLIT_AXIS_PARTIAL) {
|
||||
// override split state with NONE if all data is on the same device:
|
||||
if (n_bufs > 1) {
|
||||
size_t n_active_devs = 0;
|
||||
size_t j_single = 0;
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
if (ne_dev[j] > 0) {
|
||||
n_active_devs++;
|
||||
j_single = j;
|
||||
}
|
||||
}
|
||||
if (n_active_devs == 1) {
|
||||
ret.axis = GGML_BACKEND_SPLIT_AXIS_NONE;
|
||||
memset(ret.ne, 0, sizeof(ret.ne));
|
||||
ret.ne[j_single] = 1;
|
||||
ret.nr[0] = 1;
|
||||
ret.n_segments = 1;
|
||||
}
|
||||
}
|
||||
} else if (ret.axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED || ret.axis == GGML_BACKEND_SPLIT_AXIS_PARTIAL || ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
GGML_ASSERT(ret.n_segments == 1);
|
||||
GGML_ASSERT(ret.nr[0] == 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<ggml_backend_meta_split_state> src_ss(GGML_MAX_SRC, {GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1});
|
||||
std::vector<ggml_backend_meta_split_state> src_ss(GGML_MAX_SRC, {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1});
|
||||
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
|
||||
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
|
||||
src_ss[i] = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
continue;
|
||||
}
|
||||
src_ss[i] = ggml_backend_meta_get_split_state(stc, tensor->src[i], /*assume_sync =*/ true);
|
||||
GGML_ASSERT(src_ss[i].axis != GGML_BACKEND_SPLIT_AXIS_UNKNOWN);
|
||||
}
|
||||
|
||||
bool has_none_axis = false;
|
||||
bool all_axes_none_or_mirrored = true;
|
||||
ggml_backend_meta_split_state single_dev_ss = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
|
||||
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
|
||||
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
|
||||
continue;
|
||||
}
|
||||
if (src_ss[i].axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
if (!has_none_axis) {
|
||||
single_dev_ss = src_ss[i];
|
||||
has_none_axis = true;
|
||||
} else if (!split_states_equal(src_ss[i], single_dev_ss)) {
|
||||
all_axes_none_or_mirrored = false;
|
||||
break;
|
||||
}
|
||||
} else if (src_ss[i].axis != GGML_BACKEND_SPLIT_AXIS_MIRRORED) {
|
||||
all_axes_none_or_mirrored = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has_none_axis) {
|
||||
// if at least one NONE, then all other sources must be NONE with same dev or MIRRORED:
|
||||
GGML_ASSERT(all_axes_none_or_mirrored);
|
||||
if (tensor->op == GGML_OP_MUL_MAT || tensor->op == GGML_OP_MUL_MAT_ID) {
|
||||
// the synchronization pattern is to sync and restore MIRRORED after 2 matrix multiplications,
|
||||
// therefore if src1 is already NONE, then we should transition back to PARTIAL/MIRRORED
|
||||
if (src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_NONE && src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
return {assume_sync ? GGML_BACKEND_SPLIT_AXIS_MIRRORED : GGML_BACKEND_SPLIT_AXIS_PARTIAL, {0}, {1}, 1};
|
||||
}
|
||||
} else if (tensor->op == GGML_OP_CPY) {
|
||||
GGML_ASSERT(src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
|
||||
} else if (tensor->op == GGML_OP_SET_ROWS) {
|
||||
GGML_ASSERT(src_ss[2].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
|
||||
} else if (tensor->op == GGML_OP_SET || tensor->op == GGML_OP_ACC) {
|
||||
GGML_ASSERT(src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
|
||||
}
|
||||
return single_dev_ss;
|
||||
}
|
||||
|
||||
ggml_backend_meta_split_state split_state;
|
||||
switch (tensor->op) {
|
||||
case GGML_OP_NONE: {
|
||||
@@ -1238,7 +1306,6 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
|
||||
}
|
||||
|
||||
ggml_backend_meta_split_state ret = buf_ctx->split_state_cache[key].first;
|
||||
GGML_ASSERT(ret.axis != GGML_BACKEND_SPLIT_AXIS_NONE);
|
||||
#ifndef NDEBUG
|
||||
if (ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
|
||||
int64_t ne_ret = 0;
|
||||
@@ -1266,7 +1333,7 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(co
|
||||
GGML_ASSERT(ggml_backend_meta_is_host_view(tensor));
|
||||
|
||||
// the view is not allocated in the meta buffer, it is not split across the sub-devices
|
||||
return { GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1 };
|
||||
return { GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1 };
|
||||
}
|
||||
|
||||
ggml_backend_meta_buffer_context * buf_ctx = (ggml_backend_meta_buffer_context *) tensor->buffer->context;
|
||||
@@ -1288,12 +1355,6 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
|
||||
GGML_ASSERT(split_state.n_segments <= 16);
|
||||
|
||||
int split_dim = split_state.axis;
|
||||
int64_t ne[GGML_MAX_DIMS];
|
||||
size_t nb[GGML_MAX_DIMS];
|
||||
for (size_t k = 0; k < GGML_MAX_DIMS; k++) {
|
||||
ne[k] = tensor->ne[k];
|
||||
nb[k] = tensor->nb[k];
|
||||
}
|
||||
|
||||
std::vector<ggml_tensor *> simple_tensors;
|
||||
simple_tensors.reserve(n_simple_bufs);
|
||||
@@ -1301,6 +1362,13 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
|
||||
ggml_context * simple_ctx = stc.ctxs[j].get();
|
||||
ggml_backend_buffer_t simple_buf = buf_ctx->bufs[j].get();
|
||||
|
||||
int64_t ne[GGML_MAX_DIMS];
|
||||
size_t nb[GGML_MAX_DIMS];
|
||||
for (size_t k = 0; k < GGML_MAX_DIMS; k++) {
|
||||
ne[k] = tensor->ne[k];
|
||||
nb[k] = tensor->nb[k];
|
||||
}
|
||||
|
||||
if (split_dim >= 0 && split_dim < GGML_MAX_DIMS) {
|
||||
// TODO: the following assert fails for llama-parallel even though the results are correct:
|
||||
// GGML_ASSERT(ggml_is_contiguously_allocated(tensor));
|
||||
@@ -1313,6 +1381,11 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
|
||||
nb[i] = tensor->nb[i] * ne[split_dim]/tensor->ne[split_dim];
|
||||
}
|
||||
}
|
||||
} else if (split_dim == GGML_BACKEND_SPLIT_AXIS_NONE && split_state.ne[j] == 0) {
|
||||
for (int i = 0; i < GGML_MAX_DIMS; i++) {
|
||||
ne[i] = 0;
|
||||
nb[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ggml_tensor * t_ij = ggml_new_tensor(simple_ctx, tensor->type, GGML_MAX_DIMS, ne);
|
||||
@@ -1385,6 +1458,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
|
||||
simple_tensors.push_back(t_ij);
|
||||
}
|
||||
|
||||
if (split_state.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
for (size_t j = 0; j < n_simple_bufs; j++) {
|
||||
if (split_state.ne[j] == 0) {
|
||||
simple_tensors[j]->flags &= ~GGML_TENSOR_FLAG_COMPUTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If one of the sources has a zero-sized slice, disable the computation:
|
||||
for (int i = 0; i < GGML_MAX_SRC; i++) {
|
||||
if (tensor->src[i] == nullptr || !ggml_backend_buffer_is_meta(tensor->src[i]->buffer)) {
|
||||
@@ -1392,6 +1473,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
|
||||
}
|
||||
|
||||
const ggml_backend_meta_split_state split_state_src = ggml_backend_meta_get_split_state(tensor->src[i], /*assume_sync =*/ true);
|
||||
if (split_state_src.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
|
||||
for (size_t j = 0; j < n_simple_bufs; j++) {
|
||||
if (split_state_src.ne[j] == 0) {
|
||||
simple_tensors[j]->flags &= ~GGML_TENSOR_FLAG_COMPUTE;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (split_state_src.axis < 0 || split_state_src.axis >= GGML_MAX_DIMS) {
|
||||
continue;
|
||||
}
|
||||
@@ -1514,6 +1603,14 @@ static void ggml_backend_meta_buffer_memset_tensor(
|
||||
ggml_backend_tensor_memset(simple_tensor, value, offset, size);
|
||||
}
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_NONE: {
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
if (split_state.ne[j] != 0) {
|
||||
ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
|
||||
ggml_backend_tensor_memset(simple_tensor, value, offset, size);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
@@ -1615,6 +1712,14 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
|
||||
ggml_backend_tensor_set(simple_tensor, data, offset, size);
|
||||
}
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_NONE: {
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
if (split_state.ne[j] != 0) {
|
||||
ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
|
||||
ggml_backend_tensor_set(simple_tensor, data, offset, size);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_PARTIAL: {
|
||||
GGML_ASSERT(tensor->type == GGML_TYPE_F32);
|
||||
GGML_ASSERT(offset % sizeof(float) == 0);
|
||||
@@ -1742,6 +1847,15 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co
|
||||
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, 0);
|
||||
ggml_backend_tensor_get(simple_tensor, data, offset, size);
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_NONE: {
|
||||
for (size_t j = 0; j < n_bufs; j++) {
|
||||
if (split_state.ne[j] != 0) {
|
||||
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
|
||||
ggml_backend_tensor_get(simple_tensor, data, offset, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
@@ -2015,6 +2129,14 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens
|
||||
ggml_backend_meta_simple_backend(backend, j), ggml_backend_meta_buffer_simple_tensor(tensor, j), data, offset, size);
|
||||
}
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_NONE: {
|
||||
for (size_t j = 0; j < n_backends; j++) {
|
||||
if (split_state.ne[j] != 0) {
|
||||
ggml_backend_tensor_set_async(
|
||||
ggml_backend_meta_simple_backend(backend, j), ggml_backend_meta_buffer_simple_tensor(tensor, j), data, offset, size);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
@@ -2060,6 +2182,16 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm
|
||||
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, 0);
|
||||
ggml_backend_tensor_get_async(simple_backend, simple_tensor, data, offset, size);
|
||||
} break;
|
||||
case GGML_BACKEND_SPLIT_AXIS_NONE: {
|
||||
for (size_t j = 0; j < n_backends; j++) {
|
||||
if (split_state.ne[j] != 0) {
|
||||
ggml_backend_t simple_backend = ggml_backend_meta_simple_backend(backend, j);
|
||||
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
|
||||
ggml_backend_tensor_get_async(simple_backend, simple_tensor, data, offset, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#include "ggml-metal.h"
|
||||
#endif
|
||||
|
||||
#ifdef GGML_USE_HRX
|
||||
#include "ggml-hrx.h"
|
||||
#endif // GGML_USE_HRX
|
||||
|
||||
#ifdef GGML_USE_SYCL
|
||||
#include "ggml-sycl.h"
|
||||
#endif
|
||||
@@ -123,6 +127,9 @@ struct ggml_backend_registry {
|
||||
#ifdef GGML_USE_METAL
|
||||
register_backend(ggml_backend_metal_reg());
|
||||
#endif
|
||||
#ifdef GGML_USE_HRX
|
||||
register_backend(ggml_backend_hrx_reg());
|
||||
#endif // GGML_USE_HRX
|
||||
#ifdef GGML_USE_SYCL
|
||||
register_backend(ggml_backend_sycl_reg());
|
||||
#endif
|
||||
@@ -581,6 +588,7 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
|
||||
ggml_backend_load_best("cann", silent, dir_path);
|
||||
ggml_backend_load_best("cuda", silent, dir_path);
|
||||
ggml_backend_load_best("hip", silent, dir_path);
|
||||
ggml_backend_load_best("hrx", silent, dir_path);
|
||||
ggml_backend_load_best("metal", silent, dir_path);
|
||||
ggml_backend_load_best("rpc", silent, dir_path);
|
||||
ggml_backend_load_best("sycl", silent, dir_path);
|
||||
|
||||
@@ -2686,8 +2686,8 @@ static bool ggml_backend_cann_supports_op(ggml_backend_dev_t dev, const ggml_ten
|
||||
return true;
|
||||
case GGML_OP_FLASH_ATTN_EXT:
|
||||
{
|
||||
// K/V row lists and indexed bias are not supported
|
||||
if (op->src[5] != nullptr || ggml_flash_attn_ext_has_indexed_bias(op)) {
|
||||
// K/V row lists and bias are not supported
|
||||
if (op->src[5] != nullptr || ggml_flash_attn_ext_has_bias(op)) {
|
||||
return false;
|
||||
}
|
||||
#ifdef ASCEND_310P
|
||||
|
||||
@@ -73,15 +73,14 @@ void quantize_row_q8_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, i
|
||||
|
||||
y[i].d = GGML_CPU_FP32_TO_FP16(d);
|
||||
|
||||
for (int j = 0; j < 8; j++) {
|
||||
const float32x4_t v = vec_mul(srcv[j], vec_splats(id));
|
||||
for (int j = 0; j < 8; j += 4) {
|
||||
/* Uses non-default rounding for vec_signed or vec_round */
|
||||
const int32x4_t vi = vec_signed(__builtin_s390_vfisb(v, 4, 1));
|
||||
const int32x4_t vi0 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 0], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi1 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 1], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi2 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 2], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi3 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 3], vec_splats(id)), 4, 1));
|
||||
|
||||
y[i].qs[4*j + 0] = vec_extract(vi, 0);
|
||||
y[i].qs[4*j + 1] = vec_extract(vi, 1);
|
||||
y[i].qs[4*j + 2] = vec_extract(vi, 2);
|
||||
y[i].qs[4*j + 3] = vec_extract(vi, 3);
|
||||
vec_xst(vec_packs(vec_packs(vi0, vi1), vec_packs(vi2, vi3)), 0, y[i].qs + 4*j);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -121,17 +120,16 @@ void quantize_row_q8_1(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, i
|
||||
|
||||
int32x4_t acc = vec_splats(0);
|
||||
|
||||
for (int j = 0; j < 8; j++) {
|
||||
const float32x4_t v = vec_mul(srcv[j], vec_splats(id));
|
||||
for (int j = 0; j < 8; j += 4) {
|
||||
/* Uses non-default rounding for vec_signed or vec_round */
|
||||
const int32x4_t vi = vec_signed(__builtin_s390_vfisb(v, 4, 1));
|
||||
const int32x4_t vi0 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 0], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi1 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 1], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi2 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 2], vec_splats(id)), 4, 1));
|
||||
const int32x4_t vi3 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 3], vec_splats(id)), 4, 1));
|
||||
|
||||
y[i].qs[4*j + 0] = vec_extract(vi, 0);
|
||||
y[i].qs[4*j + 1] = vec_extract(vi, 1);
|
||||
y[i].qs[4*j + 2] = vec_extract(vi, 2);
|
||||
y[i].qs[4*j + 3] = vec_extract(vi, 3);
|
||||
vec_xst(vec_packs(vec_packs(vi0, vi1), vec_packs(vi2, vi3)), 0, y[i].qs + 4*j);
|
||||
|
||||
acc = vec_add(acc, vi);
|
||||
acc = vec_add(acc, vec_add(vec_add(vi0, vi1), vec_add(vi2, vi3)));
|
||||
}
|
||||
|
||||
y[i].s = GGML_CPU_FP32_TO_FP16(d * (acc[0] + acc[1] + acc[2] + acc[3]));
|
||||
@@ -248,14 +246,9 @@ void ggml_vec_dot_q4_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
|
||||
const int8x16_t v_yh = vec_xl(QK8_0/2, y[ib].qs);
|
||||
|
||||
const int16x8_t v_xylso = vec_mulo(v_xls, v_yl);
|
||||
const int16x8_t v_xyl = vec_meadd(v_xls, v_yl, v_xylso);
|
||||
const int16x8_t v_xyhso = vec_mulo(v_xhs, v_yh);
|
||||
const int16x8_t v_xyh = vec_meadd(v_xhs, v_yh, v_xyhso);
|
||||
const int16x8_t v_xy_ = ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xls, v_yl), v_xhs, v_yh);
|
||||
|
||||
int16x8_t v_xy_ = v_xyl + v_xyh; v_xy_ += vec_reve(v_xy_);
|
||||
|
||||
const float32x4_t v_xy = vec_float(vec_unpackh(v_xy_));
|
||||
const float32x4_t v_xy = vec_float(vec_paddl_s16(v_xy_));
|
||||
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x[ib].d) * GGML_CPU_FP16_TO_FP32(y[ib].d));
|
||||
|
||||
acc = vec_madd(v_xy, v_d, acc);
|
||||
@@ -298,9 +291,6 @@ void ggml_vec_dot_q4_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
|
||||
#pragma GCC unroll 4
|
||||
for (; ib < nb; ++ib) {
|
||||
__builtin_prefetch(x[ib].qs, 0, 1);
|
||||
__builtin_prefetch(y[ib].qs, 0, 1);
|
||||
|
||||
summs += GGML_CPU_FP16_TO_FP32(x[ib].m) * GGML_CPU_FP16_TO_FP32(y[ib].s);
|
||||
|
||||
const uint8x16_t v_x = vec_xl(0, x[ib].qs);
|
||||
@@ -310,8 +300,8 @@ void ggml_vec_dot_q4_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
|
||||
const int8x16_t v_yh = vec_xl(QK8_1/2, y[ib].qs);
|
||||
|
||||
const int32x4_t v_xy_ = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xl, v_yl), v_xh, v_yh);
|
||||
const float32x4_t v_xy = vec_float(v_xy_);
|
||||
const int16x8_t v_xy_ = ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xl, v_yl), v_xh, v_yh);
|
||||
const float32x4_t v_xy = vec_float(vec_paddl_s16(v_xy_));
|
||||
|
||||
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x[ib].d) * GGML_CPU_FP16_TO_FP32(y[ib].d));
|
||||
|
||||
@@ -379,8 +369,8 @@ void ggml_vec_dot_mxfp4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
|
||||
const int8x16_t v_y1l = vec_xl(0, y1->qs);
|
||||
const int8x16_t v_y1h = vec_xl(QK8_0/2, y1->qs);
|
||||
|
||||
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0l, v_y0l), v_x0h, v_y0h);
|
||||
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1l, v_y1l), v_x1h, v_y1h);
|
||||
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0l, v_y0l), v_x0h, v_y0h));
|
||||
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1l, v_y1l), v_x1h, v_y1h));
|
||||
|
||||
const float32x4_t v_xy0f = vec_float(v_xy0);
|
||||
const float32x4_t v_xy1f = vec_float(v_xy1);
|
||||
@@ -407,7 +397,7 @@ void ggml_vec_dot_mxfp4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
|
||||
const int8x16_t v_yl = vec_xl(0, y0->qs);
|
||||
const int8x16_t v_yh = vec_xl(QK8_0/2, y0->qs);
|
||||
|
||||
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xl, v_yl), v_xh, v_yh);
|
||||
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xl, v_yl), v_xh, v_yh));
|
||||
const float32x4_t v_xyf = vec_float(v_xy);
|
||||
|
||||
const float32x4_t v_d = vec_splats(GGML_E8M0_TO_FP32_HALF(x0->e) * GGML_CPU_FP16_TO_FP32(y0->d));
|
||||
@@ -502,8 +492,8 @@ void ggml_vec_dot_q5_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_y1l = vec_xl(0, (const int8_t *)y1->qs);
|
||||
const int8x16_t v_y1h = vec_xl(QK8_0/2, (const int8_t *)y1->qs);
|
||||
|
||||
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0lf, v_y0l), v_x0hf, v_y0h);
|
||||
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1lf, v_y1l), v_x1hf, v_y1h);
|
||||
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0lf, v_y0l), v_x0hf, v_y0h));
|
||||
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1lf, v_y1l), v_x1hf, v_y1h));
|
||||
|
||||
const float32x4_t v_xy0f = vec_float(v_xy0);
|
||||
const float32x4_t v_xy1f = vec_float(v_xy1);
|
||||
@@ -548,7 +538,7 @@ void ggml_vec_dot_q5_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_yl = vec_xl(0, (const int8_t *)y0->qs);
|
||||
const int8x16_t v_yh = vec_xl(QK8_0/2, (const int8_t *)y0->qs);
|
||||
|
||||
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xlf, v_yl), v_xhf, v_yh);
|
||||
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xlf, v_yl), v_xhf, v_yh));
|
||||
const float32x4_t v_xyf = vec_float(v_xy);
|
||||
|
||||
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d));
|
||||
@@ -653,8 +643,8 @@ void ggml_vec_dot_q5_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_y1l = vec_xl(0 , y1->qs);
|
||||
const int8x16_t v_y1h = vec_xl(QK8_1/2, y1->qs);
|
||||
|
||||
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0lf, v_y0l), v_x0hf, v_y0h);
|
||||
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1lf, v_y1l), v_x1hf, v_y1h);
|
||||
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0lf, v_y0l), v_x0hf, v_y0h));
|
||||
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1lf, v_y1l), v_x1hf, v_y1h));
|
||||
|
||||
const float32x4_t v_xy0f = vec_float(v_xy0);
|
||||
const float32x4_t v_xy1f = vec_float(v_xy1);
|
||||
@@ -701,7 +691,7 @@ void ggml_vec_dot_q5_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int8x16_t v_yl = vec_xl(0 , y0->qs);
|
||||
const int8x16_t v_yh = vec_xl(QK8_1/2, y0->qs);
|
||||
|
||||
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xlf, v_yl), v_xhf, v_yh);
|
||||
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xlf, v_yl), v_xhf, v_yh));
|
||||
const float32x4_t v_xyf = vec_float(v_xy);
|
||||
|
||||
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d));
|
||||
@@ -743,9 +733,6 @@ void ggml_vec_dot_q8_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
|
||||
#pragma GCC unroll 8
|
||||
for (; ib < nb; ++ib) {
|
||||
__builtin_prefetch(x[ib].qs, 0, 1);
|
||||
__builtin_prefetch(y[ib].qs, 0, 1);
|
||||
|
||||
const int8x16_t v_xl = vec_xl(0 , x[ib].qs);
|
||||
const int8x16_t v_xh = vec_xl(QK8_0/2, x[ib].qs);
|
||||
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
|
||||
@@ -791,7 +778,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
uint32_t aux[3];
|
||||
uint32_t utmp[4];
|
||||
|
||||
const int32x4_t v_z = vec_splat_s32(0);
|
||||
const int16x8_t v_z = vec_splat_s16(0);
|
||||
const uint8x16_t v_3m = vec_splat_u8(0x03);
|
||||
|
||||
const uint8x16_t v_0c = vec_splat_u8(1);
|
||||
@@ -817,7 +804,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
qhbits[0] = vec_xl(0 , x0h);
|
||||
qhbits[1] = vec_xl(16, x0h);
|
||||
|
||||
int32_t isum = 0;
|
||||
int32x4_t v_isum = vec_splat_s32(0);
|
||||
|
||||
memcpy(aux, x[i].scales, 12);
|
||||
utmp[3] = ((aux[1] >> 4) & kmask2) | (((aux[2] >> 6) & kmask1) << 4);
|
||||
@@ -825,11 +812,12 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
utmp[1] = (aux[1] & kmask2) | (((aux[2] >> 2) & kmask1) << 4);
|
||||
utmp[0] = (aux[0] & kmask2) | (((aux[2] >> 0) & kmask1) << 4);
|
||||
|
||||
int8_t * scale = (int8_t *)utmp;
|
||||
for (int j = 0; j < 16; ++j) scale[j] -= 32;
|
||||
const int8x16_t v_scale = vec_sub(vec_xl(0, (const int8_t *)utmp), vec_splats((int8_t)32));
|
||||
const int16x8_t v_scalel = vec_unpackh(v_scale);
|
||||
const int16x8_t v_scaleh = vec_unpackl(v_scale);
|
||||
|
||||
for (int j = 0; j < QK_K/128; ++j) {
|
||||
int32x4_t isum0, isum1, isum2, isum3;
|
||||
const int16x8_t v_scales = j == 0 ? v_scalel : v_scaleh;
|
||||
|
||||
q3b[0] = vec_xl(0 , x0l);
|
||||
q3b[1] = vec_xl(16, x0l);
|
||||
@@ -855,17 +843,10 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
q3bytes[2] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[0], 2), v_3m), (int8x16_t)q3h[2]);
|
||||
q3bytes[3] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[1], 2), v_3m), (int8x16_t)q3h[3]);
|
||||
|
||||
isum0 = ggml_vec_dot_s32(v_z, q3bytes[0], q8bytes[0]);
|
||||
isum1 = ggml_vec_dot_s32(v_z, q3bytes[1], q8bytes[1]);
|
||||
isum2 = ggml_vec_dot_s32(v_z, q3bytes[2], q8bytes[2]);
|
||||
isum3 = ggml_vec_dot_s32(v_z, q3bytes[3], q8bytes[3]);
|
||||
|
||||
isum += (isum0[0] + isum0[1] + isum0[2] + isum0[3]) * scale[0];
|
||||
isum += (isum1[0] + isum1[1] + isum1[2] + isum1[3]) * scale[1];
|
||||
isum += (isum2[0] + isum2[1] + isum2[2] + isum2[3]) * scale[2];
|
||||
isum += (isum3[0] + isum3[1] + isum3[2] + isum3[3]) * scale[3];
|
||||
|
||||
scale += 4;
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[0], q8bytes[0]), vec_splat(v_scales, 0)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[1], q8bytes[1]), vec_splat(v_scales, 1)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[2], q8bytes[2]), vec_splat(v_scales, 2)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[3], q8bytes[3]), vec_splat(v_scales, 3)));
|
||||
|
||||
q3h[0] = vec_andc(v_2c, qhbits[0]);
|
||||
q3h[1] = vec_andc(v_2c, qhbits[1]);
|
||||
@@ -877,17 +858,10 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
q3bytes[2] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[0], 6), v_3m), (int8x16_t)q3h[2]);
|
||||
q3bytes[3] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[1], 6), v_3m), (int8x16_t)q3h[3]);
|
||||
|
||||
isum0 = ggml_vec_dot_s32(v_z, q3bytes[0], q8bytes[4]);
|
||||
isum1 = ggml_vec_dot_s32(v_z, q3bytes[1], q8bytes[5]);
|
||||
isum2 = ggml_vec_dot_s32(v_z, q3bytes[2], q8bytes[6]);
|
||||
isum3 = ggml_vec_dot_s32(v_z, q3bytes[3], q8bytes[7]);
|
||||
|
||||
isum += vec_hsum_i32x4(isum0) * scale[0];
|
||||
isum += vec_hsum_i32x4(isum1) * scale[1];
|
||||
isum += vec_hsum_i32x4(isum2) * scale[2];
|
||||
isum += vec_hsum_i32x4(isum3) * scale[3];
|
||||
|
||||
scale += 4;
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[0], q8bytes[4]), vec_splat(v_scales, 4)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[1], q8bytes[5]), vec_splat(v_scales, 5)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[2], q8bytes[6]), vec_splat(v_scales, 6)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[3], q8bytes[7]), vec_splat(v_scales, 7)));
|
||||
|
||||
if (j == 0) {
|
||||
qhbits[0] = vec_sr(qhbits[0], 4);
|
||||
@@ -895,7 +869,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
}
|
||||
}
|
||||
|
||||
sum += d * isum;
|
||||
sum += d * vec_hsum_i32x4(v_isum);
|
||||
}
|
||||
|
||||
*s = sum;
|
||||
@@ -931,7 +905,7 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
|
||||
#if defined(__VXE__) || defined(__VXE2__)
|
||||
const uint8x16_t v_lm = vec_splat_u8(0x0F);
|
||||
const int32x4_t v_z = vec_splat_s32(0);
|
||||
const int16x8_t v_z = vec_splat_s16(0);
|
||||
|
||||
uint8x16_t v_x[2];
|
||||
int8x16_t v_xl[2];
|
||||
@@ -966,8 +940,7 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const uint8_t * GGML_RESTRICT x0 = x[i].qs;
|
||||
const int8_t * GGML_RESTRICT y0 = y[i].qs;
|
||||
|
||||
int32_t sumi1 = 0;
|
||||
int32_t sumi2 = 0;
|
||||
int32x4_t v_sumi = vec_splat_s32(0);
|
||||
|
||||
for (int j = 0; j < QK_K/64; ++j) {
|
||||
v_x[0] = vec_xl(0 , x0);
|
||||
@@ -981,8 +954,8 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
v_xl[0] = (int8x16_t)vec_and(v_x[0], v_lm);
|
||||
v_xl[1] = (int8x16_t)vec_and(v_x[1], v_lm);
|
||||
|
||||
const int32x4_t p1 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
|
||||
sumi1 += vec_hsum_i32x4(p1) * scales[2*j+0];
|
||||
const int16x8_t v_p1 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p1, vec_splats((int16_t)scales[2*j+0])));
|
||||
|
||||
v_y[0] = vec_xl(0 , y0);
|
||||
v_y[1] = vec_xl(16, y0);
|
||||
@@ -991,11 +964,11 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
v_xl[0] = (int8x16_t)vec_sr(v_x[0], 4);
|
||||
v_xl[1] = (int8x16_t)vec_sr(v_x[1], 4);
|
||||
|
||||
const int32x4_t p2 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
|
||||
sumi2 += vec_hsum_i32x4(p2) * scales[2*j+1];
|
||||
const int16x8_t v_p2 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p2, vec_splats((int16_t)scales[2*j+1])));
|
||||
}
|
||||
|
||||
sumf += d * (sumi1 + sumi2);
|
||||
sumf += d * vec_hsum_i32x4(v_sumi);
|
||||
}
|
||||
|
||||
*s = sumf;
|
||||
@@ -1036,7 +1009,7 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const uint8x16_t v_1m = vec_splat_u8(0x01);
|
||||
const uint8x16_t v_2m = vec_splat_u8(0x02);
|
||||
|
||||
const int32x4_t v_z = vec_splat_s32(0);
|
||||
const int16x8_t v_z = vec_splat_s16(0);
|
||||
|
||||
const uchar8x16_t v_minsm = {
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
@@ -1083,7 +1056,7 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
v_xh[0] = vec_xl(0 , x0h);
|
||||
v_xh[1] = vec_xl(16, x0h);
|
||||
|
||||
int32_t sumi = 0;
|
||||
int32x4_t v_sumi = vec_splat_s32(0);
|
||||
for (int j = 0; j < QK_K/64; ++j) {
|
||||
v_xl[0] = vec_xl(0 , x0l);
|
||||
v_xl[1] = vec_xl(16, x0l);
|
||||
@@ -1107,14 +1080,14 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
q5b[2] = (int8x16_t)vec_or(vec_sr(v_xl[0], 4), q5h[2]);
|
||||
q5b[3] = (int8x16_t)vec_or(vec_sr(v_xl[1], 4), q5h[3]);
|
||||
|
||||
int32x4_t sumi0 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, q5b[0], v_y[0]), q5b[1], v_y[1]);
|
||||
int32x4_t sumi1 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, q5b[2], v_y[2]), q5b[3], v_y[3]);
|
||||
const int16x8_t v_p0 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, q5b[0], v_y[0]), q5b[1], v_y[1]);
|
||||
const int16x8_t v_p1 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, q5b[2], v_y[2]), q5b[3], v_y[3]);
|
||||
|
||||
sumi += vec_hsum_i32x4(sumi0) * *scales++;
|
||||
sumi += vec_hsum_i32x4(sumi1) * *scales++;
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p0, vec_splats((int16_t)*scales++)));
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p1, vec_splats((int16_t)*scales++)));
|
||||
}
|
||||
|
||||
sumf += d * sumi - dmin * mins;
|
||||
sumf += d * vec_hsum_i32x4(v_sumi) - dmin * mins;
|
||||
}
|
||||
|
||||
*s = sumf;
|
||||
@@ -1151,7 +1124,7 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const uint8x16_t v_lm = vec_splat_u8(0x0F);
|
||||
const uint8x16_t v_um = vec_splat_u8(0x03);
|
||||
|
||||
const int32x4_t v_z = vec_splat_s32(0);
|
||||
const int16x8_t v_z = vec_splat_s16(0);
|
||||
|
||||
int8x16_t q6b[4];
|
||||
uint8x16_t q6h[4];
|
||||
@@ -1167,12 +1140,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const uint8_t * GGML_RESTRICT x0h = x[i].qh;
|
||||
const int8_t * GGML_RESTRICT y0 = y[i].qs;
|
||||
|
||||
const int8_t * GGML_RESTRICT scale = x[i].scales;
|
||||
|
||||
const int16x8_t v_ysumsl = vec_xl(0 , y[i].bsums);
|
||||
const int16x8_t v_ysumsh = vec_xl(16, y[i].bsums);
|
||||
|
||||
const int8x16_t v_scale = vec_xl(0, scale);
|
||||
const int8x16_t v_scale = vec_xl(0, x[i].scales);
|
||||
const int16x8_t v_scalel = vec_unpackh(v_scale);
|
||||
const int16x8_t v_scaleh = vec_unpackl(v_scale);
|
||||
|
||||
@@ -1182,10 +1153,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
const int32x4_t v_minsh = vec_meadd(v_ysumsh, v_scaleh, v_minsho);
|
||||
const int32x4_t v_mins = vec_add(v_minsl, v_minsh);
|
||||
|
||||
const int32_t mins = vec_hsum_i32x4(v_mins);
|
||||
|
||||
int32_t isum = 0;
|
||||
int32x4_t v_isum = vec_splat_s32(0);
|
||||
for (int j = 0; j < QK_K/128; ++j) {
|
||||
const int16x8_t v_scales = j == 0 ? v_scalel : v_scaleh;
|
||||
|
||||
// Load model upper 2 bits
|
||||
v_xh[0] = vec_xl(0 , x0h);
|
||||
v_xh[1] = vec_xl(16, x0h);
|
||||
@@ -1217,18 +1188,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
q6b[2] = (int8x16_t)(vec_or(vec_and(v_xl[2], v_lm), q6h[2]));
|
||||
q6b[3] = (int8x16_t)(vec_or(vec_and(v_xl[3], v_lm), q6h[3]));
|
||||
|
||||
int32x4_t summs0 = ggml_vec_dot_s32(v_z, q6b[0], v_y[0]);
|
||||
int32x4_t summs1 = ggml_vec_dot_s32(v_z, q6b[1], v_y[1]);
|
||||
int32x4_t summs2 = ggml_vec_dot_s32(v_z, q6b[2], v_y[2]);
|
||||
int32x4_t summs3 = ggml_vec_dot_s32(v_z, q6b[3], v_y[3]);
|
||||
|
||||
isum += vec_hsum_i32x4(summs0) * scale[0] +
|
||||
vec_hsum_i32x4(summs1) * scale[1] +
|
||||
vec_hsum_i32x4(summs2) * scale[2] +
|
||||
vec_hsum_i32x4(summs3) * scale[3];
|
||||
|
||||
scale += 4;
|
||||
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[0], v_y[0]), vec_splat(v_scales, 0)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[1], v_y[1]), vec_splat(v_scales, 1)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[2], v_y[2]), vec_splat(v_scales, 2)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[3], v_y[3]), vec_splat(v_scales, 3)));
|
||||
|
||||
// Load activation quants
|
||||
v_y[0] = vec_xl(0 , y0);
|
||||
@@ -1251,20 +1214,15 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
|
||||
q6b[2] = (int8x16_t)(vec_or(vec_sr(v_xl[2], 4), q6h[2]));
|
||||
q6b[3] = (int8x16_t)(vec_or(vec_sr(v_xl[3], 4), q6h[3]));
|
||||
|
||||
summs0 = ggml_vec_dot_s32(v_z, q6b[0], v_y[0]);
|
||||
summs1 = ggml_vec_dot_s32(v_z, q6b[1], v_y[1]);
|
||||
summs2 = ggml_vec_dot_s32(v_z, q6b[2], v_y[2]);
|
||||
summs3 = ggml_vec_dot_s32(v_z, q6b[3], v_y[3]);
|
||||
|
||||
isum += vec_hsum_i32x4(summs0) * scale[0] +
|
||||
vec_hsum_i32x4(summs1) * scale[1] +
|
||||
vec_hsum_i32x4(summs2) * scale[2] +
|
||||
vec_hsum_i32x4(summs3) * scale[3];
|
||||
|
||||
scale += 4;
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[0], v_y[0]), vec_splat(v_scales, 4)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[1], v_y[1]), vec_splat(v_scales, 5)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[2], v_y[2]), vec_splat(v_scales, 6)));
|
||||
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[3], v_y[3]), vec_splat(v_scales, 7)));
|
||||
}
|
||||
|
||||
sum += d_all * y[i].d * (isum - 32 * mins);
|
||||
v_isum = vec_sub(v_isum, vec_sl(v_mins, 5));
|
||||
|
||||
sum += d_all * y[i].d * vec_hsum_i32x4(v_isum);
|
||||
}
|
||||
|
||||
*s = sum;
|
||||
@@ -1477,6 +1435,7 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
|
||||
#if defined(__VXE__) || defined(__VXE2__)
|
||||
const int8x16_t v_k = vec_xl(0, kvalues_iq4nl);
|
||||
const uint8x16_t v_m = vec_splat_u8(0x0F);
|
||||
const int16x8_t v_z = vec_splat_s16(0);
|
||||
|
||||
float sumf = 0;
|
||||
|
||||
@@ -1486,7 +1445,7 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
|
||||
|
||||
uint16_t h = x[ibl].scales_h;
|
||||
|
||||
int sumi1 = 0, sumi2 = 0;
|
||||
int32x4_t v_sumi = vec_splat_s32(0);
|
||||
for (int ib = 0; ib < QK_K/64; ++ib) {
|
||||
const uint8x16_t v_x0 = vec_xl(0 , q4);
|
||||
const uint8x16_t v_x1 = vec_xl(QK4_NL/2, q4);
|
||||
@@ -1508,19 +1467,21 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
|
||||
const int8x16_t v_y3 = vec_xl(48, q8);
|
||||
q8 += 64;
|
||||
|
||||
int32x4_t vsumi0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0l, v_y0), v_x0h, v_y1);
|
||||
int32x4_t vsumi1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1l, v_y2), v_x1h, v_y3);
|
||||
|
||||
int ls1 = ((x[ibl].scales_l[ib] & 0xF) | ((h << 4) & 0x30)) - 32;
|
||||
int ls2 = ((x[ibl].scales_l[ib] >> 4) | ((h << 2) & 0x30)) - 32;
|
||||
|
||||
h >>= 4;
|
||||
|
||||
sumi1 += vec_hsum_i32x4(vsumi0) * ls1;
|
||||
sumi2 += vec_hsum_i32x4(vsumi1) * ls2;
|
||||
const int16x8_t v_ls1 = vec_splats((int16_t)ls1);
|
||||
const int16x8_t v_ls2 = vec_splats((int16_t)ls2);
|
||||
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x0l, v_y0), v_ls1));
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x0h, v_y1), v_ls1));
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x1l, v_y2), v_ls2));
|
||||
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x1h, v_y3), v_ls2));
|
||||
}
|
||||
|
||||
sumf += GGML_CPU_FP16_TO_FP32(x[ibl].d) * y[ibl].d * (sumi1 + sumi2);
|
||||
sumf += GGML_CPU_FP16_TO_FP32(x[ibl].d) * y[ibl].d * vec_hsum_i32x4(v_sumi);
|
||||
}
|
||||
|
||||
*s = sumf;
|
||||
|
||||
@@ -112,17 +112,20 @@ void ggml_gemv_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
|
||||
const int8_t * y_lo = a_ptr[l].qs;
|
||||
const int8_t * y_hi = y_lo + qk / 2;
|
||||
|
||||
int16x8_t v_sumi = vec_splats((int16_t)0);
|
||||
const int16x8_t v_zero = vec_splats((int16_t)0);
|
||||
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x0l, ggml_vec_xl_s8x4_splat(y_lo + 0));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x1l, ggml_vec_xl_s8x4_splat(y_lo + 4));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x2l, ggml_vec_xl_s8x4_splat(y_lo + 8));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x3l, ggml_vec_xl_s8x4_splat(y_lo + 12));
|
||||
// separate sums, a long multiply-add chain is slow
|
||||
int16x8_t v_sumi0 = ggml_vec_dot_s16(v_zero, v_x0l, ggml_vec_xl_s8x4_splat(y_lo + 0));
|
||||
int16x8_t v_sumi1 = ggml_vec_dot_s16(v_zero, v_x1l, ggml_vec_xl_s8x4_splat(y_lo + 4));
|
||||
int16x8_t v_sumi2 = ggml_vec_dot_s16(v_zero, v_x2l, ggml_vec_xl_s8x4_splat(y_lo + 8));
|
||||
int16x8_t v_sumi3 = ggml_vec_dot_s16(v_zero, v_x3l, ggml_vec_xl_s8x4_splat(y_lo + 12));
|
||||
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x0h, ggml_vec_xl_s8x4_splat(y_hi + 0));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x1h, ggml_vec_xl_s8x4_splat(y_hi + 4));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x2h, ggml_vec_xl_s8x4_splat(y_hi + 8));
|
||||
v_sumi = ggml_vec_dot_s16(v_sumi, v_x3h, ggml_vec_xl_s8x4_splat(y_hi + 12));
|
||||
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_x0h, ggml_vec_xl_s8x4_splat(y_hi + 0));
|
||||
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_x1h, ggml_vec_xl_s8x4_splat(y_hi + 4));
|
||||
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_x2h, ggml_vec_xl_s8x4_splat(y_hi + 8));
|
||||
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_x3h, ggml_vec_xl_s8x4_splat(y_hi + 12));
|
||||
|
||||
const int16x8_t v_sumi = vec_add(vec_add(v_sumi0, v_sumi1), vec_add(v_sumi2, v_sumi3));
|
||||
|
||||
const float32x4_t v_yd = vec_splats(GGML_CPU_FP16_TO_FP32(a_ptr[l].d));
|
||||
const float32x4_t v_xd = ggml_vec_xl_f16x4_finite(b_ptr[l].d);
|
||||
@@ -162,6 +165,8 @@ void ggml_gemm_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
|
||||
}
|
||||
|
||||
for (int l = 0; l < nb; l++) {
|
||||
const int16x8_t v_zero = vec_splats((int16_t)0);
|
||||
|
||||
int16x8_t v_sumi0 = vec_splats((int16_t)0);
|
||||
int16x8_t v_sumi1 = vec_splats((int16_t)0);
|
||||
int16x8_t v_sumi2 = vec_splats((int16_t)0);
|
||||
@@ -175,15 +180,16 @@ void ggml_gemm_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
|
||||
const int8_t * y_lo = a_ptr[l].qs + 16 * k;
|
||||
const int8_t * y_hi = y_lo + qk / 2 * 4;
|
||||
|
||||
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 0));
|
||||
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 4));
|
||||
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 8));
|
||||
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 12));
|
||||
// add each product pair with vec_add, a long multiply-add chain is slow
|
||||
const int16x8_t v_xyl0 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 0));
|
||||
const int16x8_t v_xyl1 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 4));
|
||||
const int16x8_t v_xyl2 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 8));
|
||||
const int16x8_t v_xyl3 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 12));
|
||||
|
||||
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 0));
|
||||
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 4));
|
||||
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 8));
|
||||
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 12));
|
||||
v_sumi0 = vec_add(v_sumi0, ggml_vec_dot_s16(v_xyl0, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 0)));
|
||||
v_sumi1 = vec_add(v_sumi1, ggml_vec_dot_s16(v_xyl1, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 4)));
|
||||
v_sumi2 = vec_add(v_sumi2, ggml_vec_dot_s16(v_xyl2, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 8)));
|
||||
v_sumi3 = vec_add(v_sumi3, ggml_vec_dot_s16(v_xyl3, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 12)));
|
||||
}
|
||||
|
||||
const float32x4_t v_yd = __lzs_f16cx4_load(a_ptr[l].d);
|
||||
|
||||
@@ -487,7 +487,7 @@ inline static int16x8_t vec_padd_s16(int16x8_t a, int16x8_t b) {
|
||||
|
||||
inline static int32x4_t vec_paddl_s16(int16x8_t a) {
|
||||
const int16x8_t v_ones = vec_splats((int16_t)1);
|
||||
return vec_mule(a, v_ones) + vec_mulo(a, v_ones);
|
||||
return vec_meadd(a, v_ones, vec_mulo(a, v_ones));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,9 +507,14 @@ inline static int16x8_t ggml_vec_dot_s16(int16x8_t acc, int8x16_t a, int8x16_t b
|
||||
return vec_meadd(a, b, vec_moadd(a, b, acc));
|
||||
}
|
||||
|
||||
// a * b, each pair of 16-bit products summed into one 32-bit lane
|
||||
inline static int32x4_t ggml_vec_madd_s16(int16x8_t a, int16x8_t b) {
|
||||
return vec_meadd(a, b, vec_mulo(a, b));
|
||||
}
|
||||
|
||||
inline static int32x4_t ggml_vec_dot_s32(int32x4_t acc, int8x16_t a, int8x16_t b) {
|
||||
const int16x8_t p = vec_mule(a, b) + vec_mulo(a, b);
|
||||
return acc + (vec_unpackh(p) + vec_unpackl(p));
|
||||
const int16x8_t p = vec_meadd(a, b, vec_mulo(a, b));
|
||||
return acc + ggml_vec_madd_s16(p, vec_splats((int16_t)1));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -442,7 +442,7 @@ static bool ggml_backend_cpu_device_supports_op(ggml_backend_dev_t dev, const st
|
||||
|
||||
switch (op->op) {
|
||||
case GGML_OP_FLASH_ATTN_EXT:
|
||||
return ggml_validate_flash_attn_ext_indexed_bias(op);
|
||||
return !ggml_flash_attn_ext_has_bias(op) || ggml_flash_attn_ext_bias_is_indexed(op);
|
||||
case GGML_OP_CPY:
|
||||
case GGML_OP_SET_ROWS:
|
||||
return
|
||||
|
||||
@@ -1380,10 +1380,8 @@ class tinyBLAS_Q0_VXE {
|
||||
static constexpr bool has_min = std::is_same<TB, block_q8_1>::value;
|
||||
|
||||
static int32x4_t dot_s8_wide(int8x16_t v_x, int8x16_t v_y) {
|
||||
const int16x8_t v_even = vec_mule(v_x, v_y);
|
||||
const int16x8_t v_odd = vec_mulo(v_x, v_y);
|
||||
// Two (-128) * (-128) products can overflow a signed 16-bit sum.
|
||||
return vec_unpackh(v_even) + vec_unpackl(v_even) + vec_unpackh(v_odd) + vec_unpackl(v_odd);
|
||||
// v_y is never -128, so the sum of two products fits in 16 bits
|
||||
return vec_paddl_s16(vec_meadd(v_x, v_y, vec_mulo(v_x, v_y)));
|
||||
}
|
||||
|
||||
static int32x4_t dot(int8x16_t v_xl, int8x16_t v_xh, int8x16_t v_yl, int8x16_t v_yh) {
|
||||
|
||||
+39
-17
@@ -8981,8 +8981,8 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
|
||||
const ggml_tensor * mask = dst->src[3];
|
||||
const ggml_tensor * sinks = dst->src[4];
|
||||
const ggml_tensor * kv_rows = dst->src[5];
|
||||
const ggml_tensor * bias_table = dst->src[6];
|
||||
const ggml_tensor * bias_indices = dst->src[7];
|
||||
const ggml_tensor * bias = dst->src[6];
|
||||
const ggml_tensor * bias_idxs = dst->src[7];
|
||||
|
||||
GGML_TENSOR_LOCALS(int64_t, neq, q, ne)
|
||||
GGML_TENSOR_LOCALS(size_t, nbq, q, nb)
|
||||
@@ -9024,7 +9024,7 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
|
||||
const int64_t rv2 = neq2/nev2;
|
||||
const int64_t rv3 = neq3/nev3;
|
||||
|
||||
const int64_t n_bins = bias_table ? bias_table->ne[0] : 0;
|
||||
const int64_t n_bins = bias ? bias->ne[0] : 0;
|
||||
|
||||
// parallelize by q rows using ggml_vec_dot_f32
|
||||
|
||||
@@ -9090,8 +9090,8 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
|
||||
const int32_t * rows = kv_rows ? (const int32_t *) ((const char *) kv_rows->data + iq3*kv_rows->nb[1]) : nullptr;
|
||||
|
||||
// bias rows of this query and head, queries of all streams are flattened
|
||||
const float * bias = bias_table ? (const float *) ((const char *) bias_table->data + (iq3*neq1 + iq1)*bias_table->nb[2] + iq2*bias_table->nb[1]) : nullptr;
|
||||
const int32_t * bins = bias_indices ? (const int32_t *) ((const char *) bias_indices->data + (iq3*neq1 + iq1)*bias_indices->nb[1]) : nullptr;
|
||||
const float * bias_row = bias ? (const float *) ((const char *) bias->data + (iq3*neq1 + iq1)*bias->nb[2] + iq2*bias->nb[1]) : nullptr;
|
||||
const int32_t * bins = bias_idxs ? (const int32_t *) ((const char *) bias_idxs->data + (iq3*neq1 + iq1)*bias_idxs->nb[1]) : nullptr;
|
||||
|
||||
// online softmax / attention
|
||||
// loop over n_kv and n_head_kv
|
||||
@@ -9099,9 +9099,9 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
|
||||
|
||||
for (int64_t ic = ic_start; ic < ic_end; ++ic) {
|
||||
float mv = mp ? GGML_CPU_FP16_TO_FP32(mp[ic]) : 0.0f;
|
||||
if (bias) {
|
||||
if (bias_row) {
|
||||
GGML_ASSERT(bins[ic] >= 0 && bins[ic] < n_bins);
|
||||
mv += bias[bins[ic]];
|
||||
mv += bias_row[bins[ic]];
|
||||
}
|
||||
mv *= slope;
|
||||
if (mv == -INFINITY) {
|
||||
@@ -9281,9 +9281,9 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
|
||||
const ggml_tensor * kv_rows = dst->src[5];
|
||||
const int64_t n_kv_cols = kv_rows ? kv_rows->ne[0] : nek1;
|
||||
|
||||
const ggml_tensor * bias_table = dst->src[6];
|
||||
const ggml_tensor * bias_indices = dst->src[7];
|
||||
const int64_t n_bins = bias_table ? bias_table->ne[0] : 0;
|
||||
const ggml_tensor * bias = dst->src[6];
|
||||
const ggml_tensor * bias_idxs = dst->src[7];
|
||||
const int64_t n_bins = bias ? bias->ne[0] : 0;
|
||||
|
||||
int ir = ir0;
|
||||
while (ir < ir1) {
|
||||
@@ -9363,13 +9363,13 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
|
||||
bool can_skip = true;
|
||||
for (int tq = 0; tq < tile_rows; tq++) {
|
||||
const ggml_fp16_t * mp_row = (const ggml_fp16_t *)((const char *) mask->data + (iq1 + tq)*mask->nb[1] + (iq2%mask->ne[2])*mask->nb[2] + (iq3%mask->ne[3])*mask->nb[3]);
|
||||
const float * bias = bias_table ? (const float *) ((const char *) bias_table->data + (iq3*neq1 + iq1 + tq)*bias_table->nb[2] + iq2*bias_table->nb[1]) : nullptr;
|
||||
const int32_t * bins = bias_indices ? (const int32_t *) ((const char *) bias_indices->data + (iq3*neq1 + iq1 + tq)*bias_indices->nb[1]) : nullptr;
|
||||
const float * bias_row = bias ? (const float *) ((const char *) bias->data + (iq3*neq1 + iq1 + tq)*bias->nb[2] + iq2*bias->nb[1]) : nullptr;
|
||||
const int32_t * bins = bias_idxs ? (const int32_t *) ((const char *) bias_idxs->data + (iq3*neq1 + iq1 + tq)*bias_idxs->nb[1]) : nullptr;
|
||||
for (int tk = 0; tk < kv_tile; tk++) {
|
||||
float m = GGML_CPU_FP16_TO_FP32(mp_row[ic + tk]);
|
||||
if (bias) {
|
||||
if (bias_row) {
|
||||
GGML_ASSERT(bins[ic + tk] >= 0 && bins[ic + tk] < n_bins);
|
||||
m += bias[bins[ic + tk]];
|
||||
m += bias_row[bins[ic + tk]];
|
||||
}
|
||||
mask32[tq * KV_TILE_SZ + tk] = slope * m;
|
||||
if (mask32[tq * KV_TILE_SZ + tk] != -INFINITY) {
|
||||
@@ -9722,7 +9722,7 @@ static void ggml_compute_forward_flash_attn_ext_f16(
|
||||
void ggml_compute_forward_flash_attn_ext(
|
||||
const ggml_compute_params * params,
|
||||
ggml_tensor * dst) {
|
||||
GGML_ASSERT(ggml_validate_flash_attn_ext_indexed_bias(dst));
|
||||
GGML_ASSERT(!ggml_flash_attn_ext_has_bias(dst) || ggml_flash_attn_ext_bias_is_indexed(dst));
|
||||
switch (ggml_prec_get_acc(dst)) {
|
||||
case GGML_PREC_UNDEFINED:
|
||||
case GGML_PREC_F32:
|
||||
@@ -10251,8 +10251,30 @@ static void ggml_compute_forward_ssm_scan_f32(
|
||||
|
||||
sumf = GGML_F32xt_REDUCE_ONE(sum);
|
||||
#elif defined(__riscv_v)
|
||||
// todo: RVV implementation
|
||||
const int np = 0;
|
||||
int64_t np = 0;
|
||||
if (!params->use_ref) {
|
||||
const size_t vlmax = __riscv_vsetvlmax_e32m4();
|
||||
vfloat32m4_t sum = __riscv_vfmv_v_f_f32m4(0.0f, vlmax);
|
||||
|
||||
for (int64_t i0 = 0; i0 < nc; ) {
|
||||
const size_t vl = __riscv_vsetvl_e32m4(nc - i0);
|
||||
vfloat32m4_t t0 = __riscv_vle32_v_f32m4(s0 + i0 + ii*nc, vl);
|
||||
vfloat32m4_t t1 = __riscv_vle32_v_f32m4(B + i0 + g*nc, vl);
|
||||
vfloat32m4_t t2 = __riscv_vle32_v_f32m4(C + i0 + g*nc, vl);
|
||||
|
||||
t0 = __riscv_vfmul_vf_f32m4(t0, dA, vl);
|
||||
t1 = __riscv_vfmul_vf_f32m4(t1, x_dt, vl);
|
||||
t0 = __riscv_vfadd_vv_f32m4(t0, t1, vl);
|
||||
|
||||
sum = __riscv_vfmacc_vv_f32m4_tu(sum, t0, t2, vl);
|
||||
__riscv_vse32_v_f32m4(s + i0 + ii*nc, t0, vl);
|
||||
i0 += vl;
|
||||
}
|
||||
|
||||
vfloat32m1_t zero = __riscv_vfmv_v_f_f32m1(0.0f, 1);
|
||||
sumf = __riscv_vfmv_f_s_f32m1_f32(__riscv_vfredusum_vs_f32m4_f32m1(sum, zero, vlmax));
|
||||
np = nc;
|
||||
}
|
||||
#else
|
||||
const int np = (nc & ~(GGML_F32_STEP - 1));
|
||||
|
||||
|
||||
@@ -1047,8 +1047,8 @@ class tensor_traits_common : public tensor_traits_base {
|
||||
return true;
|
||||
}
|
||||
case GGML_OP_FLASH_ATTN_EXT:
|
||||
// K/V row lists and the indexed bias are handled by the generic CPU path
|
||||
if (op->src[5] != nullptr || ggml_flash_attn_ext_has_indexed_bias(op)) {
|
||||
// K/V row lists and bias are handled by the generic CPU path
|
||||
if (op->src[5] != nullptr || ggml_flash_attn_ext_has_bias(op)) {
|
||||
return false;
|
||||
}
|
||||
forward_flash_attn_ext_f16(params, op);
|
||||
|
||||
@@ -517,35 +517,64 @@ struct ggml_cuda_unroll<1> {
|
||||
}
|
||||
};
|
||||
|
||||
template<int width = WARP_SIZE>
|
||||
// If only_lane0_is_used is set to true, then the performance can be better but only lane 0 is guaranteed to have the correct result.
|
||||
template<typename T, int width, bool only_lane0_is_used = false>
|
||||
static __device__ __forceinline__ T warp_reduce_sum_impl(T x) {
|
||||
#if defined(GGML_USE_HIP)
|
||||
if constexpr (width <= 64 && width <= ggml_cuda_get_physical_warp_size()) {
|
||||
static_assert(width >= 2 && width <= 64 && (width & (width - 1)) == 0, "width must be a power of two between 2 and 64");
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_QUAD_PERM_1032>(x);
|
||||
if constexpr (width >= 4) {
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_QUAD_PERM_2301>(x);
|
||||
}
|
||||
if constexpr (width >= 8) {
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_HALF_MIRROR>(x);
|
||||
}
|
||||
if constexpr (width >= 16) {
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_ROR_8>(x);
|
||||
}
|
||||
if constexpr (width == 64) {
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_BCAST_15>(x);
|
||||
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_BCAST_31>(x);
|
||||
if constexpr (only_lane0_is_used) {
|
||||
return ggml_hip_dpp_update<GGML_HIP_DPP_WAVE_ROR_1>(x);
|
||||
} else {
|
||||
return ggml_cuda_shfl(x, 63, 64);
|
||||
}
|
||||
}
|
||||
if constexpr (width == 32) {
|
||||
return x + ggml_hip_swizzle<GGML_HIP_SWIZZLE_SWAP16>(x);
|
||||
}
|
||||
return x;
|
||||
} else
|
||||
#endif // defined(GGML_USE_HIP)
|
||||
{
|
||||
#pragma unroll
|
||||
for (int offset = width/2; offset > 0; offset >>= 1) {
|
||||
x += ggml_cuda_shfl_xor(x, offset, width);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
|
||||
static __device__ __forceinline__ int warp_reduce_sum(int x) {
|
||||
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
|
||||
return __reduce_add_sync(GGML_CUDA_FULL_THREAD_MASK, x);
|
||||
#else
|
||||
#pragma unroll
|
||||
for (int offset = width/2; offset > 0; offset >>= 1) {
|
||||
x += ggml_cuda_shfl_xor(x, offset, width);
|
||||
}
|
||||
return x;
|
||||
return warp_reduce_sum_impl<int, width, only_lane0_is_used>(x);
|
||||
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
|
||||
}
|
||||
|
||||
template<int width = WARP_SIZE>
|
||||
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
|
||||
static __device__ __forceinline__ float warp_reduce_sum(float x) {
|
||||
#pragma unroll
|
||||
for (int offset = width/2; offset > 0; offset >>= 1) {
|
||||
x += ggml_cuda_shfl_xor(x, offset, width);
|
||||
}
|
||||
return x;
|
||||
return warp_reduce_sum_impl<float, width, only_lane0_is_used>(x);
|
||||
}
|
||||
|
||||
template<int width = WARP_SIZE>
|
||||
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
|
||||
static __device__ __forceinline__ float2 warp_reduce_sum(float2 a) {
|
||||
#pragma unroll
|
||||
for (int offset = width/2; offset > 0; offset >>= 1) {
|
||||
a.x += ggml_cuda_shfl_xor(a.x, offset, width);
|
||||
a.y += ggml_cuda_shfl_xor(a.y, offset, width);
|
||||
}
|
||||
a.x = warp_reduce_sum_impl<float, width, only_lane0_is_used>(a.x);
|
||||
a.y = warp_reduce_sum_impl<float, width, only_lane0_is_used>(a.y);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,14 +40,23 @@ static __global__ void dequantize_block(const void * __restrict__ vx, dst_t * __
|
||||
}
|
||||
}
|
||||
|
||||
template <bool need_check>
|
||||
static __global__ void dequantize_block_q8_0_f16(const void * __restrict__ vx, half * __restrict__ y, const int64_t k) {
|
||||
// has_rows: rows of k elements, block (x, y) converts part y of row rows[x] (row 0 for x == n_rows, nothing for negative entries)
|
||||
template <bool need_check, bool has_rows>
|
||||
static __global__ void dequantize_block_q8_0_f16(const void * __restrict__ vx, half * __restrict__ y, const int64_t k,
|
||||
const int32_t * __restrict__ rows, const int64_t n_rows) {
|
||||
#if __CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL
|
||||
constexpr int nint = CUDA_Q8_0_NE_ALIGN/sizeof(int) + WARP_SIZE;
|
||||
|
||||
const int64_t i0 = CUDA_Q8_0_NE_ALIGN*blockIdx.x;
|
||||
const int * x0 = ((int *) vx) + blockIdx.x * nint;
|
||||
half2 * y2 = (half2 *) (y + i0);
|
||||
const int64_t i01 = has_rows && blockIdx.x < n_rows ? rows[blockIdx.x] : 0;
|
||||
const int64_t ipart = has_rows ? blockIdx.y : blockIdx.x;
|
||||
|
||||
if (i01 < 0) {
|
||||
return; // padding
|
||||
}
|
||||
|
||||
const int64_t i0 = CUDA_Q8_0_NE_ALIGN*ipart;
|
||||
const int * x0 = ((int *) vx) + i01*(k/QK8_0)*sizeof(block_q8_0)/sizeof(int) + ipart * nint;
|
||||
half2 * y2 = (half2 *) (y + i01*k + i0);
|
||||
|
||||
__shared__ int vals[nint];
|
||||
|
||||
@@ -76,7 +85,7 @@ static __global__ void dequantize_block_q8_0_f16(const void * __restrict__ vx, h
|
||||
y2[iy/2 + threadIdx.x] = __hmul2(make_half2(qs.x, qs.y), __half2half2(d));
|
||||
}
|
||||
#else
|
||||
GGML_UNUSED_VARS(vx, y, k);
|
||||
GGML_UNUSED_VARS(vx, y, k, rows, n_rows);
|
||||
NO_DEVICE_CODE;
|
||||
#endif // __CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL
|
||||
}
|
||||
@@ -268,10 +277,31 @@ static void dequantize_block_q8_0_f16_cuda(const void * __restrict__ vx, half *
|
||||
const int num_blocks = (k + CUDA_Q8_0_NE_ALIGN - 1) / CUDA_Q8_0_NE_ALIGN;
|
||||
if (k % CUDA_Q8_0_NE_ALIGN == 0) {
|
||||
const bool need_check = false;
|
||||
dequantize_block_q8_0_f16<need_check><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, k);
|
||||
dequantize_block_q8_0_f16<need_check, false><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, k, nullptr, 0);
|
||||
} else {
|
||||
const bool need_check = true;
|
||||
dequantize_block_q8_0_f16<need_check><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, k);
|
||||
dequantize_block_q8_0_f16<need_check, false><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, k, nullptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// for ne01 contiguous rows of ne00 elements, converts only the rows in rows[0..n_rows) and row 0
|
||||
static void dequantize_block_q8_0_f16_rows_cuda(const void * vx, half * y, const int64_t ne00, const int64_t ne01,
|
||||
const int32_t * rows, const int64_t n_rows, cudaStream_t stream) {
|
||||
const int64_t nparts = (ne00 + CUDA_Q8_0_NE_ALIGN - 1) / CUDA_Q8_0_NE_ALIGN;
|
||||
const int64_t nparts_all = (ne00*ne01 + CUDA_Q8_0_NE_ALIGN - 1) / CUDA_Q8_0_NE_ALIGN;
|
||||
// convert all of the data if that needs fewer blocks (not elements), so this never launches more blocks than the full conversion
|
||||
// the kernel reads int so a row has to start at a multiple of sizeof(int)
|
||||
if ((n_rows + 1)*nparts >= nparts_all || nparts > 65535 || (ne00/QK8_0*sizeof(block_q8_0)) % sizeof(int) != 0) {
|
||||
dequantize_block_q8_0_f16_cuda(vx, y, ne00*ne01, stream);
|
||||
return;
|
||||
}
|
||||
const dim3 num_blocks(n_rows + 1, nparts, 1);
|
||||
if (ne00 % CUDA_Q8_0_NE_ALIGN == 0) {
|
||||
const bool need_check = false;
|
||||
dequantize_block_q8_0_f16<need_check, true><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, ne00, rows, n_rows);
|
||||
} else {
|
||||
const bool need_check = true;
|
||||
dequantize_block_q8_0_f16<need_check, true><<<num_blocks, WARP_SIZE, 0, stream>>>(vx, y, ne00, rows, n_rows);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,6 +703,13 @@ to_fp32_cuda_t ggml_get_to_fp32_cuda(ggml_type type) {
|
||||
}
|
||||
}
|
||||
|
||||
to_fp16_rows_cuda_t ggml_get_to_fp16_rows_cuda(ggml_type type) {
|
||||
if (type == GGML_TYPE_Q8_0 && fp16_available(ggml_cuda_info().devices[ggml_cuda_get_device()].cc)) {
|
||||
return dequantize_block_q8_0_f16_rows_cuda;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
to_fp16_nc_cuda_t ggml_get_to_fp16_nc_cuda(ggml_type type) {
|
||||
switch (type) {
|
||||
case GGML_TYPE_F32:
|
||||
|
||||
@@ -31,6 +31,12 @@ to_fp32_nc_cuda_t ggml_get_to_fp32_nc_cuda(ggml_type type);
|
||||
to_fp16_nc_cuda_t ggml_get_to_fp16_nc_cuda(ggml_type type);
|
||||
to_bf16_nc_cuda_t ggml_get_to_bf16_nc_cuda(ggml_type type);
|
||||
|
||||
// for ne01 contiguous rows of ne00 elements, converts only the rows in rows[0..n_rows) and row 0, negative entries are skipped
|
||||
typedef void (*to_fp16_rows_cuda_t)(const void * x, half * y,
|
||||
int64_t ne00, int64_t ne01, const int32_t * rows, int64_t n_rows, cudaStream_t stream);
|
||||
|
||||
to_fp16_rows_cuda_t ggml_get_to_fp16_rows_cuda(ggml_type type);
|
||||
|
||||
template<typename dst_t, typename src_t>
|
||||
__host__ __device__ inline dst_t ggml_cuda_cast(src_t x) {
|
||||
if constexpr (std::is_same_v<dst_t, src_t>) {
|
||||
|
||||
@@ -16,7 +16,7 @@ static __global__ void count_equal(const T * __restrict__ x, const T * __restric
|
||||
nequal += xi == yi;
|
||||
}
|
||||
|
||||
nequal = warp_reduce_sum(nequal);
|
||||
nequal = warp_reduce_sum<WARP_SIZE, true>(nequal);
|
||||
|
||||
if (threadIdx.x != 0) {
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,7 @@ static __global__ void cross_entropy_loss_f32(
|
||||
const float logit_i = use_shared ? tmp[i] : logits[i];
|
||||
loss += (logit_i - max_logit - sum) * labels[i];
|
||||
}
|
||||
loss = -warp_reduce_sum(loss) / (float)k;
|
||||
loss = -warp_reduce_sum<WARP_SIZE, true>(loss) / (float)k;
|
||||
|
||||
if (threadIdx.x != 0) {
|
||||
return;
|
||||
|
||||
@@ -20,20 +20,20 @@
|
||||
// The macro on the following line shifts it by a factor of 2**3=8, as was needed to fix https://github.com/ggml-org/llama.cpp/issues/18606 .
|
||||
#define FATTN_KQ_MAX_OFFSET (3.0f*0.6931f)
|
||||
|
||||
struct fattn_indexed_bias {
|
||||
const float * table;
|
||||
const int32_t * indices;
|
||||
struct fattn_bias_indexed {
|
||||
const float * bias;
|
||||
const int32_t * bias_idxs;
|
||||
int64_t n_bins;
|
||||
int64_t n_keys;
|
||||
int64_t query_stride;
|
||||
|
||||
__device__ fattn_indexed_bias for_head(int64_t first_query, int head) const {
|
||||
return {table + first_query*query_stride + head*n_bins, indices + first_query*n_keys, n_bins, n_keys, query_stride};
|
||||
__device__ fattn_bias_indexed for_head(int64_t first_query, int head) const {
|
||||
return {bias + first_query*query_stride + head*n_bins, bias_idxs + first_query*n_keys, n_bins, n_keys, query_stride};
|
||||
}
|
||||
|
||||
__device__ float add(float mask, int query, int key) const {
|
||||
const int bin = indices[query*n_keys + key];
|
||||
return bin >= 0 && bin < n_bins ? mask + table[query*query_stride + bin] : mask;
|
||||
const int bin = bias_idxs[query*n_keys + key];
|
||||
return bin >= 0 && bin < n_bins ? mask + bias[query*query_stride + bin] : mask;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ using fattn_kernel_t = void (*)(
|
||||
const int32_t s21, const int32_t s22, const int64_t s23,
|
||||
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
||||
const int32_t s31, const int64_t s32, const int64_t s33,
|
||||
const fattn_indexed_bias bias);
|
||||
const fattn_bias_indexed bias);
|
||||
|
||||
typedef float (*vec_dot_KQ_t)(
|
||||
const char * __restrict__ K_c, const void * __restrict__ Q_v, const int * __restrict__ Q_q8 , const void * __restrict__ Q_ds);
|
||||
@@ -1324,9 +1324,9 @@ void launch_fattn(
|
||||
const ggml_tensor * sinks = dst->src[4];
|
||||
const ggml_tensor * kv_rows = dst->src[5];
|
||||
|
||||
const bool has_bias = ggml_flash_attn_ext_has_indexed_bias(dst);
|
||||
const ggml_tensor * bias_table = has_bias ? dst->src[6] : nullptr;
|
||||
const ggml_tensor * bias_indices = has_bias ? dst->src[7] : nullptr;
|
||||
const bool bias_indexed = ggml_flash_attn_ext_bias_is_indexed(dst);
|
||||
const ggml_tensor * bias = bias_indexed ? dst->src[6] : nullptr;
|
||||
const ggml_tensor * bias_idxs = bias_indexed ? dst->src[7] : nullptr;
|
||||
|
||||
// with kv_rows the kernel iterates over the mask columns and reads K/V rows through kv_rows
|
||||
const int64_t n_kv_cols = kv_rows ? kv_rows->ne[0] : K->ne[1];
|
||||
@@ -1373,8 +1373,16 @@ void launch_fattn(
|
||||
GGML_ASSERT(f16_extra.K != 0);
|
||||
half * K_f16 = (half *) f16_extra.K;
|
||||
if (ggml_is_contiguously_allocated(K)) {
|
||||
to_fp16_cuda_t to_fp16 = ggml_get_to_fp16_cuda(K->type);
|
||||
to_fp16(K_data, K_f16, ggml_nelements(K), main_stream);
|
||||
// with kv_rows the kernel reads only the listed rows and row 0 (for padding), so convert only those
|
||||
const to_fp16_rows_cuda_t to_fp16_rows = kv_rows && nb12*bs == K->ne[0]*ts && nb11 == K->ne[2]*nb12 ?
|
||||
ggml_get_to_fp16_rows_cuda(K->type) : nullptr;
|
||||
if (to_fp16_rows) {
|
||||
to_fp16_rows(K_data, K_f16, K->ne[0]*K->ne[2], K->ne[1],
|
||||
(const int32_t *) kv_rows->data, ggml_nelements(kv_rows), main_stream);
|
||||
} else {
|
||||
to_fp16_cuda_t to_fp16 = ggml_get_to_fp16_cuda(K->type);
|
||||
to_fp16(K_data, K_f16, ggml_nelements(K), main_stream);
|
||||
}
|
||||
|
||||
nb11 = nb11*bs*sizeof(half)/ts;
|
||||
nb12 = nb12*bs*sizeof(half)/ts;
|
||||
@@ -1407,8 +1415,15 @@ void launch_fattn(
|
||||
GGML_ASSERT(f16_extra.V != 0);
|
||||
half * V_f16 = (half *) f16_extra.V;
|
||||
if (ggml_is_contiguously_allocated(V)) {
|
||||
to_fp16_cuda_t to_fp16 = ggml_get_to_fp16_cuda(V->type);
|
||||
to_fp16(V_data, V_f16, ggml_nelements(V), main_stream);
|
||||
const to_fp16_rows_cuda_t to_fp16_rows = kv_rows && nb22*bs == V->ne[0]*ts && nb21 == V->ne[2]*nb22 ?
|
||||
ggml_get_to_fp16_rows_cuda(V->type) : nullptr;
|
||||
if (to_fp16_rows) {
|
||||
to_fp16_rows(V_data, V_f16, V->ne[0]*V->ne[2], V->ne[1],
|
||||
(const int32_t *) kv_rows->data, ggml_nelements(kv_rows), main_stream);
|
||||
} else {
|
||||
to_fp16_cuda_t to_fp16 = ggml_get_to_fp16_cuda(V->type);
|
||||
to_fp16(V_data, V_f16, ggml_nelements(V), main_stream);
|
||||
}
|
||||
V_data = (char *) V_f16;
|
||||
|
||||
nb21 = nb21*bs*sizeof(half)/ts;
|
||||
@@ -1461,7 +1476,7 @@ void launch_fattn(
|
||||
// Only worth the overhead if there is at lease one FATTN_KQ_STRIDE x FATTN_KQ_STRIDE square to be skipped or
|
||||
// multiple sequences of possibly different lengths, or kv_rows lists that end with padding.
|
||||
// The scan reads ncols1 mask rows per tile, including the last tile.
|
||||
const bool scan_mask = !has_bias && !use_sparse && mask && mask->ne[2] == 1 && mask->ne[1]/ncols1 >= ntiles_x &&
|
||||
const bool scan_mask = !bias_indexed && !use_sparse && mask && mask->ne[2] == 1 && mask->ne[1]/ncols1 >= ntiles_x &&
|
||||
n_kv_cols % FATTN_KQ_STRIDE == 0 && (Q->ne[1] >= 1024 || Q->ne[3] > 1 || kv_rows);
|
||||
if (scan_mask) {
|
||||
const int64_t s31 = mask->nb[1] / sizeof(half2);
|
||||
@@ -1621,11 +1636,11 @@ void launch_fattn(
|
||||
mask ? int32_t(mask->nb[1] / sizeof(half)) : 0,
|
||||
mask ? int64_t(mask->nb[2] / sizeof(half)) : 0,
|
||||
mask ? int64_t(mask->nb[3] / sizeof(half)) : 0,
|
||||
fattn_indexed_bias{has_bias ? (const float *) bias_table->data : nullptr,
|
||||
has_bias ? (const int32_t *) bias_indices->data : nullptr,
|
||||
has_bias ? bias_table->ne[0] : 0,
|
||||
has_bias ? bias_indices->ne[0] : 0,
|
||||
has_bias ? bias_table->ne[0]*bias_table->ne[1] : 0}
|
||||
fattn_bias_indexed{bias_indexed ? (const float *) bias->data : nullptr,
|
||||
bias_indexed ? (const int32_t *) bias_idxs->data : nullptr,
|
||||
bias_indexed ? bias->ne[0] : 0,
|
||||
bias_indexed ? bias_idxs->ne[0] : 0,
|
||||
bias_indexed ? bias->ne[0]*bias->ne[1] : 0}
|
||||
);
|
||||
CUDA_CHECK(cudaGetLastError());
|
||||
|
||||
|
||||
@@ -754,7 +754,7 @@ static __device__ __forceinline__ void flash_attn_ext_f16_iter(
|
||||
const int i = i0 + T_C_KQ::get_j(l);
|
||||
const int j = ((threadIdx.y / np)*cols_per_warp + T_C_KQ::get_i(l)) / ncols2;
|
||||
|
||||
KQ_C[i00/(np*T_C_KQ::J)].x[l] += __half2float(tile_mask[j*(nbatch_fa + 8) + i]);
|
||||
KQ_C[i00/(np*T_C_KQ::J)].x[l] += slope*__half2float(tile_mask[j*(nbatch_fa + 8) + i]);
|
||||
}
|
||||
#else
|
||||
#pragma unroll
|
||||
@@ -1866,7 +1866,7 @@ static __global__ void flash_attn_ext_f16(
|
||||
const int32_t s21, const int32_t s22, const int64_t s23,
|
||||
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
||||
const int32_t s31, const int64_t s32, const int64_t s33,
|
||||
const fattn_indexed_bias bias) {
|
||||
const fattn_bias_indexed bias) {
|
||||
GGML_UNUSED(bias); // biased ops are never dispatched to the mma kernel
|
||||
ggml_cuda_pdl_sync(); // TODO optimize placement
|
||||
#if defined(FLASH_ATTN_AVAILABLE) && (defined(VOLTA_MMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE) || defined(AMD_MFMA_AVAILABLE))
|
||||
@@ -1913,7 +1913,7 @@ static __global__ void flash_attn_ext_f16(
|
||||
#endif // __CUDA_ARCH__ == GGML_CUDA_CC_TURING
|
||||
|
||||
#if defined(AMD_WMMA_AVAILABLE)
|
||||
if (ncols1*ncols2 < 16 || ncols2 == 1 || DKQ > 256) {
|
||||
if (ncols1*ncols2 < 16 || DKQ > 256) {
|
||||
NO_DEVICE_CODE;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -373,9 +373,21 @@ static constexpr __device__ int ggml_cuda_fattn_tile_get_nbatch_K(const int DKQ,
|
||||
return (ggml_cuda_fattn_tile_get_config(DKQ, DV, ncols) >> 23) & ((1 << 9) - 1);
|
||||
}
|
||||
|
||||
#ifdef GGML_USE_HIP
|
||||
// The sparse launch pins ncols1 == 1, so the ncols2 parameter is the total number of Q columns per block.
|
||||
static constexpr bool ggml_cuda_flash_attn_ext_tile_may_use_sparse(
|
||||
const int DKQ, const int DV, const int ncols2, const bool use_logit_softcap) {
|
||||
return DKQ > 64 && ncols2 > 1 && !use_logit_softcap &&
|
||||
ggml_cuda_fattn_tile_get_config_amd(DKQ, DV, ncols2) != 0 &&
|
||||
ggml_cuda_fattn_tile_get_config_amd_rdna(DKQ, DV, ncols2) != 0;
|
||||
}
|
||||
|
||||
bool ggml_cuda_flash_attn_ext_tile_shall_use_sparse(const int cc, const ggml_tensor * dst, const int DKQ, const int DV);
|
||||
#endif // GGML_USE_HIP
|
||||
|
||||
// Function that performs a single iteration in for the KQ matrix multiplication:
|
||||
template <int warp_size, int nwarps, int ncols1, int ncols2, int DKQ, int nbatch_fa, int nbatch_K,
|
||||
bool use_logit_softcap, bool oob_check, bool indexed_bias, typename T_vec_dot, typename T_K>
|
||||
bool use_logit_softcap, bool oob_check, bool bias_indexed, bool use_sparse, typename T_vec_dot, typename T_K>
|
||||
static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
|
||||
T_vec_dot * const Q_tmp,
|
||||
const T_K * const __restrict__ K_h2,
|
||||
@@ -394,7 +406,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
|
||||
constexpr int np = nwarps > ncols ? nwarps/ncols : 1; // number of parallel warps per Q column
|
||||
|
||||
constexpr int stride_tile_K = std::is_same_v<T_vec_dot, half2> ? nbatch_K/2 + cpy_ne : nbatch_K + cpy_ne;
|
||||
flash_attn_load_tile<warp_size, nwarps, nbatch_fa, nbatch_K, stride_tile_K, false, oob_check, false, indexed_bias, false, T_K, T_vec_dot>
|
||||
flash_attn_load_tile<warp_size, nwarps, nbatch_fa, nbatch_K, stride_tile_K, false, oob_check, use_sparse, bias_indexed || use_sparse, false, T_K, T_vec_dot>
|
||||
(K_h2 + k_KQ_0/2, KV_tmp, nbatch_K/2, stride_K2, k_VKQ_0, k_VKQ_sup, rows);
|
||||
__syncthreads();
|
||||
|
||||
@@ -452,7 +464,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
|
||||
|
||||
// Function that performs a single iteration of the main loop over up to nbatch_fa tokens.
|
||||
template <int warp_size, int nwarps, int ncols1, int ncols2, int DKQ, int DV, int nbatch_fa, int nbatch_K,
|
||||
bool use_logit_softcap, bool oob_check, bool indexed_bias, typename T_vec_dot, typename T_KQ, typename T_acc, typename T_K, typename T_V>
|
||||
bool use_logit_softcap, bool oob_check, bool bias_indexed, bool use_sparse, typename T_vec_dot, typename T_KQ, typename T_acc, typename T_K, typename T_V>
|
||||
static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
T_vec_dot * const Q_tmp,
|
||||
const T_K * const __restrict__ K_h2,
|
||||
@@ -472,7 +484,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
const int k_VKQ_0,
|
||||
const int k_VKQ_max,
|
||||
const int col_Q_0,
|
||||
const fattn_indexed_bias bias,
|
||||
const fattn_bias_indexed bias,
|
||||
const int32_t * const __restrict__ rows) {
|
||||
constexpr int cpy_nb = 16;
|
||||
constexpr int cpy_ne = cpy_nb / 4;
|
||||
@@ -505,12 +517,12 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
constexpr int nbatch_K_last = DKQ % nbatch_K;
|
||||
#pragma unroll
|
||||
for (int k_KQ_0 = 0; k_KQ_0 < DKQ - nbatch_K_last; k_KQ_0 += nbatch_K) {
|
||||
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>(
|
||||
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, bias_indexed, use_sparse>(
|
||||
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc, rows);
|
||||
}
|
||||
if (nbatch_K_last > 0) {
|
||||
constexpr int k_KQ_0 = DKQ - nbatch_K_last;
|
||||
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K_last, use_logit_softcap, oob_check, indexed_bias>(
|
||||
flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K_last, use_logit_softcap, oob_check, bias_indexed, use_sparse>(
|
||||
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc, rows);
|
||||
}
|
||||
|
||||
@@ -534,11 +546,11 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
}
|
||||
|
||||
if (!oob_check || i_KQ < k_VKQ_sup) {
|
||||
if (indexed_bias || ncols2 > 1 || mask) {
|
||||
const int k = k_VKQ_0 + i_KQ;
|
||||
if (bias_indexed || ncols2 > 1 || mask) {
|
||||
const int k = use_sparse ? rows[k_VKQ_0 + i_KQ] : k_VKQ_0 + i_KQ;
|
||||
__builtin_assume(k >= 0); // avoid sign extension and register spills on RDNA
|
||||
const float m = __half2float(mask[int64_t(j)*stride_mask + k]);
|
||||
KQ_acc[(i_KQ_0/(np*warp_size))*cpw + jc0] += slope*(indexed_bias ? bias.add(m, j, k) : m);
|
||||
KQ_acc[(i_KQ_0/(np*warp_size))*cpw + jc0] += slope*(bias_indexed ? bias.add(m, j, k) : m);
|
||||
}
|
||||
|
||||
KQ_max_new[jc0] = fmaxf(KQ_max_new[jc0], KQ_acc[(i_KQ_0/(np*warp_size))*cpw + jc0] + FATTN_KQ_MAX_OFFSET);
|
||||
@@ -621,7 +633,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
constexpr int stride_tile_V = std::is_same_v<T_vec_dot, half2> ? DV/2 : DV;
|
||||
#pragma unroll
|
||||
for (int k0 = 0; k0 < nbatch_fa; k0 += nbatch_V) {
|
||||
flash_attn_load_tile<warp_size, nwarps, nbatch_V, DV, stride_tile_V, false, oob_check, false, indexed_bias, false, T_V, T_vec_dot>
|
||||
flash_attn_load_tile<warp_size, nwarps, nbatch_V, DV, stride_tile_V, false, oob_check, use_sparse, bias_indexed || use_sparse, false, T_V, T_vec_dot>
|
||||
(V_h2, KV_tmp, DV/2, stride_V2, k_VKQ_0 + k0, k_VKQ_sup - k0, rows);
|
||||
__syncthreads();
|
||||
|
||||
@@ -691,7 +703,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
|
||||
}
|
||||
}
|
||||
|
||||
template<int DKQ, int DV, int ncols1, int ncols2, bool use_logit_softcap, bool indexed_bias, ggml_type type_K, ggml_type type_V, bool use_kv_rows> // D == head size
|
||||
template<int DKQ, int DV, int ncols1, int ncols2, bool use_logit_softcap, bool bias_indexed, ggml_type type_K, ggml_type type_V, bool use_kv_rows, bool use_sparse = false> // D == head size
|
||||
__launch_bounds__(ggml_cuda_fattn_tile_get_nthreads(DKQ, DV, ncols1*ncols2), ggml_cuda_fattn_tile_get_occupancy(DKQ, DV, ncols1*ncols2))
|
||||
static __global__ void flash_attn_tile(
|
||||
const float2 * Q_ptr,
|
||||
@@ -716,7 +728,7 @@ static __global__ void flash_attn_tile(
|
||||
const int32_t s21, const int32_t s22, const int64_t s23,
|
||||
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
||||
const int32_t s31, const int64_t s32, const int64_t s33,
|
||||
const fattn_indexed_bias bias) {
|
||||
const fattn_bias_indexed bias) {
|
||||
#ifdef FLASH_ATTN_AVAILABLE
|
||||
using T_K = decltype(ggml_cuda_fattn_kv_dtype<type_K>());
|
||||
using T_V = decltype(ggml_cuda_fattn_kv_dtype<type_V>());
|
||||
@@ -732,6 +744,15 @@ static __global__ void flash_attn_tile(
|
||||
|
||||
// Skip unused kernel variants for faster compilation:
|
||||
|
||||
#ifndef GCN
|
||||
if constexpr (use_sparse) {
|
||||
NO_DEVICE_CODE;
|
||||
return;
|
||||
}
|
||||
#endif // GCN
|
||||
|
||||
static_assert(!use_sparse || (ncols1 == 1 && !bias_indexed && !use_kv_rows), "bad sparse configuration");
|
||||
|
||||
if ((use_logit_softcap && !(DV == 128 || DV == 256 || DV == 512))) {
|
||||
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
|
||||
max_bias, m0, m1, n_head_log2, logit_softcap,
|
||||
@@ -767,15 +788,18 @@ static __global__ void flash_attn_tile(
|
||||
|
||||
const int sequence = blockIdx.z / (ne02/ncols2);
|
||||
const int head0 = blockIdx.z*ncols2 - sequence*ne02; // == blockIdx.z % (ne02/ncols2)
|
||||
const int32_t * rows = use_kv_rows ? KV_rows_ptr + int64_t(sequence)*ne11 : nullptr;
|
||||
// For sparse attention, ne11 is the capacity of each index list, not the KV cache length.
|
||||
const int64_t list = use_sparse ? int64_t(sequence % ne33)*gridDim.x + blockIdx.x : 0;
|
||||
const int32_t * rows = use_sparse ? KV_max + list*ne11 :
|
||||
use_kv_rows ? KV_rows_ptr + int64_t(sequence)*ne11 : nullptr;
|
||||
__builtin_assume(!use_kv_rows || rows != nullptr);
|
||||
const fattn_indexed_bias head_bias = indexed_bias ? bias.for_head(int64_t(sequence)*ne01.z, head0) : bias;
|
||||
const fattn_bias_indexed head_bias = bias_indexed ? bias.for_head(int64_t(sequence)*ne01.z, head0) : bias;
|
||||
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
|
||||
const float2 * Q_f2 = Q + s03*sequence + s02* head0;
|
||||
const T_K * K_h2 = K + s13*sequence + s12*(head0 / gqa_ratio);
|
||||
const T_V * V_h2 = V + s23*sequence + s22*(head0 / gqa_ratio); // K and V have same shape
|
||||
|
||||
const half * maskh = indexed_bias || mask ? mask + s33*(sequence % ne33) + s32*(head0 % ne32) : nullptr;
|
||||
const half * maskh = bias_indexed || mask ? mask + s33*(sequence % ne33) + s32*(head0 % ne32) : nullptr;
|
||||
|
||||
const int stride_K2 = s11;
|
||||
const int stride_V2 = s21;
|
||||
@@ -868,20 +892,21 @@ static __global__ void flash_attn_tile(
|
||||
__syncthreads();
|
||||
|
||||
// Main loop over KV cache:
|
||||
const int k_VKQ_max = KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
|
||||
if (ncols2 == 1) {
|
||||
const int k_VKQ_max = use_sparse ? KV_max[int64_t(gridDim.x)*ne33*ne11 + list] :
|
||||
KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
|
||||
if (ncols2 == 1 || use_sparse) {
|
||||
// Branch with out-of-bounds checks.
|
||||
int k_VKQ_0 = blockIdx.y*nbatch_fa;
|
||||
while (k_VKQ_0 <= k_VKQ_max - nbatch_fa) {
|
||||
constexpr bool oob_check = false;
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, bias_indexed, use_sparse>
|
||||
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
|
||||
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
|
||||
k_VKQ_0 += gridDim.y*nbatch_fa;
|
||||
}
|
||||
if (k_VKQ_0 < k_VKQ_max) {
|
||||
constexpr bool oob_check = true;
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, bias_indexed, use_sparse>
|
||||
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
|
||||
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
|
||||
}
|
||||
@@ -889,7 +914,7 @@ static __global__ void flash_attn_tile(
|
||||
// Branch without out-of-bounds checks.
|
||||
for (int k_VKQ_0 = blockIdx.y*nbatch_fa; k_VKQ_0 < k_VKQ_max; k_VKQ_0 += gridDim.y*nbatch_fa) {
|
||||
constexpr bool oob_check = false;
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
|
||||
flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, bias_indexed, use_sparse>
|
||||
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
|
||||
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
|
||||
}
|
||||
@@ -1063,7 +1088,7 @@ static __global__ void flash_attn_tile(
|
||||
#endif // FLASH_ATTN_AVAILABLE
|
||||
}
|
||||
|
||||
template <int DKQ, int DV, int ncols2, bool use_logit_softcap, ggml_type type_K, ggml_type type_V, bool indexed_bias, bool use_kv_rows>
|
||||
template <int DKQ, int DV, int ncols2, bool use_logit_softcap, ggml_type type_K, ggml_type type_V, bool bias_indexed, bool use_kv_rows>
|
||||
static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
||||
using T_K = decltype(ggml_cuda_fattn_kv_dtype<type_K>());
|
||||
using T_V = decltype(ggml_cuda_fattn_kv_dtype<type_V>());
|
||||
@@ -1077,15 +1102,26 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr size_t nbytes_shared = 0;
|
||||
|
||||
#ifdef GGML_USE_HIP
|
||||
if constexpr (!bias_indexed && !use_kv_rows && ggml_cuda_flash_attn_ext_tile_may_use_sparse(DKQ, DV, ncols2, use_logit_softcap)) {
|
||||
if (ggml_cuda_flash_attn_ext_tile_shall_use_sparse(cc, dst, DKQ, DV)) {
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads(DKQ, DV, ncols2, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, ncols2, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, 1, ncols2, use_logit_softcap, false, type_K, type_V, false, true>;
|
||||
launch_fattn<DV, 1, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, true, warp_size);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Limit indexed bias tile widths to avoid spilling registers on AMD.
|
||||
// TODO: select the tile width in one function.
|
||||
constexpr int max_cols = !indexed_bias ? 64 : DKQ == 64 ? 32 : use_kv_rows ? 16 : 8;
|
||||
constexpr int max_cols = !bias_indexed ? 64 : DKQ == 64 ? 32 : use_kv_rows ? 16 : 8;
|
||||
if constexpr (DKQ <= 128 && max_cols >= 64) {
|
||||
if (!(amd_mfma_available(cc) && ncols2 == 1) && Q->ne[1] > 32/ncols2) {
|
||||
constexpr int cols_per_block = 64;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1100,7 +1136,7 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr int cols_per_block = 32;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1112,7 +1148,7 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr int cols_per_block = 16;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1124,7 +1160,7 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr int cols_per_block = 8;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1136,7 +1172,7 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr int cols_per_block = 4;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1147,7 +1183,7 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
|
||||
constexpr int cols_per_block = 2;
|
||||
const int nwarps = ggml_cuda_fattn_tile_get_nthreads (DKQ, DV, cols_per_block, cc) / warp_size;
|
||||
const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, cols_per_block, cc);
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, indexed_bias, type_K, type_V, use_kv_rows>;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, cols_per_block/ncols2, ncols2, use_logit_softcap, bias_indexed, type_K, type_V, use_kv_rows>;
|
||||
launch_fattn<DV, cols_per_block/ncols2, ncols2, T_K, T_V>
|
||||
(ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, false, warp_size);
|
||||
return;
|
||||
@@ -1177,7 +1213,7 @@ static void launch_fattn_tile_switch_ncols2(ggml_backend_cuda_context & ctx, ggm
|
||||
const bool use_gqa_opt = mask && mask->ne[2] == 1 && max_bias == 0.0f && Q->ne[1] <= gqa_limit && K->ne[1] % FATTN_KQ_STRIDE == 0;
|
||||
|
||||
if constexpr (DKQ == 64 || DKQ == 128) {
|
||||
if (ggml_flash_attn_ext_has_indexed_bias(dst)) {
|
||||
if (ggml_flash_attn_ext_bias_is_indexed(dst)) {
|
||||
if (dst->src[5]) {
|
||||
launch_fattn_tile_switch_ncols1<DKQ, DV, 1, use_logit_softcap, type_K, type_V, true, true>(ctx, dst);
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ static constexpr __device__ int ggml_cuda_fattn_vec_get_nthreads_device() {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpass-failed"
|
||||
#endif // __clang__
|
||||
template<int D, int ncols, ggml_type type_K, ggml_type type_V, bool use_logit_softcap, bool indexed_bias, bool use_kv_rows> // D == head size
|
||||
template<int D, int ncols, ggml_type type_K, ggml_type type_V, bool use_logit_softcap, bool bias_indexed, bool use_kv_rows> // D == head size
|
||||
__launch_bounds__(ggml_cuda_fattn_vec_get_nthreads_device(), 1)
|
||||
static __global__ void flash_attn_ext_vec(
|
||||
const float2 * Q_ptr,
|
||||
@@ -41,7 +41,7 @@ static __global__ void flash_attn_ext_vec(
|
||||
const int32_t s21, const int32_t s22, const int64_t s23,
|
||||
const int32_t ne31, const int32_t ne32, const int32_t ne33,
|
||||
const int32_t s31, const int64_t s32, const int64_t s33,
|
||||
const fattn_indexed_bias bias) {
|
||||
const fattn_bias_indexed bias) {
|
||||
ggml_cuda_pdl_lc();
|
||||
#ifdef FLASH_ATTN_AVAILABLE
|
||||
const float2 * GGML_CUDA_RESTRICT Q = Q_ptr;
|
||||
@@ -75,7 +75,7 @@ static __global__ void flash_attn_ext_vec(
|
||||
|
||||
#ifdef GGML_USE_HIP
|
||||
#ifdef RDNA
|
||||
constexpr int nthreads_KQ_q = indexed_bias && type_K == GGML_TYPE_F8_E4M3 ? 16 : 2;
|
||||
constexpr int nthreads_KQ_q = bias_indexed && type_K == GGML_TYPE_F8_E4M3 ? 16 : 2;
|
||||
#else
|
||||
constexpr int nthreads_KQ_q = type_K == GGML_TYPE_F8_E4M3 && D == 256 && ncols == 2 ? 16 : 4;
|
||||
#endif // RDNA
|
||||
@@ -107,13 +107,13 @@ static __global__ void flash_attn_ext_vec(
|
||||
|
||||
const int sequence = blockIdx.z / ne02;
|
||||
const int head = blockIdx.z - sequence*ne02;
|
||||
const fattn_indexed_bias head_bias = indexed_bias ? bias.for_head(int64_t(sequence)*ne01.z, head) : bias;
|
||||
const fattn_bias_indexed head_bias = bias_indexed ? bias.for_head(int64_t(sequence)*ne01.z, head) : bias;
|
||||
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
|
||||
Q += s03*sequence + s02* head + s01*ic0;
|
||||
K += s13*sequence + s12*(head / gqa_ratio);
|
||||
V += s23*sequence + s22*(head / gqa_ratio);
|
||||
|
||||
const half * maskh = indexed_bias || mask ? mask + s33*(sequence % ne33) + s32*(head % ne32) + s31*ic0 : nullptr;
|
||||
const half * maskh = bias_indexed || mask ? mask + s33*(sequence % ne33) + s32*(head % ne32) + s31*ic0 : nullptr;
|
||||
|
||||
const float slope = get_alibi_slope(max_bias, head, n_head_log2, m0, m1);
|
||||
|
||||
@@ -305,7 +305,7 @@ static __global__ void flash_attn_ext_vec(
|
||||
sum = logit_softcap*tanhf(sum);
|
||||
}
|
||||
|
||||
if constexpr (!indexed_bias) {
|
||||
if constexpr (!bias_indexed) {
|
||||
if (mask && (ncols == 1 || ic0 + j < int(ne01.z))) {
|
||||
sum += slope*__half2float(maskh[j*ne11 + i_KQ]);
|
||||
}
|
||||
@@ -321,14 +321,14 @@ static __global__ void flash_attn_ext_vec(
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < ncols; ++j) {
|
||||
if constexpr (indexed_bias) {
|
||||
if constexpr (bias_indexed) {
|
||||
const int k = k_VKQ_0 + tid;
|
||||
const float m = head_bias.add(__half2float(maskh[j*ne11 + tid]), ic0 + j, k);
|
||||
KQ_reg[j] += slope*m;
|
||||
KQ_max_new[j] = fmaxf(KQ_max[j], KQ_reg[j] + FATTN_KQ_MAX_OFFSET);
|
||||
}
|
||||
#pragma unroll
|
||||
for (int offset = indexed_bias ? 1 : nthreads_KQ; offset < WARP_SIZE; offset <<= 1) {
|
||||
for (int offset = bias_indexed ? 1 : nthreads_KQ; offset < WARP_SIZE; offset <<= 1) {
|
||||
KQ_max_new[j] = fmaxf(KQ_max_new[j], ggml_cuda_shfl_xor(KQ_max_new[j], offset, WARP_SIZE));
|
||||
}
|
||||
const float KQ_max_scale = expf(KQ_max[j] - KQ_max_new[j]);
|
||||
@@ -513,7 +513,7 @@ static __global__ void flash_attn_ext_vec(
|
||||
#endif // V_DOT2_F32_F16_AVAILABLE
|
||||
|
||||
KQ_sum[j_VKQ] *= kqmax_scale;
|
||||
KQ_sum[j_VKQ] = warp_reduce_sum(KQ_sum[j_VKQ]);
|
||||
KQ_sum[j_VKQ] = warp_reduce_sum<WARP_SIZE, true>(KQ_sum[j_VKQ]);
|
||||
if (threadIdx.x == 0) {
|
||||
KQ_sum_shared[j_VKQ][threadIdx.y] = KQ_sum[j_VKQ];
|
||||
}
|
||||
@@ -574,8 +574,13 @@ void ggml_cuda_flash_attn_ext_vec_case_impl(ggml_backend_cuda_context & ctx, ggm
|
||||
const int nthreads = ggml_cuda_fattn_vec_get_nthreads_host(cc);
|
||||
const int nwarps = nthreads / WARP_SIZE;
|
||||
fattn_kernel_t fattn_kernel = flash_attn_ext_vec<D, cols_per_block, type_K, type_V, use_logit_softcap, false, false>;
|
||||
if constexpr (cols_per_block == 1 && !use_logit_softcap) {
|
||||
if (dst->src[5]) {
|
||||
fattn_kernel = flash_attn_ext_vec<D, cols_per_block, type_K, type_V, use_logit_softcap, false, true>;
|
||||
}
|
||||
}
|
||||
if constexpr (cols_per_block == 1 && (D == 64 || D == 128) && !use_logit_softcap) {
|
||||
if (ggml_flash_attn_ext_has_indexed_bias(dst)) {
|
||||
if (ggml_flash_attn_ext_bias_is_indexed(dst)) {
|
||||
fattn_kernel = dst->src[5] ? flash_attn_ext_vec<D, cols_per_block, type_K, type_V, use_logit_softcap, true, true>
|
||||
: flash_attn_ext_vec<D, cols_per_block, type_K, type_V, use_logit_softcap, true, false>;
|
||||
}
|
||||
@@ -594,6 +599,9 @@ void ggml_cuda_flash_attn_ext_vec_case(ggml_backend_cuda_context & ctx, ggml_ten
|
||||
float logit_softcap;
|
||||
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
||||
|
||||
// the kv_rows variant exists for one query per sequence without softcap
|
||||
GGML_ASSERT(!dst->src[5] || (Q->ne[1] == 1 && logit_softcap == 0.0f));
|
||||
|
||||
if (Q->ne[1] == 1) {
|
||||
constexpr int cols_per_block = 1;
|
||||
if (logit_softcap == 0.0f) {
|
||||
|
||||
+138
-75
@@ -127,6 +127,71 @@ void ggml_cuda_flash_attn_ext_compact_mask(
|
||||
#endif // !defined(GGML_USE_MUSA)
|
||||
}
|
||||
|
||||
#ifdef GGML_USE_HIP
|
||||
bool ggml_cuda_flash_attn_ext_tile_shall_use_sparse(const int cc, const ggml_tensor * dst, const int DKQ, const int DV) {
|
||||
const ggml_tensor * Q = dst->src[0];
|
||||
const ggml_tensor * K = dst->src[1];
|
||||
const ggml_tensor * mask = dst->src[3];
|
||||
|
||||
const int n_kv_max = ggml_get_op_params_i32(dst, 4);
|
||||
const int64_t n_kv = K->ne[1];
|
||||
|
||||
float max_bias = 0.0f;
|
||||
memcpy(&max_bias, (const float *) dst->op_params + 1, sizeof(float));
|
||||
|
||||
if (!mask || mask->ne[0] != n_kv || mask->ne[1] < Q->ne[1] ||
|
||||
mask->ne[2] != 1 || dst->src[5] || n_kv_max <= 0 || max_bias != 0.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GGML_CUDA_CC_IS_GCN(cc)) {
|
||||
// Sparse compaction is not beneficial when the selected positions exceed 25% of the KV cache.
|
||||
if (n_kv_max > n_kv/4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
||||
|
||||
if (DKQ == 72 && DV == 72) {
|
||||
return n_kv >= 8192;
|
||||
}
|
||||
if (DKQ == 80 && DV == 80) {
|
||||
return n_kv >= 16384;
|
||||
}
|
||||
if (DKQ == 96 && DV == 96) {
|
||||
return n_kv >= 16384;
|
||||
}
|
||||
if (DKQ == 112 && DV == 112) {
|
||||
return n_kv >= 16384;
|
||||
}
|
||||
if (DKQ == 128 && DV == 128) {
|
||||
return n_kv >= 8192;
|
||||
}
|
||||
if (DKQ == 192 && DV == 128) {
|
||||
return n_kv >= 16384;
|
||||
}
|
||||
if (DKQ == 256 && DV == 256) {
|
||||
if (gqa_ratio == 2) {
|
||||
return (n_kv_max <= DKQ && n_kv >= 16384) ||
|
||||
(n_kv >= 32768 && (Q->ne[1] == 1 || n_kv_max <= 2*DKQ));
|
||||
}
|
||||
return n_kv >= 4096 && (Q->ne[1] == 1 || n_kv_max < n_kv/8);
|
||||
}
|
||||
if (DKQ == 320 && DV == 256) {
|
||||
return n_kv >= 65536 && gqa_ratio >= 64;
|
||||
}
|
||||
if (DKQ == 512 && DV == 512) {
|
||||
return n_kv >= 16384 && gqa_ratio >= 16;
|
||||
}
|
||||
if (DKQ == 576 && DV == 512) {
|
||||
return n_kv >= 32768 && gqa_ratio >= 32;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif // GGML_USE_HIP
|
||||
|
||||
bool ggml_cuda_flash_attn_ext_mma_f16_shall_use_sparse(const int cc, const ggml_tensor * dst, const int ncols1, const int ncols2) {
|
||||
#ifdef GGML_USE_MUSA
|
||||
GGML_UNUSED_VARS(cc, dst, ncols1, ncols2);
|
||||
@@ -198,9 +263,7 @@ static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1(ggml_backend_cuda_con
|
||||
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 64/ncols2, ncols2, type_K, type_V>(ctx, dst);
|
||||
}
|
||||
|
||||
template <int DKQ, int DV, ggml_type type_K, ggml_type type_V>
|
||||
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
||||
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
||||
static int ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(const int cc, const ggml_tensor * dst) {
|
||||
const ggml_tensor * KQV = dst;
|
||||
const ggml_tensor * Q = dst->src[0];
|
||||
const ggml_tensor * K = dst->src[1];
|
||||
@@ -230,71 +293,56 @@ static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_con
|
||||
}
|
||||
}
|
||||
|
||||
if (!use_gqa_opt) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
|
||||
const int gqa_ratio = Q->ne[2] / K->ne[2];
|
||||
|
||||
// On Volta the GQA optimizations aren't as impactful vs. minimizing wasted compute:
|
||||
if (cc == GGML_CUDA_CC_VOLTA) {
|
||||
if (use_gqa_opt && gqa_ratio % 8 == 0) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
const int ncols2_max = Q->ne[0] == 320 ? 32 : ((Q->ne[0] == 576 || Q->ne[0] == 192) ? 16 : 8);
|
||||
|
||||
if (use_gqa_opt && gqa_ratio % 4 == 0) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (DKQ <= 256) {
|
||||
if (use_gqa_opt && gqa_ratio % 2 == 0) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
} else {
|
||||
GGML_ABORT("fatal error");
|
||||
// On Volta and RDNA it is preferable to minimize wasted compute vs. duplicate I/O for the mask:
|
||||
if (cc == GGML_CUDA_CC_VOLTA || (amd_wmma_available(cc) && gqa_ratio % 2 == 0)) {
|
||||
int ncols2 = 1;
|
||||
while (gqa_ratio % (2*ncols2) == 0 && ncols2 < ncols2_max) {
|
||||
ncols2 *= 2;
|
||||
}
|
||||
return ncols2;
|
||||
}
|
||||
|
||||
// On RDNA it is preferable to minimize wasted compute vs. duplicate I/O for the mask.
|
||||
if (amd_wmma_available(cc)) {
|
||||
if (use_gqa_opt && gqa_ratio % 8 == 0) {
|
||||
int ncols2 = 1;
|
||||
while (gqa_ratio > ncols2 && ncols2 < ncols2_max) {
|
||||
ncols2 *= 2;
|
||||
}
|
||||
return ncols2;
|
||||
}
|
||||
|
||||
template <int DKQ, int DV, ggml_type type_K, ggml_type type_V>
|
||||
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
||||
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
|
||||
|
||||
const int ncols2 = ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(cc, dst);
|
||||
|
||||
switch (ncols2) {
|
||||
case 8:
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_gqa_opt && gqa_ratio % 4 == 0) {
|
||||
break;
|
||||
case 4:
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_gqa_opt && gqa_ratio % 2 == 0) {
|
||||
break;
|
||||
case 2:
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_gqa_opt && gqa_ratio > 4) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_gqa_opt && gqa_ratio > 2) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_gqa_opt && gqa_ratio > 1) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (DKQ <= 256) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
|
||||
} else {
|
||||
GGML_ABORT("fatal error");
|
||||
break;
|
||||
case 1:
|
||||
if constexpr (DKQ <= 256) {
|
||||
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
|
||||
break;
|
||||
} else {
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
default:
|
||||
GGML_ABORT("fatal error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,7 +654,7 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
|
||||
const ggml_tensor * mask = dst->src[3];
|
||||
const ggml_tensor * kv_rows = dst->src[5];
|
||||
|
||||
if (!ggml_validate_flash_attn_ext_indexed_bias(dst)) {
|
||||
if (ggml_flash_attn_ext_has_bias(dst) && !ggml_flash_attn_ext_bias_is_indexed(dst)) {
|
||||
return BEST_FATTN_KERNEL_NONE;
|
||||
}
|
||||
|
||||
@@ -691,7 +739,7 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
|
||||
}
|
||||
|
||||
// the tile and vec kernels implement the indexed bias, the mma kernel does not
|
||||
if (ggml_flash_attn_ext_has_indexed_bias(dst)) {
|
||||
if (ggml_flash_attn_ext_bias_is_indexed(dst)) {
|
||||
float logit_softcap;
|
||||
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
||||
if (Q->ne[0] != 128 && !(Q->ne[0] == 64 && logit_softcap == 0.0f)) {
|
||||
@@ -717,10 +765,23 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
|
||||
}
|
||||
}
|
||||
|
||||
// without a bias only the MMA kernel reads K/V through kv_rows
|
||||
// without a bias only the MMA and vec kernels read K/V through kv_rows
|
||||
if (kv_rows) {
|
||||
return GGML_CUDA_CC_IS_NVIDIA(cc) && turing_mma_available(cc) && mask && Q->ne[0] != 40 && Q->ne[0] != 72 ?
|
||||
BEST_FATTN_KERNEL_MMA_F16 : BEST_FATTN_KERNEL_NONE;
|
||||
if (!(GGML_CUDA_CC_IS_NVIDIA(cc) && turing_mma_available(cc) && mask)) {
|
||||
return BEST_FATTN_KERNEL_NONE;
|
||||
}
|
||||
float logit_softcap = 0.0f;
|
||||
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
|
||||
|
||||
// the vec kernel reads quantized/bf16/f8 K/V in place, the MMA kernel would convert the whole cache to f16
|
||||
// only for K/V pairs with a compiled vec kernel, the f16 fallback of the vec kernel also converts the whole cache
|
||||
const bool vec_rows = n_kv % FATTN_KQ_STRIDE == 0 &&
|
||||
(K->type != GGML_TYPE_F16 || V->type != GGML_TYPE_F16) && K->type != GGML_TYPE_F32 && V->type != GGML_TYPE_F32 &&
|
||||
Q->ne[1] == 1 && logit_softcap == 0.0f && ggml_cuda_get_fattn_vec_case(Q->ne[0], K->type, V->type) != nullptr;
|
||||
if (vec_rows) {
|
||||
return BEST_FATTN_KERNEL_VEC;
|
||||
}
|
||||
return Q->ne[0] != 40 && Q->ne[0] != 72 ? BEST_FATTN_KERNEL_MMA_F16 : BEST_FATTN_KERNEL_NONE;
|
||||
}
|
||||
|
||||
// For small batch sizes the vector kernel may be preferable over the kernels optimized for large batch sizes:
|
||||
@@ -757,20 +818,16 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
|
||||
const int ncols2_max = Q->ne[0] == 320 ? 32 : ((Q->ne[0] == 576 || Q->ne[0] == 192) ? 16 : 8);
|
||||
int gqa_ratio_eff = 1;
|
||||
while (max_bias == 0.0f && (!mask || mask->ne[2] == 1) && gqa_ratio % (2*gqa_ratio_eff) == 0 && gqa_ratio_eff < ncols2_max) {
|
||||
gqa_ratio_eff *= 2;
|
||||
}
|
||||
const int ncols2 = ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(cc, dst);
|
||||
|
||||
// the tile kernel for DKQ=576 only has the ncols2 = 4 and 16 variants
|
||||
const best_fattn_kernel tile_kernel = Q->ne[0] == 576 && gqa_ratio % 4 != 0 ? BEST_FATTN_KERNEL_NONE : BEST_FATTN_KERNEL_TILE;
|
||||
|
||||
if (volta_mma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
|
||||
if (can_use_vector_kernel && Q->ne[1] * gqa_ratio_eff <= 2) {
|
||||
if (can_use_vector_kernel && Q->ne[1] * ncols2 <= 2) {
|
||||
return BEST_FATTN_KERNEL_VEC;
|
||||
}
|
||||
if (Q->ne[1] * gqa_ratio_eff <= 16) {
|
||||
if (Q->ne[1] * ncols2 <= 16) {
|
||||
return tile_kernel; // On Volta tensor cores are only faster for sufficiently large matrices.
|
||||
}
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
@@ -783,23 +840,29 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
|
||||
|
||||
// AMD MFMA needs a certain minimum batch size to outscale the tile kernel for large head sizes.
|
||||
if (amd_mfma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
|
||||
if ((Q->ne[0] <= 64 && Q->ne[1] * gqa_ratio_eff > 8)) {
|
||||
if ((Q->ne[0] <= 64 && Q->ne[1] * ncols2 > 8)) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
if ((Q->ne[0] <= 128 && Q->ne[1] * gqa_ratio_eff > 16)) {
|
||||
if ((Q->ne[0] <= 128 && Q->ne[1] * ncols2 > 16)) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
if ((Q->ne[0] <= 256 && Q->ne[1] * gqa_ratio_eff > 64)) {
|
||||
if ((Q->ne[0] <= 256 && Q->ne[1] * ncols2 > 64)) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
if (Q->ne[0] > 256 && gqa_opt_applies && Q->ne[1] * gqa_ratio_eff > 128) {
|
||||
if (Q->ne[0] > 256 && gqa_opt_applies && Q->ne[1] * ncols2 > 128) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
}
|
||||
|
||||
// AMD WMMA is faster than the tile kernel if the wide tiles with high arithmetic intensity can be utilized.
|
||||
if ((amd_wmma_available(cc) && gqa_opt_applies && Q->ne[0] <= 256) && Q->ne[0] != 40 && Q->ne[0] != 72 &&
|
||||
Q->ne[1] * gqa_ratio_eff > (Q->ne[0] <= 128 ? 8 : 16)) {
|
||||
Q->ne[1] * ncols2 > (Q->ne[0] <= 128 ? 8 : 16)) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
|
||||
// Mask-less attention with many queries (e.g. vision encoders) cannot use the GQA tiles above.
|
||||
// The WMMA kernel is still much faster than the tile kernel for this case:
|
||||
if (amd_wmma_available(cc) && !mask && Q->ne[0] <= 256 && Q->ne[1] >= 128) {
|
||||
return BEST_FATTN_KERNEL_MMA_F16;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ bool ggml_cuda_should_fuse_mul_mat_vec_q(const ggml_tensor * tensor) {
|
||||
}
|
||||
|
||||
// do not fuse the matmuls that few-row MMQ takes in ggml_cuda_mul_mat_id
|
||||
if (tensor->op == GGML_OP_MUL_MAT_ID && ggml_cuda_should_use_mmq_few(src0, src1, tensor->src[2], cc)) {
|
||||
if (tensor->op == GGML_OP_MUL_MAT_ID && ggml_cuda_should_use_mmq_few(src0, src1, tensor->src[2], tensor, cc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ static bool ggml_cuda_should_fuse_mul_mat_q(const ggml_tensor * up, const ggml_t
|
||||
const int64_t nchannels = is_id ? x_up->ne[2] : y->ne[2]*y->ne[3];
|
||||
const bool use_mmvq = is_id ? ncols <= get_mmvq_mmid_max_batch(x_up->type, cc) : ggml_cuda_should_use_mmvq(x_up->type, cc, ncols);
|
||||
// do not fuse the matmuls that few-row MMQ takes in ggml_cuda_mul_mat; for MUL_MAT_ID the fused MMQ keeps the expert gate and up
|
||||
if (!is_id && ggml_cuda_should_use_mmq_few(x_up, y, nullptr, cc)) {
|
||||
if (!is_id && ggml_cuda_should_use_mmq_few(x_up, y, nullptr, up, cc)) {
|
||||
return false;
|
||||
}
|
||||
if (use_mmvq || !ggml_cuda_should_use_mmq(x_up->type, cc, ncols, /*n_experts =*/ is_id ? x_up->ne[2] : 0)) {
|
||||
|
||||
@@ -203,7 +203,7 @@ gated_delta_net_cuda(const float * q,
|
||||
attn_partial += s_shard[r] * q_reg[r];
|
||||
}
|
||||
|
||||
float attn_col = warp_reduce_sum<lanes_per_col>(attn_partial);
|
||||
float attn_col = warp_reduce_sum<lanes_per_col, true>(attn_partial);
|
||||
|
||||
if (lane_in_col == 0) {
|
||||
attn_data[col] = attn_col * scale;
|
||||
@@ -237,7 +237,7 @@ gated_delta_net_cuda(const float * q,
|
||||
attn_partial += s_shard[r] * q_reg[r];
|
||||
}
|
||||
|
||||
float attn_col = warp_reduce_sum<lanes_per_col>(attn_partial);
|
||||
float attn_col = warp_reduce_sum<lanes_per_col, true>(attn_partial);
|
||||
|
||||
if (lane_in_col == 0) {
|
||||
attn_data[col] = attn_col * scale;
|
||||
|
||||
@@ -483,8 +483,14 @@ static ggml_cuda_device_info ggml_cuda_init() {
|
||||
GGML_LOG_INFO(
|
||||
" Device %d: %s\n", turing_devices_without_mma[device_pos].first, turing_devices_without_mma[device_pos].second.c_str());
|
||||
}
|
||||
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && CUDART_VERSION >= 13000
|
||||
// CUDA 13 dropped compute_61, so the Pascal code can only be compiled with an older toolkit
|
||||
GGML_LOG_INFO(
|
||||
"Consider compiling with CMAKE_CUDA_ARCHITECTURES=61-virtual;80-virtual and DGGML_CUDA_FORCE_MMQ to force the use of the Pascal code for Turing.\n");
|
||||
"Consider compiling with CUDA 12, -DCMAKE_CUDA_ARCHITECTURES=\"61-virtual;80-virtual\" and -DGGML_CUDA_FORCE_MMQ=ON to force the use of the Pascal code for Turing (CUDA 13 cannot compile for compute_61).\n");
|
||||
#else
|
||||
GGML_LOG_INFO(
|
||||
"Consider compiling with -DCMAKE_CUDA_ARCHITECTURES=\"61-virtual;80-virtual\" and -DGGML_CUDA_FORCE_MMQ=ON to force the use of the Pascal code for Turing.\n");
|
||||
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && CUDART_VERSION >= 13000
|
||||
}
|
||||
|
||||
for (int id = 0; id < info.device_count; ++id) {
|
||||
@@ -2261,15 +2267,15 @@ static bool ggml_cuda_mul_mat(ggml_backend_cuda_context & ctx, const ggml_tensor
|
||||
return false;
|
||||
}
|
||||
// from a per-type number of src1 columns up to 24, few-row MMQ is faster than MMVQ and MMQ
|
||||
const bool use_mmq_few = ggml_cuda_should_use_mmq_few(src0, src1, nullptr, cc);
|
||||
const bool use_mmq_few = ggml_cuda_should_use_mmq_few(src0, src1, nullptr, dst, cc);
|
||||
if (!use_mmq_few && ggml_cuda_should_use_mmvq(src0->type, cc, ne11)) {
|
||||
const bool fold = scale_fold && ggml_cuda_should_fuse_mul_mat_vec_q(dst);
|
||||
ggml_cuda_mul_mat_vec_q(ctx, src0, src1, nullptr, dst, fold ? &fusion : nullptr);
|
||||
return fold;
|
||||
}
|
||||
if (use_mmq_few) {
|
||||
ggml_cuda_mul_mat_q_few(ctx, src0, src1, nullptr, dst);
|
||||
return false;
|
||||
ggml_cuda_mul_mat_q_few(ctx, src0, src1, nullptr, dst, scale_fold ? &fusion : nullptr);
|
||||
return scale_fold;
|
||||
}
|
||||
if (ggml_cuda_should_use_mmq(src0->type, cc, ne11, /*n_experts =*/ 0)) {
|
||||
ggml_cuda_mul_mat_q(ctx, src0, src1, nullptr, dst, scale_fold ? &fusion : nullptr);
|
||||
@@ -2307,7 +2313,7 @@ static bool ggml_cuda_mul_mat_id_needs_sync(const ggml_tensor * dst, const int c
|
||||
}
|
||||
}
|
||||
|
||||
if (ggml_cuda_should_use_mmq_few(src0, src1, dst->src[2], cc)) {
|
||||
if (ggml_cuda_should_use_mmq_few(src0, src1, dst->src[2], dst, cc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2349,7 +2355,7 @@ static bool ggml_cuda_mul_mat_id(ggml_backend_cuda_context & ctx, ggml_tensor *
|
||||
// [TAG_MUL_MAT_ID_CUDA_GRAPHS]
|
||||
if ((src1->type == GGML_TYPE_F32 || src1->type == GGML_TYPE_BF16) && dst->type == GGML_TYPE_F32) {
|
||||
// up to 24 tokens few-row MMQ is faster than MMQ, on DGX Spark also faster than MMVQ
|
||||
const bool use_mmq_few = ggml_cuda_should_use_mmq_few(src0, src1, ids, cc);
|
||||
const bool use_mmq_few = ggml_cuda_should_use_mmq_few(src0, src1, ids, dst, cc);
|
||||
|
||||
static_assert(MMVQ_MAX_BATCH_SIZE == MMVF_MAX_BATCH_SIZE);
|
||||
if (!use_mmq_few && ne2 <= MMVQ_MAX_BATCH_SIZE) {
|
||||
|
||||
@@ -290,7 +290,7 @@ static __global__ void lightning_indexer_kernel_vec(
|
||||
|
||||
#pragma unroll
|
||||
for (int k = 0; k < K_VECS_PER_WARP; ++k) {
|
||||
float sum = warp_reduce_sum(qk[k]);
|
||||
float sum = warp_reduce_sum<WARP_SIZE, true>(qk[k]);
|
||||
|
||||
// ReLU, weight
|
||||
if (i_lane == 0) {
|
||||
|
||||
+717
-67
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,9 @@
|
||||
|
||||
#include "common.cuh"
|
||||
|
||||
// ids != nullptr: MUL_MAT_ID
|
||||
bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, int cc);
|
||||
// ids != nullptr: MUL_MAT_ID. dst is the MUL_MAT or MUL_MAT_ID node, it holds the src1 precision requested by the graph.
|
||||
bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, const ggml_tensor * dst, int cc);
|
||||
|
||||
void ggml_cuda_mul_mat_q_few(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, ggml_tensor * dst);
|
||||
// fusion: only the scalar weight scale of an NVFP4 src0 (x_scale) and the requested src1 precision of the MUL_MAT, applied in the write-back.
|
||||
void ggml_cuda_mul_mat_q_few(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, ggml_tensor * dst,
|
||||
const ggml_cuda_mm_fusion_args_host * fusion = nullptr);
|
||||
|
||||
@@ -112,18 +112,24 @@ static ggml_prec ggml_cuda_mmq_get_prec_env() {
|
||||
return GGML_PREC_UNDEFINED;
|
||||
}
|
||||
|
||||
// GGML_CUDA_MMQ_PREC if set, else the src1 precision requested by the graph
|
||||
static ggml_prec ggml_cuda_mmq_get_prec(const ggml_prec prec_requested) {
|
||||
static const ggml_prec prec_env = ggml_cuda_mmq_get_prec_env();
|
||||
return prec_env != GGML_PREC_UNDEFINED ? prec_env : prec_requested;
|
||||
}
|
||||
|
||||
bool ggml_cuda_mmq_prec_src1_supported(const ggml_prec prec_requested) {
|
||||
const ggml_prec prec = ggml_cuda_mmq_get_prec(prec_requested);
|
||||
return prec == GGML_PREC_UNDEFINED || prec == GGML_PREC_Q8 || prec == GGML_PREC_Q4;
|
||||
}
|
||||
|
||||
// src1 is quantized to Q8_1 unless the FP4 types can use 4-bit activations, in which case they
|
||||
// default to the native W4A4 instructions on Blackwell.
|
||||
static ggml_prec ggml_cuda_mmq_get_prec_src1(const ggml_type type, const ggml_prec prec_requested, const int cc) {
|
||||
static const ggml_prec prec_env = ggml_cuda_mmq_get_prec_env();
|
||||
|
||||
ggml_prec prec = prec_env;
|
||||
if (prec == GGML_PREC_UNDEFINED) {
|
||||
prec = prec_requested;
|
||||
}
|
||||
ggml_prec ggml_cuda_mmq_get_prec_src1(const ggml_type type, const ggml_prec prec_requested, const int cc) {
|
||||
GGML_ASSERT(ggml_cuda_mmq_prec_src1_supported(prec_requested));
|
||||
const ggml_prec prec = ggml_cuda_mmq_get_prec(prec_requested);
|
||||
|
||||
// Q4 only for the FP4 types on Blackwell
|
||||
GGML_ASSERT(prec == GGML_PREC_UNDEFINED || prec == GGML_PREC_Q8 || prec == GGML_PREC_Q4);
|
||||
const bool can_use_q4 = (type == GGML_TYPE_NVFP4 || type == GGML_TYPE_MXFP4) && blackwell_mma_available(cc);
|
||||
if (prec == GGML_PREC_Q8 || !can_use_q4) {
|
||||
return GGML_PREC_Q8;
|
||||
|
||||
@@ -1727,5 +1727,12 @@ void ggml_cuda_mul_mat_q(
|
||||
|
||||
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t n_experts);
|
||||
|
||||
// The src1 precision of MMQ: GGML_PREC_Q4 for MXFP4 and NVFP4 on Blackwell unless the precision is GGML_PREC_Q8, else GGML_PREC_Q8.
|
||||
// GGML_CUDA_MMQ_PREC, if set, replaces prec_requested. prec_requested must pass ggml_cuda_mmq_prec_src1_supported (asserted).
|
||||
ggml_prec ggml_cuda_mmq_get_prec_src1(ggml_type type, ggml_prec prec_requested, int cc);
|
||||
|
||||
// Whether MMQ takes this src1 precision request: UNDEFINED, Q8 or Q4 after the GGML_CUDA_MMQ_PREC override.
|
||||
bool ggml_cuda_mmq_prec_src1_supported(ggml_prec prec_requested);
|
||||
|
||||
// prec_requested: the src1 precision requested by the fused MUL_MATs.
|
||||
bool ggml_cuda_mmq_fusion_is_efficient(ggml_type type, ggml_prec prec_requested, int64_t nrows_x, int64_t ncols, int64_t nchannels, int device);
|
||||
|
||||
@@ -358,29 +358,32 @@ static __global__ void mul_mat_vec_f(
|
||||
ggml_cuda_pdl_lc();
|
||||
#pragma unroll
|
||||
for (int j = 0; j < ncols_dst; ++j) {
|
||||
sumf[j] = warp_reduce_sum<warp_size>(sumf[j]);
|
||||
sumf[j] = warp_reduce_sum<warp_size, (block_size > warp_size || ncols_dst == 1)>(sumf[j]);
|
||||
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
sumf_gate[j] = warp_reduce_sum<warp_size>(sumf_gate[j]);
|
||||
sumf_gate[j] = warp_reduce_sum<warp_size, (block_size > warp_size || ncols_dst == 1)>(sumf_gate[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (block_size > warp_size) {
|
||||
buf_iw[tid/warp_size] = sumf[j];
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
buf_iw_gate[tid/warp_size] = sumf_gate[j];
|
||||
// one write per warp
|
||||
if (tid % warp_size == 0) {
|
||||
buf_iw[tid/warp_size] = sumf[j];
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
buf_iw_gate[tid/warp_size] = sumf_gate[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
__syncthreads();
|
||||
if (tid < warp_size) {
|
||||
sumf[j] = buf_iw[tid];
|
||||
sumf[j] = warp_reduce_sum<warp_size>(sumf[j]);
|
||||
sumf[j] = warp_reduce_sum<warp_size, ncols_dst == 1>(sumf[j]);
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
sumf_gate[j] = buf_iw_gate[tid];
|
||||
sumf_gate[j] = warp_reduce_sum<warp_size>(sumf_gate[j]);
|
||||
sumf_gate[j] = warp_reduce_sum<warp_size, ncols_dst == 1>(sumf_gate[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ static constexpr __host__ __device__ int get_vdr_mmvq(ggml_type type) {
|
||||
|
||||
enum mmvq_parameter_table_id {
|
||||
MMVQ_PARAMETERS_GENERIC = 0,
|
||||
MMVQ_PARAMETERS_PASCAL_DP4A,
|
||||
MMVQ_PARAMETERS_TURING,
|
||||
MMVQ_PARAMETERS_GCN,
|
||||
MMVQ_PARAMETERS_RDNA1,
|
||||
@@ -118,6 +119,8 @@ static constexpr __device__ mmvq_parameter_table_id get_device_table_id() {
|
||||
return MMVQ_PARAMETERS_GB10;
|
||||
#elif __CUDA_ARCH__ == GGML_CUDA_CC_ORIN
|
||||
return MMVQ_PARAMETERS_ORIN;
|
||||
#elif defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= GGML_CUDA_CC_DP4A && __CUDA_ARCH__ < GGML_CUDA_CC_VOLTA
|
||||
return MMVQ_PARAMETERS_PASCAL_DP4A;
|
||||
#else
|
||||
return MMVQ_PARAMETERS_GENERIC;
|
||||
#endif
|
||||
@@ -148,6 +151,9 @@ static __host__ mmvq_parameter_table_id get_device_table_id(int cc) {
|
||||
if (GGML_CUDA_CC_IS_NVIDIA(cc) && ggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_ORIN) {
|
||||
return MMVQ_PARAMETERS_ORIN;
|
||||
}
|
||||
if (GGML_CUDA_CC_IS_NVIDIA(cc) && ggml_cuda_highest_compiled_arch(cc) >= GGML_CUDA_CC_DP4A && ggml_cuda_highest_compiled_arch(cc) < GGML_CUDA_CC_VOLTA) {
|
||||
return MMVQ_PARAMETERS_PASCAL_DP4A;
|
||||
}
|
||||
return MMVQ_PARAMETERS_GENERIC;
|
||||
}
|
||||
|
||||
@@ -478,7 +484,11 @@ static constexpr __device__ int get_mmvq_mmid_max_batch_for_device() {
|
||||
}
|
||||
|
||||
static constexpr __host__ __device__ int calc_nwarps(ggml_type type, int ncols_dst, mmvq_parameter_table_id table_id, bool small_k = false, bool halve_iters = false) {
|
||||
if (table_id == MMVQ_PARAMETERS_GENERIC) {
|
||||
if (table_id == MMVQ_PARAMETERS_GENERIC || table_id == MMVQ_PARAMETERS_PASCAL_DP4A) {
|
||||
// Pascal cc 6.1/6.2 decode is bandwidth-bound on small SMs: 2 warps beat 4 for single-token.
|
||||
if (table_id == MMVQ_PARAMETERS_PASCAL_DP4A && ncols_dst == 1) {
|
||||
return 2;
|
||||
}
|
||||
switch (ncols_dst) {
|
||||
case 1:
|
||||
case 2:
|
||||
@@ -641,7 +651,7 @@ static constexpr __host__ __device__ bool mmvq_two_rows_ncols1(ggml_type type) {
|
||||
}
|
||||
|
||||
static constexpr __host__ __device__ int calc_rows_per_block(ggml_type type, int ncols_dst, int table_id, bool small_k = false, int nwarps = 1) {
|
||||
if (table_id == MMVQ_PARAMETERS_GENERIC || table_id == MMVQ_PARAMETERS_GCN || table_id == MMVQ_PARAMETERS_TURING || table_id == MMVQ_PARAMETERS_GB10 || table_id == MMVQ_PARAMETERS_RDNA1) {
|
||||
if (table_id == MMVQ_PARAMETERS_GENERIC || table_id == MMVQ_PARAMETERS_PASCAL_DP4A || table_id == MMVQ_PARAMETERS_GCN || table_id == MMVQ_PARAMETERS_TURING || table_id == MMVQ_PARAMETERS_GB10 || table_id == MMVQ_PARAMETERS_RDNA1) {
|
||||
switch (ncols_dst) {
|
||||
case 1:
|
||||
if (small_k) {
|
||||
@@ -650,7 +660,7 @@ static constexpr __host__ __device__ int calc_rows_per_block(ggml_type type, int
|
||||
if (table_id == MMVQ_PARAMETERS_GB10) {
|
||||
return type == GGML_TYPE_IQ2_S || type == GGML_TYPE_IQ3_S ? 2 : 1;
|
||||
}
|
||||
return (table_id == MMVQ_PARAMETERS_GENERIC || table_id == MMVQ_PARAMETERS_RDNA1) && mmvq_two_rows_ncols1(type) ? 2 : 1;
|
||||
return (table_id == MMVQ_PARAMETERS_GENERIC || table_id == MMVQ_PARAMETERS_PASCAL_DP4A || table_id == MMVQ_PARAMETERS_RDNA1) && mmvq_two_rows_ncols1(type) ? 2 : 1;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
@@ -904,10 +914,11 @@ static __global__ void mul_mat_vec_q(
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp[j][i] = warp_reduce_sum<warp_size>(tmp[j][i]);
|
||||
|
||||
tmp[j][i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp[j][i]) : warp_reduce_sum<warp_size>(tmp[j][i]);
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
tmp_gate[j][i] = warp_reduce_sum<warp_size>(tmp_gate[j][i]);
|
||||
tmp_gate[j][i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp_gate[j][i]) : warp_reduce_sum<warp_size>(tmp_gate[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1053,10 +1064,10 @@ static __global__ void mul_mat_vec_q_moe(
|
||||
// Warp-level reduction only - no shared memory needed
|
||||
#pragma unroll
|
||||
for (int i = 0; i < c_rows_per_block; ++i) {
|
||||
tmp[i] = warp_reduce_sum<warp_size>(tmp[i]);
|
||||
tmp[i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp[i]) : warp_reduce_sum<warp_size>(tmp[i]);
|
||||
if constexpr (has_fusion) {
|
||||
if (use_gate) {
|
||||
tmp_gate[i] = warp_reduce_sum<warp_size>(tmp_gate[i]);
|
||||
tmp_gate[i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp_gate[i]) : warp_reduce_sum<warp_size>(tmp_gate[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,8 +290,8 @@ static __global__ void rms_norm_back_f32(
|
||||
}
|
||||
|
||||
// sum up partial sums
|
||||
sum_xx = warp_reduce_sum(sum_xx);
|
||||
sum_xg = warp_reduce_sum(sum_xg);
|
||||
sum_xx = warp_reduce_sum<WARP_SIZE, (block_size > WARP_SIZE)>(sum_xx);
|
||||
sum_xg = warp_reduce_sum<WARP_SIZE, (block_size > WARP_SIZE)>(sum_xg);
|
||||
if constexpr (block_size > WARP_SIZE) {
|
||||
static_assert(block_size == 1024, "unexpected block_size");
|
||||
__shared__ float s_sum_xx[32];
|
||||
|
||||
+311
-125
@@ -16,6 +16,18 @@ static __device__ __forceinline__ float4 quantize_load4(const src_t * x, const i
|
||||
}
|
||||
}
|
||||
|
||||
// 2 consecutive values of x as float2, x is aligned to 2 values
|
||||
template <typename src_t>
|
||||
static __device__ __forceinline__ float2 quantize_load2(const src_t * x) {
|
||||
if constexpr (std::is_same_v<src_t, nv_bfloat16>) {
|
||||
__align__(4) nv_bfloat162 v;
|
||||
ggml_cuda_memcpy_1<sizeof(v)>(&v, x);
|
||||
return ggml_cuda_cast<float2>(v);
|
||||
} else {
|
||||
return *(const float2 *) x;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(BLACKWELL_MMA_AVAILABLE)
|
||||
// this maps to 256-bit loads in PTX on supported devices,
|
||||
// and otherwise falls back to 2 128-bit loads
|
||||
@@ -42,10 +54,14 @@ static __device__ __forceinline__ decltype(auto) quantize_load8(const src_t * x)
|
||||
}
|
||||
|
||||
#if CUDART_VERSION >= 12080
|
||||
static __device__ __forceinline__ float nvfp4_native_scale_error(
|
||||
const float vals[QK_NVFP4_SUB], const float inv_col_scale, const float inv_scale, const float scale) {
|
||||
const float scale_dequant = 2.0f * scale;
|
||||
float err = 0.0f;
|
||||
// The squared errors of the 16 values (times inv_col_scale) for each of the n scales. The n sums do not depend on each other, so they run in parallel.
|
||||
template <int n>
|
||||
static __device__ __forceinline__ void nvfp4_native_scale_error(
|
||||
const float vals[QK_NVFP4_SUB], const float inv_col_scale, const float (&inv_scale)[n], const float (&scale)[n], float (&err)[n]) {
|
||||
#pragma unroll
|
||||
for (int c = 0; c < n; ++c) {
|
||||
err[c] = 0.0f;
|
||||
}
|
||||
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; k += 4) {
|
||||
@@ -54,30 +70,33 @@ static __device__ __forceinline__ float nvfp4_native_scale_error(
|
||||
const float v2 = vals[k + 2] * inv_col_scale;
|
||||
const float v3 = vals[k + 3] * inv_col_scale;
|
||||
|
||||
const __nv_fp4x4_e2m1 q(make_float4(v0 * inv_scale, v1 * inv_scale, v2 * inv_scale, v3 * inv_scale));
|
||||
const __nv_fp4x4_storage_t q_storage = q.__x;
|
||||
const __nv_fp4x2_storage_t q_lo = static_cast<__nv_fp4x2_storage_t>(q_storage);
|
||||
const __nv_fp4x2_storage_t q_hi = static_cast<__nv_fp4x2_storage_t>(q_storage >> 8U);
|
||||
#pragma unroll
|
||||
for (int c = 0; c < n; ++c) {
|
||||
const float scale_dequant = 2.0f * scale[c];
|
||||
|
||||
const __half2_raw hraw2_lo = __nv_cvt_fp4x2_to_halfraw2(q_lo, __NV_E2M1);
|
||||
const __half2_raw hraw2_hi = __nv_cvt_fp4x2_to_halfraw2(q_hi, __NV_E2M1);
|
||||
const __half2 h2_lo = static_cast<__half2>(hraw2_lo);
|
||||
const __half2 h2_hi = static_cast<__half2>(hraw2_hi);
|
||||
const float2 dq_lo = __half22float2(h2_lo);
|
||||
const float2 dq_hi = __half22float2(h2_hi);
|
||||
const __nv_fp4x4_e2m1 q(make_float4(v0 * inv_scale[c], v1 * inv_scale[c], v2 * inv_scale[c], v3 * inv_scale[c]));
|
||||
const __nv_fp4x4_storage_t q_storage = q.__x;
|
||||
const __nv_fp4x2_storage_t q_lo = static_cast<__nv_fp4x2_storage_t>(q_storage);
|
||||
const __nv_fp4x2_storage_t q_hi = static_cast<__nv_fp4x2_storage_t>(q_storage >> 8U);
|
||||
|
||||
const float err0 = fabsf(v0) - fabsf(dq_lo.x) * scale_dequant;
|
||||
const float err1 = fabsf(v1) - fabsf(dq_lo.y) * scale_dequant;
|
||||
const float err2 = fabsf(v2) - fabsf(dq_hi.x) * scale_dequant;
|
||||
const float err3 = fabsf(v3) - fabsf(dq_hi.y) * scale_dequant;
|
||||
const __half2_raw hraw2_lo = __nv_cvt_fp4x2_to_halfraw2(q_lo, __NV_E2M1);
|
||||
const __half2_raw hraw2_hi = __nv_cvt_fp4x2_to_halfraw2(q_hi, __NV_E2M1);
|
||||
const __half2 h2_lo = static_cast<__half2>(hraw2_lo);
|
||||
const __half2 h2_hi = static_cast<__half2>(hraw2_hi);
|
||||
const float2 dq_lo = __half22float2(h2_lo);
|
||||
const float2 dq_hi = __half22float2(h2_hi);
|
||||
|
||||
err = fmaf(err0, err0, err);
|
||||
err = fmaf(err1, err1, err);
|
||||
err = fmaf(err2, err2, err);
|
||||
err = fmaf(err3, err3, err);
|
||||
const float err0 = fabsf(v0) - fabsf(dq_lo.x) * scale_dequant;
|
||||
const float err1 = fabsf(v1) - fabsf(dq_lo.y) * scale_dequant;
|
||||
const float err2 = fabsf(v2) - fabsf(dq_hi.x) * scale_dequant;
|
||||
const float err3 = fabsf(v3) - fabsf(dq_hi.y) * scale_dequant;
|
||||
|
||||
err[c] = fmaf(err0, err0, err[c]);
|
||||
err[c] = fmaf(err1, err1, err[c]);
|
||||
err[c] = fmaf(err2, err2, err[c]);
|
||||
err[c] = fmaf(err3, err3, err[c]);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
#endif // defined(BLACKWELL_MMA_AVAILABLE)
|
||||
@@ -122,7 +141,7 @@ static __global__ void quantize_q8_1(
|
||||
const float d = amax / 127.0f;
|
||||
const int8_t q = amax == 0.0f ? 0 : roundf(xi / d);
|
||||
|
||||
const int sum = warp_reduce_sum<QK8_1>((int) q);
|
||||
const int sum = warp_reduce_sum<QK8_1, true>((int) q);
|
||||
|
||||
y[ib].qs[iqs] = q;
|
||||
|
||||
@@ -156,6 +175,119 @@ __device__ __forceinline__ uint8_t compute_e8m0_scale(float amax) {
|
||||
return static_cast<uint8_t>(biased);
|
||||
}
|
||||
|
||||
#if defined(BLACKWELL_MMA_AVAILABLE)
|
||||
// Quantizes 16 values divided by col_scale to E2M1 with the UE4M3 scale of the lowest squared error of 5 candidates, returns the scale code.
|
||||
// q0 and q1 get the 8 bytes of block_nvfp4: byte i holds the values i and i + 8 in its low and high nibble.
|
||||
static __device__ __forceinline__ uint8_t quantize_nvfp4_subblock(
|
||||
const float (&vals)[QK_NVFP4_SUB], const float col_scale, uint32_t & q0, uint32_t & q1) {
|
||||
const float inv_col_scale = col_scale > 0.0f ? 1.0f / col_scale : 0.0f;
|
||||
q0 = 0;
|
||||
q1 = 0;
|
||||
|
||||
float amax_sub = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
amax_sub = fmaxf(amax_sub, fabsf(vals[k] * inv_col_scale));
|
||||
}
|
||||
|
||||
static constexpr int test_offsets[5] = { 0, -1, 1, -2, 2 };
|
||||
const int first_fp8_code = (int) ggml_cuda_fp32_to_ue4m3(amax_sub / 6.0f);
|
||||
|
||||
uint8_t fp8_code = (uint8_t) first_fp8_code;
|
||||
float subblock_scale = ggml_cuda_ue4m3_to_fp32(fp8_code);
|
||||
#if CUDART_VERSION >= 12080
|
||||
// the errors of all candidates at once, then compared in order; codes out of range are skipped
|
||||
bool valid[5];
|
||||
float test_scale[5];
|
||||
float test_inv_scale[5];
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const int test_code = first_fp8_code + test_offsets[i];
|
||||
valid[i] = i == 0 || (test_code >= 0 && test_code <= 0x7e);
|
||||
test_scale[i] = ggml_cuda_ue4m3_to_fp32((uint8_t) (valid[i] ? test_code : first_fp8_code));
|
||||
test_inv_scale[i] = test_scale[i] > 0.0f ? 0.5f / test_scale[i] : 0.0f;
|
||||
}
|
||||
float err[5];
|
||||
nvfp4_native_scale_error(vals, inv_col_scale, test_inv_scale, test_scale, err);
|
||||
|
||||
float best_err = err[0];
|
||||
#pragma unroll
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
if (valid[i] && err[i] < best_err) {
|
||||
best_err = err[i];
|
||||
fp8_code = (uint8_t) (first_fp8_code + test_offsets[i]);
|
||||
subblock_scale = test_scale[i];
|
||||
}
|
||||
}
|
||||
#else
|
||||
float inv_scale_err = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
float best_err = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
const float v = vals[k] * inv_col_scale;
|
||||
const uint8_t q = ggml_cuda_float_to_fp4_e2m1(v, inv_scale_err);
|
||||
const float err_diff = fabsf(v) - fabsf(kvalues_fp4[q & 0x7]) * subblock_scale;
|
||||
best_err = fmaf(err_diff, err_diff, best_err);
|
||||
}
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
const int test_code = first_fp8_code + test_offsets[i];
|
||||
if (test_code < 0 || test_code > 0x7e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const float test_scale = ggml_cuda_ue4m3_to_fp32((uint8_t) test_code);
|
||||
const float test_inv_scale = test_scale > 0.0f ? 0.5f / test_scale : 0.0f;
|
||||
float cur_err = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
const float v = vals[k] * inv_col_scale;
|
||||
const uint8_t q = ggml_cuda_float_to_fp4_e2m1(v, test_inv_scale);
|
||||
const float err_diff = fabsf(v) - fabsf(kvalues_fp4[q & 0x7]) * test_scale;
|
||||
cur_err = fmaf(err_diff, err_diff, cur_err);
|
||||
}
|
||||
|
||||
if (cur_err < best_err) {
|
||||
best_err = cur_err;
|
||||
fp8_code = (uint8_t) test_code;
|
||||
subblock_scale = test_scale;
|
||||
}
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
#if CUDART_VERSION >= 12080
|
||||
const float inv_scale = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
const float s = inv_col_scale * inv_scale;
|
||||
|
||||
__nv_fp4x4_e2m1 q0_lo(make_float4(vals[0] * s, vals[8] * s, vals[1] * s, vals[9] * s));
|
||||
__nv_fp4x4_e2m1 q0_hi(make_float4(vals[2] * s, vals[10] * s, vals[3] * s, vals[11] * s));
|
||||
__nv_fp4x4_e2m1 q1_lo(make_float4(vals[4] * s, vals[12] * s, vals[5] * s, vals[13] * s));
|
||||
__nv_fp4x4_e2m1 q1_hi(make_float4(vals[6] * s, vals[14] * s, vals[7] * s, vals[15] * s));
|
||||
|
||||
const char2 q0_lo_c = *reinterpret_cast<char2 *>(&q0_lo);
|
||||
const char2 q0_hi_c = *reinterpret_cast<char2 *>(&q0_hi);
|
||||
const char2 q1_lo_c = *reinterpret_cast<char2 *>(&q1_lo);
|
||||
const char2 q1_hi_c = *reinterpret_cast<char2 *>(&q1_hi);
|
||||
|
||||
q0 = uint32_t(uint8_t(q0_lo_c.x)) | (uint32_t(uint8_t(q0_lo_c.y)) << 8) |
|
||||
(uint32_t(uint8_t(q0_hi_c.x)) << 16) | (uint32_t(uint8_t(q0_hi_c.y)) << 24);
|
||||
q1 = uint32_t(uint8_t(q1_lo_c.x)) | (uint32_t(uint8_t(q1_lo_c.y)) << 8) |
|
||||
(uint32_t(uint8_t(q1_hi_c.x)) << 16) | (uint32_t(uint8_t(q1_hi_c.y)) << 24);
|
||||
#else
|
||||
const float inv_scale = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB / 4; ++k) {
|
||||
q0 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 0] * inv_col_scale, inv_scale)) << (8 * k);
|
||||
q0 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 8] * inv_col_scale, inv_scale)) << (8 * k + 4);
|
||||
q1 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 4] * inv_col_scale, inv_scale)) << (8 * k);
|
||||
q1 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 12] * inv_col_scale, inv_scale)) << (8 * k + 4);
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
|
||||
return fp8_code;
|
||||
}
|
||||
#endif // defined(BLACKWELL_MMA_AVAILABLE)
|
||||
|
||||
// scatter: grid over tokens, quantize once, write to all the token's compact rows
|
||||
template <typename src_t, bool scatter, bool use_aligned_float8>
|
||||
static __global__ void quantize_mmq_nvfp4(
|
||||
@@ -232,7 +364,6 @@ static __global__ void quantize_mmq_nvfp4(
|
||||
const int sub = (i0_base % QK_FP4_MMQ) / QK_NVFP4_SUB;
|
||||
|
||||
const float row_scale = warp_amax[0];
|
||||
const float inv_col_scale = row_scale > 0.0f ? 1.0f / row_scale : 0.0f;
|
||||
|
||||
float vals[QK_NVFP4_SUB];
|
||||
if constexpr (use_aligned_float8) {
|
||||
@@ -251,90 +382,9 @@ static __global__ void quantize_mmq_nvfp4(
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t q0 = 0;
|
||||
uint32_t q1 = 0;
|
||||
|
||||
float amax_sub = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
amax_sub = fmaxf(amax_sub, fabsf(vals[k] * inv_col_scale));
|
||||
}
|
||||
|
||||
static constexpr int test_offsets[5] = { 0, -1, 1, -2, 2 };
|
||||
const int first_fp8_code = (int) ggml_cuda_fp32_to_ue4m3(amax_sub / 6.0f);
|
||||
|
||||
uint8_t fp8_code = (uint8_t) first_fp8_code;
|
||||
float subblock_scale = ggml_cuda_ue4m3_to_fp32(fp8_code);
|
||||
float inv_scale_err = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
#if CUDART_VERSION >= 12080
|
||||
float best_err = nvfp4_native_scale_error(vals, inv_col_scale, inv_scale_err, subblock_scale);
|
||||
#else
|
||||
float best_err = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
const float v = vals[k] * inv_col_scale;
|
||||
const uint8_t q = ggml_cuda_float_to_fp4_e2m1(v, inv_scale_err);
|
||||
const float err_diff = fabsf(v) - fabsf(kvalues_fp4[q & 0x7]) * subblock_scale;
|
||||
best_err = fmaf(err_diff, err_diff, best_err);
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
const int test_code = first_fp8_code + test_offsets[i];
|
||||
if (test_code < 0 || test_code > 0x7e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const float test_scale = ggml_cuda_ue4m3_to_fp32((uint8_t) test_code);
|
||||
const float test_inv_scale = test_scale > 0.0f ? 0.5f / test_scale : 0.0f;
|
||||
#if CUDART_VERSION >= 12080
|
||||
const float cur_err = nvfp4_native_scale_error(vals, inv_col_scale, test_inv_scale, test_scale);
|
||||
#else
|
||||
float cur_err = 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; ++k) {
|
||||
const float v = vals[k] * inv_col_scale;
|
||||
const uint8_t q = ggml_cuda_float_to_fp4_e2m1(v, test_inv_scale);
|
||||
const float err_diff = fabsf(v) - fabsf(kvalues_fp4[q & 0x7]) * test_scale;
|
||||
cur_err = fmaf(err_diff, err_diff, cur_err);
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
|
||||
if (cur_err < best_err) {
|
||||
best_err = cur_err;
|
||||
fp8_code = (uint8_t) test_code;
|
||||
subblock_scale = test_scale;
|
||||
}
|
||||
}
|
||||
#if CUDART_VERSION >= 12080
|
||||
const float inv_scale = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
const float s = inv_col_scale * inv_scale;
|
||||
|
||||
__nv_fp4x4_e2m1 q0_lo(make_float4(vals[0] * s, vals[8] * s, vals[1] * s, vals[9] * s));
|
||||
__nv_fp4x4_e2m1 q0_hi(make_float4(vals[2] * s, vals[10] * s, vals[3] * s, vals[11] * s));
|
||||
__nv_fp4x4_e2m1 q1_lo(make_float4(vals[4] * s, vals[12] * s, vals[5] * s, vals[13] * s));
|
||||
__nv_fp4x4_e2m1 q1_hi(make_float4(vals[6] * s, vals[14] * s, vals[7] * s, vals[15] * s));
|
||||
|
||||
const char2 q0_lo_c = *reinterpret_cast<char2 *>(&q0_lo);
|
||||
const char2 q0_hi_c = *reinterpret_cast<char2 *>(&q0_hi);
|
||||
const char2 q1_lo_c = *reinterpret_cast<char2 *>(&q1_lo);
|
||||
const char2 q1_hi_c = *reinterpret_cast<char2 *>(&q1_hi);
|
||||
|
||||
q0 = uint32_t(uint8_t(q0_lo_c.x)) | (uint32_t(uint8_t(q0_lo_c.y)) << 8) |
|
||||
(uint32_t(uint8_t(q0_hi_c.x)) << 16) | (uint32_t(uint8_t(q0_hi_c.y)) << 24);
|
||||
q1 = uint32_t(uint8_t(q1_lo_c.x)) | (uint32_t(uint8_t(q1_lo_c.y)) << 8) |
|
||||
(uint32_t(uint8_t(q1_hi_c.x)) << 16) | (uint32_t(uint8_t(q1_hi_c.y)) << 24);
|
||||
#else
|
||||
const float inv_scale = subblock_scale > 0.0f ? 0.5f / subblock_scale : 0.0f;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB / 4; ++k) {
|
||||
q0 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 0] * inv_col_scale, inv_scale)) << (8 * k);
|
||||
q0 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 8] * inv_col_scale, inv_scale)) << (8 * k + 4);
|
||||
q1 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 4] * inv_col_scale, inv_scale)) << (8 * k);
|
||||
q1 |= uint32_t(ggml_cuda_float_to_fp4_e2m1(vals[k + 12] * inv_col_scale, inv_scale)) << (8 * k + 4);
|
||||
}
|
||||
#endif // CUDART_VERSION >= 12080
|
||||
uint32_t q0;
|
||||
uint32_t q1;
|
||||
const uint8_t fp8_code = quantize_nvfp4_subblock(vals, row_scale, q0, q1);
|
||||
|
||||
if constexpr (scatter) {
|
||||
#pragma unroll
|
||||
@@ -662,8 +712,8 @@ void quantize_mmq_q8_1_cuda(
|
||||
});
|
||||
}
|
||||
|
||||
// Stores the 4 values xi of a thread, values [iu, iu + 4) of column g in a unit of 256 values, in the column group yg of the unit, see quantize.cuh for the layout.
|
||||
template <mmq_q8_1_ds_layout ds_layout>
|
||||
// Stores the 4 values xi of a thread, values [iu, iu + 4) of column g in a unit of 256 values, in the column group yg of the unit, see quantize.cuh for the layouts.
|
||||
template <mmq_q8_1_ds_layout ds_layout, bool wmma>
|
||||
static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, int4 * yg, const int iu, const int g) {
|
||||
// the 32 values of a sub-block are held by 8 threads
|
||||
float amax = fmaxf(fmaxf(fabsf(xi.x), fabsf(xi.y)), fmaxf(fabsf(xi.z), fabsf(xi.w)));
|
||||
@@ -680,11 +730,25 @@ static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, i
|
||||
// as in quantize_mmq_q8_1: the sum of the quantized values; the int warp_reduce_sum reduces the whole warp on Ampere+
|
||||
[[maybe_unused]] float sum = 0.0f;
|
||||
if constexpr (ds_layout != MMQ_Q8_1_DS_LAYOUT_D4) {
|
||||
sum = d*warp_reduce_sum<8>(float(q.x + q.y + q.z + q.w));
|
||||
sum = d*warp_reduce_sum<8, true>(float(q.x + q.y + q.z + q.w));
|
||||
}
|
||||
|
||||
const int s = iu / QK8_1; // sub-block
|
||||
const int k = iu % QK8_1; // first value in sub-block
|
||||
|
||||
if constexpr (wmma) {
|
||||
((int *) yg)[(s*MMQ_FEW_WMMA_NCOLS + g)*8 + k/4] = *(const int *) &q;
|
||||
if (k == 0) {
|
||||
int * ds = (int *) (yg + 8*MMQ_FEW_WMMA_NCOLS*2) + (s*2 + g % 2)*8 + g/2;
|
||||
if constexpr (ds_layout == MMQ_Q8_1_DS_LAYOUT_D4) {
|
||||
*(float *) ds = d;
|
||||
} else {
|
||||
*(half2 *) ds = make_half2(d, sum);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
((int *) (yg + (s/2)*WARP_SIZE + 4*g + (k % 16)/4))[2*(s % 2) + k/16] = *(const int *) &q;
|
||||
if (k == 0) {
|
||||
int4 * ds = yg + 4*WARP_SIZE + 4*(g/2) + s/2;
|
||||
@@ -696,8 +760,9 @@ static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, i
|
||||
}
|
||||
}
|
||||
|
||||
// Each thread quantizes 4 values of one column, see quantize.cuh for the layout.
|
||||
template <typename src_t, mmq_q8_1_ds_layout ds_layout>
|
||||
// Each thread quantizes 4 values of one column, see quantize.cuh for the layouts.
|
||||
// nvfp4_order: the 4 values of a thread are 2m, 2m + 8, 2m + 1, 2m + 9 of 16 values, the values of 2 bytes of block_nvfp4.
|
||||
template <typename src_t, mmq_q8_1_ds_layout ds_layout, bool wmma, bool nvfp4_order>
|
||||
static __global__ void quantize_mmq_few_q8_1(
|
||||
const src_t * x_ptr, void * vy_ptr, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int ne1, const int ne2) {
|
||||
@@ -713,11 +778,30 @@ static __global__ void quantize_mmq_few_q8_1(
|
||||
|
||||
const int64_t i2 = blockIdx.z % ne2;
|
||||
const int64_t i3 = blockIdx.z / ne2;
|
||||
const float4 xi = (int) blockIdx.x < ne1 ? quantize_load4(x + i3*s03 + i2*s02 + blockIdx.x*s01 + i0, 0) : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
static_assert(!(wmma && nvfp4_order), "the WMMA layout has no nvfp4 order");
|
||||
float4 xi = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
if ((int) blockIdx.x < ne1) {
|
||||
const src_t * xc = x + i3*s03 + i2*s02 + blockIdx.x*s01;
|
||||
if constexpr (nvfp4_order) {
|
||||
const int64_t i16 = i0 - i0 % 16 + 2*((i0 % 16)/4);
|
||||
const float2 lo = quantize_load2(xc + i16);
|
||||
const float2 hi = quantize_load2(xc + i16 + 8);
|
||||
xi = make_float4(lo.x, hi.x, lo.y, hi.y);
|
||||
} else {
|
||||
xi = quantize_load4(xc + i0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (wmma) {
|
||||
const int m = blockIdx.x % MMQ_FEW_WMMA_NCOLS; // column in group
|
||||
int4 * yg = vy + ((blockIdx.z*(ne00/QK_K) + i0/QK_K)*(gridDim.x/MMQ_FEW_WMMA_NCOLS) + blockIdx.x/MMQ_FEW_WMMA_NCOLS)*MMQ_FEW_WMMA_Q8_1_INT4;
|
||||
quantize_mmq_few_store<ds_layout, true>(xi, yg, i0 % QK_K, m);
|
||||
return;
|
||||
}
|
||||
|
||||
const int g = blockIdx.x % MMQ_FEW_NCOLS; // column in group
|
||||
int4 * yg = vy + ((blockIdx.z*(ne00/QK_K) + i0/QK_K)*(gridDim.x/MMQ_FEW_NCOLS) + blockIdx.x/MMQ_FEW_NCOLS)*MMQ_FEW_Q8_1_INT4;
|
||||
quantize_mmq_few_store<ds_layout>(xi, yg, i0 % QK_K, g);
|
||||
quantize_mmq_few_store<ds_layout, false>(xi, yg, i0 % QK_K, g);
|
||||
}
|
||||
|
||||
// MUL_MAT_ID: block x is the (token, slot) entry, ids are as in mm_ids_helper. Each block finds the pair of its entry in shared memory, block (0, 0) also writes all pairs.
|
||||
@@ -807,26 +891,34 @@ static __global__ void quantize_mmq_few_id_q8_1(
|
||||
|
||||
const int r = rank(blockIdx.x, e);
|
||||
int4 * yg = vy + (int64_t(pair0[e] + r/MMQ_FEW_NCOLS)*(ne00/QK_K) + i0/QK_K)*MMQ_FEW_Q8_1_INT4;
|
||||
quantize_mmq_few_store<ds_layout>(xi, yg, i0 % QK_K, r % MMQ_FEW_NCOLS);
|
||||
quantize_mmq_few_store<ds_layout, false>(xi, yg, i0 % QK_K, r % MMQ_FEW_NCOLS);
|
||||
}
|
||||
|
||||
template <typename src_t>
|
||||
static void quantize_mmq_few_q8_1_cuda(
|
||||
const src_t * x, void * vy, const mmq_q8_1_ds_layout ds_layout, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
template <bool wmma, typename src_t>
|
||||
static void quantize_mmq_few_q8_1_launch(
|
||||
const src_t * x, void * vy, const mmq_q8_1_ds_layout ds_layout, const bool nvfp4_order, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
||||
GGML_ASSERT(ne00 % QK_K == 0);
|
||||
GGML_ASSERT(!nvfp4_order || (ds_layout == MMQ_Q8_1_DS_LAYOUT_D4 && !wmma));
|
||||
|
||||
const int64_t block_num_y = (ne00 + 4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ - 1) / (4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ);
|
||||
const dim3 num_blocks(GGML_PAD(ne1, MMQ_FEW_NCOLS), block_num_y, ne2*ne3);
|
||||
const dim3 num_blocks(GGML_PAD(ne1, wmma ? MMQ_FEW_WMMA_NCOLS : MMQ_FEW_NCOLS), block_num_y, ne2*ne3);
|
||||
const dim3 block_size(CUDA_QUANTIZE_BLOCK_SIZE_MMQ, 1, 1);
|
||||
const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params(num_blocks, block_size, 0, stream);
|
||||
if constexpr (!wmma) {
|
||||
if (nvfp4_order) {
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_D4, false, true>, launch_params,
|
||||
x, vy, ne00, s01, s02, s03, (int) ne1, (int) ne2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (ds_layout) {
|
||||
case MMQ_Q8_1_DS_LAYOUT_D4:
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_D4>, launch_params,
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_D4, wmma, false>, launch_params,
|
||||
x, vy, ne00, s01, s02, s03, (int) ne1, (int) ne2);
|
||||
break;
|
||||
case MMQ_Q8_1_DS_LAYOUT_DS4:
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_DS4>, launch_params,
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_DS4, wmma, false>, launch_params,
|
||||
x, vy, ne00, s01, s02, s03, (int) ne1, (int) ne2);
|
||||
break;
|
||||
default:
|
||||
@@ -834,11 +926,105 @@ static void quantize_mmq_few_q8_1_cuda(
|
||||
}
|
||||
}
|
||||
|
||||
// Each thread quantizes one sub-block of 16 values like quantize_mmq_nvfp4, columns beyond ne1 are zero.
|
||||
// A CUDA block takes a chunk of the sub-blocks of one column, so each CUDA block first reads the whole column for the column scale.
|
||||
template <typename src_t>
|
||||
static __global__ void quantize_mmq_few_nvfp4(
|
||||
const src_t * x_ptr, void * vy_ptr, float * y_scale_ptr, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int ne1, const int ne2) {
|
||||
#if defined(BLACKWELL_MMA_AVAILABLE)
|
||||
ggml_cuda_pdl_lc();
|
||||
const src_t * GGML_CUDA_RESTRICT x = x_ptr;
|
||||
int * GGML_CUDA_RESTRICT vy = (int *) vy_ptr;
|
||||
float * GGML_CUDA_RESTRICT y_scale = y_scale_ptr;
|
||||
|
||||
const int col = blockIdx.x;
|
||||
const int64_t i2 = blockIdx.z % ne2;
|
||||
const int64_t i3 = blockIdx.z / ne2;
|
||||
const src_t * x_row = x + i3*s03 + i2*s02 + int64_t(col)*s01;
|
||||
|
||||
ggml_cuda_pdl_sync();
|
||||
|
||||
float amax = 0.0f;
|
||||
if (col < ne1) {
|
||||
for (int64_t i0 = 4*threadIdx.x; i0 < ne00; i0 += 4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ) {
|
||||
const float4 v = quantize_load4(x_row + i0, 0);
|
||||
amax = fmaxf(amax, fmaxf(fmaxf(fabsf(v.x), fabsf(v.y)), fmaxf(fabsf(v.z), fabsf(v.w))));
|
||||
}
|
||||
}
|
||||
__shared__ float amax_warp[CUDA_QUANTIZE_BLOCK_SIZE_MMQ/WARP_SIZE];
|
||||
amax = block_reduce<block_reduce_method::MAX, CUDA_QUANTIZE_BLOCK_SIZE_MMQ>(amax, amax_warp);
|
||||
|
||||
const float col_scale = amax / (6.0f * 448.0f);
|
||||
if (blockIdx.y == 0 && threadIdx.x == 0) {
|
||||
y_scale[blockIdx.z*gridDim.x + col] = col_scale;
|
||||
}
|
||||
|
||||
const int64_t isb = int64_t(blockIdx.y)*CUDA_QUANTIZE_BLOCK_SIZE_MMQ + threadIdx.x;
|
||||
if (isb >= ne00/QK_NVFP4_SUB) {
|
||||
return;
|
||||
}
|
||||
|
||||
float vals[QK_NVFP4_SUB] = {0.0f};
|
||||
if (col < ne1) {
|
||||
#pragma unroll
|
||||
for (int k = 0; k < QK_NVFP4_SUB; k += 4) {
|
||||
const float4 v = quantize_load4(x_row + isb*QK_NVFP4_SUB + k, 0);
|
||||
vals[k + 0] = v.x;
|
||||
vals[k + 1] = v.y;
|
||||
vals[k + 2] = v.z;
|
||||
vals[k + 3] = v.w;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t q[2];
|
||||
const uint8_t code = quantize_nvfp4_subblock(vals, col_scale, q[0], q[1]);
|
||||
|
||||
const int64_t kb = isb / (QK_NVFP4/QK_NVFP4_SUB); // block of 64 values
|
||||
const int sub = isb % (QK_NVFP4/QK_NVFP4_SUB);
|
||||
const int ib = kb % (QK_K/QK_NVFP4); // block in the unit of 256 values
|
||||
const int g = col % MMQ_FEW_NCOLS;
|
||||
int * yg = vy + 4*(((blockIdx.z*(ne00/QK_K) + kb/(QK_K/QK_NVFP4))*(gridDim.x/MMQ_FEW_NCOLS) + col/MMQ_FEW_NCOLS)*MMQ_FEW_FP4_INT4);
|
||||
#pragma unroll
|
||||
for (int h = 0; h < 2; ++h) {
|
||||
const int i = 2*sub + h; // int of the block
|
||||
yg[4*((ib/2)*WARP_SIZE + 4*g + i % 4) + 2*(ib % 2) + i/4] = q[h];
|
||||
}
|
||||
((uint8_t *) (yg + 4*(2*WARP_SIZE + g) + ib))[sub] = code;
|
||||
#else
|
||||
GGML_UNUSED_VARS(x_ptr, vy_ptr, y_scale_ptr, ne00, s01, s02, s03, ne1, ne2);
|
||||
NO_DEVICE_CODE;
|
||||
#endif // defined(BLACKWELL_MMA_AVAILABLE)
|
||||
}
|
||||
|
||||
void quantize_mmq_few_nvfp4_cuda(
|
||||
const void * x, const ggml_type type_src1, void * vy, float * y_scale, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
||||
GGML_ASSERT(ne00 % QK_K == 0);
|
||||
|
||||
const int64_t nsub = ne00 / QK_NVFP4_SUB;
|
||||
const dim3 num_blocks(GGML_PAD(ne1, MMQ_FEW_NCOLS), (nsub + CUDA_QUANTIZE_BLOCK_SIZE_MMQ - 1) / CUDA_QUANTIZE_BLOCK_SIZE_MMQ, ne2*ne3);
|
||||
const dim3 block_size(CUDA_QUANTIZE_BLOCK_SIZE_MMQ, 1, 1);
|
||||
const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params(num_blocks, block_size, 0, stream);
|
||||
quantize_launch_typed(x, type_src1, [&](auto * x_t) {
|
||||
using src_t = std::remove_cv_t<std::remove_pointer_t<decltype(x_t)>>;
|
||||
ggml_cuda_kernel_launch(quantize_mmq_few_nvfp4<src_t>, launch_params, x_t, vy, y_scale, ne00, s01, s02, s03, (int) ne1, (int) ne2);
|
||||
});
|
||||
}
|
||||
|
||||
void quantize_mmq_few_q8_1_cuda(
|
||||
const void * x, const ggml_type type_src1, void * vy, const mmq_q8_1_ds_layout ds_layout, const bool nvfp4_order, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
||||
quantize_launch_typed(x, type_src1, [&](auto * x_t) {
|
||||
quantize_mmq_few_q8_1_launch<false>(x_t, vy, ds_layout, nvfp4_order, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
|
||||
});
|
||||
}
|
||||
|
||||
void quantize_mmq_few_wmma_q8_1_cuda(
|
||||
const void * x, const ggml_type type_src1, void * vy, const mmq_q8_1_ds_layout ds_layout, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
|
||||
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
|
||||
quantize_launch_typed(x, type_src1, [&](auto * x_t) {
|
||||
quantize_mmq_few_q8_1_cuda(x_t, vy, ds_layout, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
|
||||
quantize_mmq_few_q8_1_launch<true>(x_t, vy, ds_layout, /*nvfp4_order =*/ false, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,21 @@ void quantize_mmq_q8_1_cuda(
|
||||
static constexpr int MMQ_FEW_NCOLS = 8; // src1 columns per column group
|
||||
static constexpr int MMQ_FEW_Q8_1_INT4 = 4*WARP_SIZE + 4*4; // int4 per 256 values and column group
|
||||
|
||||
// nvfp4_order: the value order of block_nvfp4 within 16 values, see quantize_mmq_few_q8_1.
|
||||
void quantize_mmq_few_q8_1_cuda(
|
||||
const void * x, ggml_type type_src1, void * vy, mmq_q8_1_ds_layout ds_layout, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
||||
const void * x, ggml_type type_src1, void * vy, mmq_q8_1_ds_layout ds_layout, bool nvfp4_order, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
||||
int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
||||
|
||||
// src1 of the few-row MMQ for NVFP4 src0 with 4-bit src1 (Blackwell), quantized like quantize_mmq_nvfp4: a float scale per column, E2M1 values with a UE4M3 scale per 16 values.
|
||||
// A 64 value block has the block_nvfp4 layout: 8 ints of packed values and an int of 4 scales. The values of int i are k = 8i .. 8i + 7 of the m16n8k64 MMA.
|
||||
// Per channel, 256 values and column group:
|
||||
// qs: int4[2][32], [h][lane] holds the B fragments of the blocks 2h and 2h+1 of lane (g, t): ints t and t + 4 of column g.
|
||||
// sc: int4[8], [g] holds the scales of the 4 blocks of column g.
|
||||
// The column scales are a float array per channel, ne1 padded to a multiple of MMQ_FEW_NCOLS.
|
||||
static constexpr int MMQ_FEW_FP4_INT4 = 2*WARP_SIZE + MMQ_FEW_NCOLS; // int4 per 256 values and column group
|
||||
|
||||
void quantize_mmq_few_nvfp4_cuda(
|
||||
const void * x, ggml_type type_src1, void * vy, float * y_scale, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
||||
int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
||||
|
||||
// MUL_MAT_ID: a pair is an expert and one column group of up to MMQ_FEW_NCOLS of its (token, slot) entries. The src1 of pair p is channel p above, its columns past the entries are not written.
|
||||
@@ -42,6 +55,17 @@ void quantize_mmq_few_id_q8_1_cuda(
|
||||
const void * x, ggml_type type_src1, const int32_t * ids, void * vy, int * pairs, mmq_q8_1_ds_layout ds_layout, int64_t ne00, int64_t s11, int64_t s12,
|
||||
int64_t ne11, int64_t n_experts, int64_t n_expert_used, int64_t n_tokens, int64_t si1, int64_t npairs_max, cudaStream_t stream);
|
||||
|
||||
// src1 of the few-row MMQ for RDNA3 WMMA, which multiplies 16 src1 columns and needs the same A and B data in both half-warps.
|
||||
// Per channel, 256 values and group of MMQ_FEW_WMMA_NCOLS columns:
|
||||
// qs: int4[8][16][2], [s][m][k] holds the values [16k, 16k + 16) of sub-block s of column m, the A fragments of lanes m and m + 16.
|
||||
// ds: int4[8][2][2], [s][h][k] holds d (D4, float) or (d, sum) (DS4, half2) of sub-block s of the columns 2v + h, v = 4k .. 4k + 3.
|
||||
static constexpr int MMQ_FEW_WMMA_NCOLS = 16;
|
||||
static constexpr int MMQ_FEW_WMMA_Q8_1_INT4 = 8*16*2 + 8*2*2;
|
||||
|
||||
void quantize_mmq_few_wmma_q8_1_cuda(
|
||||
const void * x, ggml_type type_src1, void * vy, mmq_q8_1_ds_layout ds_layout, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
|
||||
int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
|
||||
|
||||
void quantize_mmq_fp4_cuda(const void * x,
|
||||
ggml_type type_src1,
|
||||
const int32_t * ids,
|
||||
|
||||
@@ -33,6 +33,27 @@ static __device__ __forceinline__ float reduce_row_f32(const float * x, const in
|
||||
return sum;
|
||||
}
|
||||
|
||||
#define CUDA_REDUCE_ROWS_SHORT_NCOLS 8
|
||||
|
||||
template <bool norm>
|
||||
static __global__ void reduce_rows_f32_short(const float * x_ptr, float * dst_ptr, const int ncols, const int64_t nrows) {
|
||||
const int64_t row = (int64_t) blockIdx.x*blockDim.x + threadIdx.x;
|
||||
|
||||
ggml_cuda_pdl_sync();
|
||||
if (row >= nrows) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float * GGML_CUDA_RESTRICT x = x_ptr + row*ncols;
|
||||
|
||||
float sum = 0.0f;
|
||||
for (int i = 0; i < ncols; ++i) {
|
||||
sum += x[i];
|
||||
}
|
||||
|
||||
dst_ptr[row] = norm ? sum / ncols : sum;
|
||||
}
|
||||
|
||||
// Row reduction kernel template - compute sum (norm=false) or mean (norm=true)
|
||||
template <bool norm>
|
||||
static __global__ void reduce_rows_f32(const float * x_ptr, float * dst_ptr, const int ncols) {
|
||||
|
||||
@@ -142,6 +142,64 @@ static __global__ void soft_max_f32(
|
||||
}
|
||||
}
|
||||
|
||||
#define CUDA_SOFT_MAX_SHORT_NCOLS 8
|
||||
|
||||
template <typename T>
|
||||
static __global__ void soft_max_f32_short(
|
||||
const float * x, const T * mask, const float * sinks, float * dst, const soft_max_params p,
|
||||
const uint3 ne01_fdv, const uint3 ne02_fdv, const uint3 ne12_fdv, const uint3 ne13_fdv) {
|
||||
const uint32_t rowx = blockIdx.x*blockDim.x + threadIdx.x;
|
||||
if (rowx >= p.nrows_x) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t i012 = fastdiv(rowx, ne01_fdv);
|
||||
const uint32_t i01 = rowx - i012*ne01_fdv.z;
|
||||
const uint32_t i03 = fastdiv(i012, ne02_fdv);
|
||||
const uint32_t i02 = i012 - i03*ne02_fdv.z;
|
||||
|
||||
const uint32_t i12 = fastmodulo(i02, ne12_fdv);
|
||||
const uint32_t i13 = fastmodulo(i03, ne13_fdv);
|
||||
|
||||
const int ncols = p.ncols;
|
||||
|
||||
x += (int64_t) rowx*ncols;
|
||||
mask += (i01*p.nb11 + i12*p.nb12 + i13*p.nb13) / sizeof(T) * (mask != nullptr);
|
||||
dst += (int64_t) rowx*ncols;
|
||||
|
||||
const float slope = get_alibi_slope(p.max_bias, i02, p.n_head_log2, p.m0, p.m1);
|
||||
|
||||
float vals[CUDA_SOFT_MAX_SHORT_NCOLS];
|
||||
float max_val = sinks ? sinks[i02] : -INFINITY;
|
||||
|
||||
#pragma unroll
|
||||
for (int col = 0; col < CUDA_SOFT_MAX_SHORT_NCOLS; ++col) {
|
||||
if (col < ncols) {
|
||||
vals[col] = x[col]*p.scale + (mask ? slope*t2f32(mask[col]) : 0.0f);
|
||||
max_val = max(max_val, vals[col]);
|
||||
}
|
||||
}
|
||||
|
||||
float sum = sinks ? expf(sinks[i02] - max_val) : 0.0f;
|
||||
|
||||
#pragma unroll
|
||||
for (int col = 0; col < CUDA_SOFT_MAX_SHORT_NCOLS; ++col) {
|
||||
if (col < ncols) {
|
||||
vals[col] = expf(vals[col] - max_val);
|
||||
sum += vals[col];
|
||||
}
|
||||
}
|
||||
|
||||
const float inv_sum = 1.0f / sum;
|
||||
|
||||
#pragma unroll
|
||||
for (int col = 0; col < CUDA_SOFT_MAX_SHORT_NCOLS; ++col) {
|
||||
if (col < ncols) {
|
||||
dst[col] = vals[col]*inv_sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <int n_elem_per_thread = 0>
|
||||
static __device__ void soft_max_f32_parallelize_cols_single_row(const float * __restrict__ x,
|
||||
float * __restrict__ dst,
|
||||
@@ -392,6 +450,15 @@ static void soft_max_f32_cuda(const float * x,
|
||||
int nth = WARP_SIZE;
|
||||
const int64_t ncols_x = params.ncols;
|
||||
|
||||
if (ncols_x <= CUDA_SOFT_MAX_SHORT_NCOLS && params.nrows_x <= INT_MAX) {
|
||||
const uint3 ne01_fdv = init_fastdiv_values(params.ne01);
|
||||
const uint3 ne02_fdv = init_fastdiv_values(params.ne02);
|
||||
const uint3 ne12_fdv = init_fastdiv_values(params.ne12);
|
||||
const uint3 ne13_fdv = init_fastdiv_values(params.ne13);
|
||||
soft_max_f32_short<<<(params.nrows_x + 255) / 256, 256, 0, stream>>>(x, mask, sinks, dst, params, ne01_fdv, ne02_fdv, ne12_fdv, ne13_fdv);
|
||||
return;
|
||||
}
|
||||
|
||||
while (nth < ncols_x && nth < CUDA_SOFT_MAX_BLOCK_SIZE) nth *= 2;
|
||||
const dim3 block_dims(nth, 1, 1);
|
||||
const dim3 block_nums(params.ne01, params.ne02, params.ne03);
|
||||
|
||||
@@ -218,7 +218,7 @@ __global__ void __launch_bounds__(d_state, 1)
|
||||
}
|
||||
|
||||
// parallel accumulation for output
|
||||
state_sum = warp_reduce_sum(state_sum);
|
||||
state_sum = warp_reduce_sum<WARP_SIZE, true>(state_sum);
|
||||
|
||||
if (lane == 0) {
|
||||
y_warp[i * stride_y] = state_sum;
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
void sum_rows_f32_cuda(const float * x, float * dst, const int ncols, const int nrows, cudaStream_t stream) {
|
||||
const int id = ggml_cuda_get_device();
|
||||
const int nsm = ggml_cuda_info().devices[id].nsm;
|
||||
if (ncols <= CUDA_REDUCE_ROWS_SHORT_NCOLS) {
|
||||
const dim3 block_dims(256, 1, 1);
|
||||
const dim3 block_nums((nrows + 255) / 256, 1, 1);
|
||||
const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params(block_nums, block_dims, 0, stream);
|
||||
ggml_cuda_kernel_launch(reduce_rows_f32_short</*norm=*/false>, launch_params, x, dst, ncols, (int64_t) nrows);
|
||||
return;
|
||||
}
|
||||
const dim3 block_nums(nrows, 1, 1);
|
||||
if ((nrows / nsm) < 2) {
|
||||
const dim3 block_dims(512, 1, 1);
|
||||
|
||||
@@ -135,7 +135,11 @@ static void unary_cuda(const T * x, T * dst, const int k, cudaStream_t stream) {
|
||||
}
|
||||
|
||||
template <float (*op)(float), typename T>
|
||||
static __global__ void unary_op_kernel_strided(const T * x, T * dst, const int k,const int64_t ne00,const int64_t ne01,const int64_t ne02,const size_t nb00,const size_t nb01,const size_t nb02,const size_t nb03) {
|
||||
static __global__ void unary_op_kernel_strided(
|
||||
const T * x, T * dst, const int k,
|
||||
const int64_t ne00, const int64_t ne01, const int64_t ne02,
|
||||
const size_t nb00, const size_t nb01, const size_t nb02, const size_t nb03,
|
||||
const size_t nb0, const size_t nb1, const size_t nb2, const size_t nb3) {
|
||||
ggml_cuda_pdl_lc();
|
||||
const int i = blockDim.x*blockIdx.x + threadIdx.x;
|
||||
|
||||
@@ -149,17 +153,25 @@ static __global__ void unary_op_kernel_strided(const T * x, T * dst, const int k
|
||||
const int64_t i2 = rem % ne02;
|
||||
const int64_t i3 = rem / ne02;
|
||||
const size_t src_byte_offset = i0 * nb00 + i1 * nb01 + i2 * nb02 + i3 * nb03;
|
||||
const T * src_ptr = (const T *)((const char *)x + src_byte_offset);
|
||||
const size_t dst_byte_offset = i0 * nb0 + i1 * nb1 + i2 * nb2 + i3 * nb3;
|
||||
const T * src_ptr = (const T *)((const char *)x + src_byte_offset);
|
||||
T * dst_ptr = ( T *)(( char *)dst + dst_byte_offset);
|
||||
|
||||
ggml_cuda_pdl_sync();
|
||||
dst[i] = ggml_cuda_cast<T>(op(ggml_cuda_cast<float>(*src_ptr)));
|
||||
*dst_ptr = ggml_cuda_cast<T>(op(ggml_cuda_cast<float>(*src_ptr)));
|
||||
}
|
||||
|
||||
template <float (*op)(float), typename T>
|
||||
static void unary_cuda_strided(const T * x, T * dst, const int k,const int64_t ne00,const int64_t ne01,const int64_t ne02,const size_t nb00,const size_t nb01,const size_t nb02,const size_t nb03, cudaStream_t stream) {
|
||||
static void unary_cuda_strided(
|
||||
const T * x, T * dst, const int k,
|
||||
const int64_t ne00, const int64_t ne01, const int64_t ne02,
|
||||
const size_t nb00, const size_t nb01, const size_t nb02, const size_t nb03,
|
||||
const size_t nb0, const size_t nb1, const size_t nb2, const size_t nb3,
|
||||
cudaStream_t stream) {
|
||||
const int num_blocks = (k + CUDA_NEG_BLOCK_SIZE - 1) / CUDA_NEG_BLOCK_SIZE;
|
||||
const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params((dim3)num_blocks, CUDA_NEG_BLOCK_SIZE, 0, stream);
|
||||
ggml_cuda_kernel_launch(unary_op_kernel_strided<op, T>, launch_params, x, dst, k, ne00,ne01,ne02,nb00,nb01,nb02,nb03);
|
||||
ggml_cuda_kernel_launch(unary_op_kernel_strided<op, T>, launch_params,
|
||||
x, dst, k, ne00, ne01, ne02, nb00, nb01, nb02, nb03, nb0, nb1, nb2, nb3);
|
||||
}
|
||||
|
||||
template <float (*op)(float)>
|
||||
@@ -172,8 +184,9 @@ void ggml_cuda_op_unary(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
||||
|
||||
GGML_ASSERT(src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16 || src0->type == GGML_TYPE_BF16);
|
||||
GGML_ASSERT(src0->type == dst->type);
|
||||
GGML_ASSERT(ggml_are_same_shape(src0, dst));
|
||||
|
||||
if (ggml_is_contiguous(src0)) {
|
||||
if (ggml_is_contiguous(src0) && ggml_is_contiguous(dst)) {
|
||||
if (src0->type == GGML_TYPE_F16) {
|
||||
unary_cuda<op>((const half *)src0_d, (half *)dst_d, ggml_nelements(src0), stream);
|
||||
} else if (src0->type == GGML_TYPE_BF16) {
|
||||
@@ -185,15 +198,18 @@ void ggml_cuda_op_unary(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
||||
if (src0->type == GGML_TYPE_F16) {
|
||||
unary_cuda_strided<op>((const half *)src0_d, (half *)dst_d, ggml_nelements(src0),
|
||||
src0->ne[0], src0->ne[1], src0->ne[2],
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], stream);
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
||||
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3], stream);
|
||||
} else if (src0->type == GGML_TYPE_BF16) {
|
||||
unary_cuda_strided<op>((const nv_bfloat16 *)src0_d, (nv_bfloat16 *)dst_d, ggml_nelements(src0),
|
||||
src0->ne[0], src0->ne[1], src0->ne[2],
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], stream);
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
||||
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3], stream);
|
||||
} else {
|
||||
unary_cuda_strided<op>((const float *)src0_d, (float *)dst_d, ggml_nelements(src0),
|
||||
src0->ne[0], src0->ne[1], src0->ne[2],
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], stream);
|
||||
src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
||||
dst->nb[0], dst->nb[1], dst->nb[2], dst->nb[3], stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+31
-1
@@ -31,7 +31,7 @@ typedef uint64_t ggml_cuda_thread_mask_t;
|
||||
#define CU_MEM_ALLOCATION_TYPE_PINNED hipMemAllocationTypePinned
|
||||
#define CU_MEM_LOCATION_TYPE_DEVICE hipMemLocationTypeDevice
|
||||
#define CU_MEM_ACCESS_FLAGS_PROT_READWRITE hipMemAccessFlagsProtReadWrite
|
||||
#define CU_CHECK(fn) {hipError_t err = fn; if(err != hipSuccess) { GGML_ABORT("HipVMM Failure: %s\n", hipGetErrorString(err)); }}
|
||||
#define CU_CHECK(fn) do { hipError_t err_ = (fn); if (err_ != hipSuccess) { GGML_ABORT("HipVMM Failure: %s\n", hipGetErrorString(err_)); } } while (0)
|
||||
#define cublasStrsmBatched hipblasStrsmBatched
|
||||
#define cublasCreate hipblasCreate
|
||||
#define cublasDestroy hipblasDestroy
|
||||
@@ -333,3 +333,33 @@ static __device__ __forceinline__ uint32_t ggml_hip_perm(const uint32_t hi, cons
|
||||
return __builtin_amdgcn_perm(hi, lo, sel);
|
||||
#endif // __has_builtin(__builtin_amdgcn_is_invocable)
|
||||
}
|
||||
|
||||
// DPP control codes.
|
||||
#define GGML_HIP_DPP_QUAD_PERM_1032 0x0b1 // quad_perm:[1,0,3,2]
|
||||
#define GGML_HIP_DPP_QUAD_PERM_2301 0x04e // quad_perm:[2,3,0,1]
|
||||
#define GGML_HIP_DPP_ROW_HALF_MIRROR 0x141 // row_half_mirror
|
||||
#define GGML_HIP_DPP_ROW_ROR_8 0x128 // row_ror:8
|
||||
#define GGML_HIP_DPP_ROW_BCAST_15 0x142 // row_bcast:15, GCN/CDNA only
|
||||
#define GGML_HIP_DPP_ROW_BCAST_31 0x143 // row_bcast:31, GCN/CDNA only
|
||||
#define GGML_HIP_DPP_WAVE_ROR_1 0x13c // wave_ror:1
|
||||
|
||||
// DS swizzle mask codes.
|
||||
#define GGML_HIP_SWIZZLE_SWAP16 0x401F // XOR16 within each 32-lane group
|
||||
|
||||
template <int dpp_ctrl, typename T>
|
||||
static __device__ __forceinline__ T ggml_hip_dpp_update(T x) {
|
||||
static_assert(sizeof(T) == 4, "DPP updates require 32-bit values");
|
||||
union { T t; int i; } value;
|
||||
value.t = x;
|
||||
value.i = __builtin_amdgcn_update_dpp(value.i, value.i, dpp_ctrl, 0xf, 0xf, true);
|
||||
return value.t;
|
||||
}
|
||||
|
||||
template <int swizzle_mask, typename T>
|
||||
static __device__ __forceinline__ T ggml_hip_swizzle(T x) {
|
||||
static_assert(sizeof(T) == 4, "DS swizzle requires 32-bit values");
|
||||
union { T t; int i; } value;
|
||||
value.t = x;
|
||||
value.i = __builtin_amdgcn_ds_swizzle(value.i, swizzle_mask);
|
||||
return value.t;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ rwkv_wkv7_f32_t1_warp_row(const int T, const int C, const int H, const float * r
|
||||
const float vt = v[t];
|
||||
const float st0 = s0 * _w[lane] + _k[lane] * vt + sa * _b[lane];
|
||||
const float st1 = s1 * _w[lane + half_head] + _k[lane + half_head] * vt + sa * _b[lane + half_head];
|
||||
const float y = warp_reduce_sum(st0 * _r[lane] + st1 * _r[lane + half_head]);
|
||||
const float y = warp_reduce_sum<WARP_SIZE, true>(st0 * _r[lane] + st1 * _r[lane + half_head]);
|
||||
|
||||
dst[T * C + state_base + lane] = st0;
|
||||
dst[T * C + state_base + lane + half_head] = st1;
|
||||
|
||||
@@ -25,32 +25,11 @@
|
||||
#define A_L1_START 0 // L1 SCP lines 0..15 for A (activations)
|
||||
#define B_L1_START 16 // L1 SCP lines 16..31 for B (dequantized weights)
|
||||
|
||||
// L2 SCP layout per minion (double-buffered dequant panel + sync counters).
|
||||
// L2 SCP layout per minion (double-buffered dequant panel).
|
||||
// panel = BLOCK_K k-lines x TILE_M m (FP32) = 32 * 64 = 2048 bytes, in TenB
|
||||
// [k][m] order: panel[k*TILE_M + m].
|
||||
#define SCP_PANEL_SIZE (BLOCK_K * TILE_M * (uint64_t) sizeof(float)) // 2048
|
||||
#define SCP_READY_OFF (2 * SCP_PANEL_SIZE) // 4096
|
||||
#define SCP_CONSUMED_OFF (SCP_READY_OFF + 64) // 4160
|
||||
#define SCP_PER_MINION (SCP_CONSUMED_OFF + 64) // 4224
|
||||
|
||||
// Signal a counter value to the other hart via L2 SCP.
|
||||
static inline void __attribute__((always_inline)) scp_signal(volatile uint32_t * flag, uint32_t value) {
|
||||
*flag = value;
|
||||
FENCE;
|
||||
evict_to_l2((const void *) flag, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
}
|
||||
|
||||
// Wait for a counter in L2 SCP to reach the expected value.
|
||||
static inline void __attribute__((always_inline)) scp_wait(volatile uint32_t * flag, uint32_t expected) {
|
||||
while (1) {
|
||||
evict_to_l2((const void *) flag, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
if (*flag >= expected) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#define SCP_PANEL_SIZE (BLOCK_K * TILE_M * (uint64_t) sizeof(float)) // 2048
|
||||
#define SCP_PER_MINION (2 * SCP_PANEL_SIZE) // 4096
|
||||
|
||||
// Dequantize one 32-element Q4_0 block of TILE_M weight rows into the FP32
|
||||
// panel, written directly in TenB [k][m] order: panel[k*TILE_M + m].
|
||||
@@ -192,22 +171,17 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
const int64_t kb_start = k_split * k_steps_per_split; // first block
|
||||
const int64_t kb_end = kb_start + k_steps_per_split; // one past last
|
||||
|
||||
// L2 SCP pointers for this minion's double-buffered panels + sync.
|
||||
// L2 SCP pointers for this minion's double-buffered panels.
|
||||
uint64_t scp_base = local_minion * SCP_PER_MINION;
|
||||
float * scp_panel[2] = {
|
||||
(float *) et_shire_l2scp_local(scp_base),
|
||||
(float *) et_shire_l2scp_local(scp_base + SCP_PANEL_SIZE),
|
||||
};
|
||||
volatile uint32_t * ready_ctr = (volatile uint32_t *) et_shire_l2scp_local(scp_base + SCP_READY_OFF);
|
||||
volatile uint32_t * consumed_ctr = (volatile uint32_t *) et_shire_l2scp_local(scp_base + SCP_CONSUMED_OFF);
|
||||
|
||||
// ================================================================
|
||||
// Hart 1: Q4_0 weight dequant producer
|
||||
// ================================================================
|
||||
if (is_hart1) {
|
||||
scp_signal(ready_ctr, 0);
|
||||
scp_signal(consumed_ctr, 0);
|
||||
|
||||
uint32_t chunk_id = 0;
|
||||
|
||||
for (int64_t tile = (int64_t) shire_id + local_tile_idx * NUM_COMPUTE_SHIRES; tile < base_tiles;
|
||||
@@ -229,22 +203,28 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
for (int64_t kb = kb_start; kb < kb_end; ++kb) {
|
||||
int buf = chunk_id & 1;
|
||||
|
||||
// Back-pressure: wait for hart 0 to finish with this buffer.
|
||||
// Back-pressure via FCC 0 (avoids FLB 0 aliasing with uberkernel barriers).
|
||||
if (chunk_id >= 2) {
|
||||
scp_wait(consumed_ctr, chunk_id - 1);
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
}
|
||||
|
||||
dequant_q4_0_panel(scp_panel[buf], src0_batch, mb, kb, nb1_0);
|
||||
|
||||
FENCE;
|
||||
flush_to_l2(scp_panel[buf], BLOCK_K, 64);
|
||||
flush_to_l2_multi(scp_panel[buf], BLOCK_K, 64);
|
||||
WAIT_CACHEOPS;
|
||||
|
||||
et_sem_post(ET_BARRIER_MINION);
|
||||
chunk_id++;
|
||||
scp_signal(ready_ctr, chunk_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Drain the up to 2 unconsumed FCC 0 credits from the wait-skip on chunks 0 and 1.
|
||||
uint32_t drain = (chunk_id < 2) ? chunk_id : 2;
|
||||
for (uint32_t d = 0; d < drain; ++d) {
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
}
|
||||
|
||||
FENCE;
|
||||
return 0;
|
||||
}
|
||||
@@ -261,11 +241,6 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
#endif
|
||||
CLEAR_TENSOR_ERROR;
|
||||
|
||||
evict_to_l2((const void *) ready_ctr, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
evict_to_l2((const void *) consumed_ctr, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
|
||||
uint32_t chunk_id = 0;
|
||||
|
||||
for (int64_t tile = (int64_t) shire_id + local_tile_idx * NUM_COMPUTE_SHIRES; tile < base_tiles;
|
||||
@@ -307,8 +282,7 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
int buf = chunk_id & 1;
|
||||
|
||||
// Wait for hart 1 to finish dequantizing this block.
|
||||
chunk_id++;
|
||||
scp_wait(ready_ctr, chunk_id);
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
|
||||
// Two FMA passes over the 32-wide block (16 K-cols each).
|
||||
for (int half = 0; half < 2; ++half) {
|
||||
@@ -337,7 +311,8 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
}
|
||||
|
||||
// Signal that this buffer is free for hart 1 to reuse.
|
||||
scp_signal(consumed_ctr, chunk_id);
|
||||
et_sem_post(ET_BARRIER_MINION);
|
||||
chunk_id++;
|
||||
}
|
||||
|
||||
// K-split ring reduce.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// Hart 0: tensor engine (load A, load B from SCP, FMA, reduce, store)
|
||||
// Hart 1: pack B into double-buffered L2 SCP panels, flush for tensor_load
|
||||
//
|
||||
// Sync: monotonic counters in L2 SCP with evict-based coherency.
|
||||
// Sync: FCC 0 semaphores (et_sem_post / et_sem_wait).
|
||||
// Double-buffered bpanel allows pack/FMA overlap.
|
||||
//
|
||||
#define NUM_COMPUTE_SHIRES 32
|
||||
@@ -28,34 +28,11 @@
|
||||
|
||||
typedef uint16_t et_fp16_t;
|
||||
|
||||
// L2 SCP layout per minion (double-buffered bpanel + sync counters)
|
||||
// L2 SCP layout per minion (double-buffered bpanel)
|
||||
// [0..1023] bpanel buffer 0 (16 lines x 64 bytes)
|
||||
// [1024..2047] bpanel buffer 1
|
||||
// [2048..2111] ready counter (hart1 -> hart0, own cache line)
|
||||
// [2112..2175] consumed counter (hart0 -> hart1, own cache line)
|
||||
#define SCP_BPANEL_SIZE (16 * 32 * sizeof(et_fp16_t)) // 1024 bytes
|
||||
#define SCP_READY_OFF (2 * SCP_BPANEL_SIZE) // 2048
|
||||
#define SCP_CONSUMED_OFF (SCP_READY_OFF + 64) // 2112
|
||||
#define SCP_PER_MINION (SCP_CONSUMED_OFF + 64) // 2176
|
||||
|
||||
// Signal a counter value to the other hart via L2 SCP.
|
||||
static inline void __attribute__((always_inline)) scp_signal(volatile uint32_t * flag, uint32_t value) {
|
||||
*flag = value;
|
||||
FENCE;
|
||||
evict_to_l2((const void *) flag, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
}
|
||||
|
||||
// Wait for a counter in L2 SCP to reach the expected value.
|
||||
static inline void __attribute__((always_inline)) scp_wait(volatile uint32_t * flag, uint32_t expected) {
|
||||
while (1) {
|
||||
evict_to_l2((const void *) flag, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
if (*flag >= expected) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#define SCP_BPANEL_SIZE (16 * 32 * sizeof(et_fp16_t)) // 1024 bytes
|
||||
#define SCP_PER_MINION (2 * SCP_BPANEL_SIZE) // 2048 bytes
|
||||
|
||||
/**
|
||||
* Build the interleaved B panel that TensorFMA16A32 expects (vectorized).
|
||||
@@ -170,23 +147,17 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
const int64_t k_start = k_split * k_steps_per_split * TILE_K;
|
||||
const int64_t k_end = k_start + k_steps_per_split * TILE_K;
|
||||
|
||||
// L2 SCP pointers for this minion's double-buffered panels + sync
|
||||
// L2 SCP pointers for this minion's double-buffered panels
|
||||
uint64_t scp_base = local_minion * SCP_PER_MINION;
|
||||
et_fp16_t * scp_bp[2] = {
|
||||
(et_fp16_t *) et_shire_l2scp_local(scp_base),
|
||||
(et_fp16_t *) et_shire_l2scp_local(scp_base + SCP_BPANEL_SIZE),
|
||||
};
|
||||
volatile uint32_t * ready_ctr = (volatile uint32_t *) et_shire_l2scp_local(scp_base + SCP_READY_OFF);
|
||||
volatile uint32_t * consumed_ctr = (volatile uint32_t *) et_shire_l2scp_local(scp_base + SCP_CONSUMED_OFF);
|
||||
|
||||
// ================================================================
|
||||
// Hart 1: B-panel packer
|
||||
// ================================================================
|
||||
if (is_hart1) {
|
||||
// Initialize sync counters
|
||||
scp_signal(ready_ctr, 0);
|
||||
scp_signal(consumed_ctr, 0);
|
||||
|
||||
uint32_t chunk_id = 0;
|
||||
|
||||
for (int64_t tile = (int64_t) shire_id + local_tile_idx * NUM_COMPUTE_SHIRES; tile < base_tiles;
|
||||
@@ -208,9 +179,9 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
for (int64_t kb = k_start; kb < k_end; kb += TILE_K) {
|
||||
int buf = chunk_id & 1;
|
||||
|
||||
// Back-pressure: wait for hart 0 to finish with this buffer
|
||||
// Back-pressure via FCC 0 (avoids FLB 0 aliasing with uberkernel barriers).
|
||||
if (chunk_id >= 2) {
|
||||
scp_wait(consumed_ctr, chunk_id - 1);
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
}
|
||||
|
||||
pack_b_interleaved(scp_bp[buf], src0_batch, mb, kb, nb1_0);
|
||||
@@ -219,11 +190,17 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
flush_to_l2(scp_bp[buf], 16, 64);
|
||||
WAIT_CACHEOPS;
|
||||
|
||||
et_sem_post(ET_BARRIER_MINION);
|
||||
chunk_id++;
|
||||
scp_signal(ready_ctr, chunk_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Drain the up to 2 unconsumed FCC 0 credits from the wait-skip on chunks 0 and 1.
|
||||
uint32_t drain = (chunk_id < 2) ? chunk_id : 2;
|
||||
for (uint32_t d = 0; d < drain; ++d) {
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
}
|
||||
|
||||
FENCE;
|
||||
return 0;
|
||||
}
|
||||
@@ -240,12 +217,6 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
#endif
|
||||
CLEAR_TENSOR_ERROR;
|
||||
|
||||
// Evict any stale L1D copies of sync counters
|
||||
evict_to_l2((const void *) ready_ctr, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
evict_to_l2((const void *) consumed_ctr, 1, 64);
|
||||
WAIT_CACHEOPS;
|
||||
|
||||
uint32_t chunk_id = 0;
|
||||
|
||||
for (int64_t tile = (int64_t) shire_id + local_tile_idx * NUM_COMPUTE_SHIRES; tile < base_tiles;
|
||||
@@ -282,8 +253,7 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
(uint64_t) nb1_1, 0);
|
||||
|
||||
// Wait for hart 1 to finish packing this chunk
|
||||
chunk_id++;
|
||||
scp_wait(ready_ctr, chunk_id);
|
||||
et_sem_wait(ET_BARRIER_MINION);
|
||||
|
||||
// Load B from L2 SCP (hart 1 already flushed it)
|
||||
tensor_load(false, false, B_L1_START, TENSOR_LOAD_PLAIN, 0, (uint64_t) scp_bp[buf], 0, 15, 64, 1);
|
||||
@@ -298,7 +268,8 @@ int entry_point(struct ggml_et_binary_params * params, void * env) {
|
||||
tensor_wait(TENSOR_FMA_WAIT);
|
||||
|
||||
// Signal that this buffer is free for hart 1 to reuse
|
||||
scp_signal(consumed_ctr, chunk_id);
|
||||
et_sem_post(ET_BARRIER_MINION);
|
||||
chunk_id++;
|
||||
}
|
||||
|
||||
// K-split ring reduce
|
||||
|
||||
@@ -476,6 +476,23 @@ static inline void __attribute__((always_inline)) flush_to_l2(const void * addr,
|
||||
: "x31", "memory");
|
||||
}
|
||||
|
||||
// Flush any number of cache lines to L2 in 16-line chunks (FlushVA hardware cap).
|
||||
static inline void __attribute__((always_inline)) flush_to_l2_multi(const void * addr,
|
||||
uint64_t nlines,
|
||||
uint64_t stride) {
|
||||
const char * p = (const char *) addr;
|
||||
const uint64_t step = stride & 0xFFFFFFFFFFC0ULL;
|
||||
|
||||
while (nlines > 16) {
|
||||
flush_to_l2(p, 16, step);
|
||||
p += 16 * step;
|
||||
nlines -= 16;
|
||||
}
|
||||
if (nlines > 0) {
|
||||
flush_to_l2(p, nlines, step);
|
||||
}
|
||||
}
|
||||
|
||||
// Evict nlines cache lines at stride apart starting at addr from L1 to L2.
|
||||
// Uses EvictVA (CSR 0x89F). Unlike flush_to_l2, this guarantees the line is
|
||||
// NOT present in L1 after the operation - subsequent loads will miss and go
|
||||
|
||||
@@ -1281,7 +1281,7 @@ static bool ggml_backend_et_device_supports_op(ggml_backend_dev_t dev, const ggm
|
||||
if (op->type == GGML_TYPE_F32 && op->src[0] && op->src[0]->type == GGML_TYPE_F32 && op->src[1] &&
|
||||
(op->src[1]->type == GGML_TYPE_F32 || op->src[1]->type == GGML_TYPE_F16) && op->src[2] &&
|
||||
(op->src[2]->type == GGML_TYPE_F32 || op->src[2]->type == GGML_TYPE_F16) && op->src[4] == nullptr && op->src[5] == nullptr &&
|
||||
!ggml_flash_attn_ext_has_indexed_bias(op) &&
|
||||
!ggml_flash_attn_ext_has_bias(op) &&
|
||||
ggml_is_contiguous_rows(op) && ggml_is_contiguous_rows(op->src[0])) {
|
||||
float max_bias = 0.0f;
|
||||
float logit_softcap = 0.0f;
|
||||
|
||||
@@ -135,6 +135,7 @@ size_t opt_mbuf_static = 1ul * 1024 * 1024 * 1024; // max static (weight/KV) buf
|
||||
size_t opt_mbuf_total = 0; // total buffer space limit (0 = unconstrained)
|
||||
|
||||
int opt_mm_select = 3; // 3 = W8A8 INT HMX -> FP16 HMX -> HVX -> CPU (default), 2 = FP16 HMX -> HVX -> CPU, 1 = HVX -> CPU, 0 = CPU
|
||||
int opt_mm_fwht = 0; // 1 = enable online block-32 FWHT rotation in W8A8 HMX matmul, 0 = off (default)
|
||||
int opt_fa_select = 3; // 3 = INT HMX W8A8 (default) -> FP16 HMX -> HVX -> CPU, 2 = FP16 HMX -> HVX -> CPU, 1 = HVX -> CPU, 0 = CPU
|
||||
int opt_fa_split = 1; // 1 = head-split + team-split when n_kv_heads < N_cores (default), 0 = off
|
||||
int opt_li_select = 2; // 2 = HMX -> HVX, 1 = HVX, 0 = CPU (unsupported)
|
||||
@@ -365,7 +366,7 @@ struct ggml_hexagon_session {
|
||||
std::unordered_map<uint64_t, volatile uint32_t *> cpy_fence_slots;
|
||||
|
||||
void enqueue_mdev_group();
|
||||
void enqueue_op(const htp_opnode & node, bool allow_fuse = true);
|
||||
void enqueue_op(const htp_opnode & node, bool fusable = false);
|
||||
void enqueue_cpy(const ggml_tensor * src, ggml_tensor * dst, const ggml_tensor * sync_tensor = nullptr, uint32_t fence_seq = 0);
|
||||
void enqueue_fence(const ggml_tensor * sync_tensor, uint32_t fence_seq = 0, bool wait = true);
|
||||
void enqueue_allreduce(const ggml_tensor * dst, const std::vector<const ggml_tensor *> & src_tensors,
|
||||
@@ -1342,26 +1343,27 @@ struct ggml_hexagon_tensor_map {
|
||||
};
|
||||
|
||||
struct ggml_hexagon_opbatch {
|
||||
ggml_hexagon_session* sess;
|
||||
ggml_hexagon_session* sess;
|
||||
|
||||
std::vector<htp_opnode> ops; // htp_opnode of ops
|
||||
std::vector<htp_buf_desc> h_bufs; // htp buffer descriptors
|
||||
std::vector<htp_tensor> h_tens; // htp tensor descriptors
|
||||
std::vector<htp_op_desc> h_ops; // htp op descriptors
|
||||
std::vector<htp_opnode> ops; // htp_opnode of ops
|
||||
std::vector<htp_buf_desc> h_bufs; // htp buffer descriptors
|
||||
std::vector<htp_tensor> h_tens; // htp tensor descriptors
|
||||
std::vector<htp_op_desc> h_ops; // htp op descriptors
|
||||
|
||||
ggml_hexagon_tensor_map t_map; // tensor hash to index
|
||||
ggml_hexagon_tensor_map t_map; // tensor hash to index
|
||||
|
||||
unsigned int n_bufs; // num buffers in the batch
|
||||
unsigned int n_tens; // num tensors ...
|
||||
unsigned int n_ops; // num ops ...
|
||||
size_t b_vmem; // sum of non-extended buffer sizes
|
||||
bool last_op_fusable;
|
||||
unsigned int n_bufs; // num buffers in the batch
|
||||
unsigned int n_tens; // num tensors ...
|
||||
unsigned int n_ops; // num ops ...
|
||||
size_t b_vmem; // sum of non-extended buffer sizes
|
||||
|
||||
unsigned int n_bufs_max;
|
||||
unsigned int n_tens_max;
|
||||
unsigned int n_ops_max;
|
||||
size_t b_vmem_max;
|
||||
|
||||
bool last_op_fusable;
|
||||
|
||||
void reset() {
|
||||
n_bufs = 0;
|
||||
n_tens = 0;
|
||||
@@ -1586,14 +1588,14 @@ struct ggml_hexagon_opbatch {
|
||||
}
|
||||
|
||||
// caller must ensure the op fits
|
||||
void add_op(const htp_opnode & node, bool save_op = true) {
|
||||
void add_op(const htp_opnode & node, bool save_op = true, bool fusable = false) {
|
||||
unsigned int n = n_ops++;
|
||||
GGML_ASSERT(n_ops <= n_ops_max);
|
||||
|
||||
if (save_op) {
|
||||
ops[n] = node;
|
||||
}
|
||||
last_op_fusable = save_op;
|
||||
last_op_fusable = fusable;
|
||||
h_ops[n].flags = 0;
|
||||
|
||||
if (opt_verbose) {
|
||||
@@ -1656,6 +1658,7 @@ struct ggml_hexagon_opbatch {
|
||||
|
||||
htp_lower_opnode(sess, last_node);
|
||||
sync_op_desc(n_ops - 1, last_node);
|
||||
last_op_fusable = false;
|
||||
HEX_VERBOSE("ggml-hex: %s fused %s (N=%zu, #%u)\n",
|
||||
sess->c_name(), last_node.name().c_str(), last_node.fused.size() + 1, n_ops - 1);
|
||||
return true;
|
||||
@@ -1970,7 +1973,7 @@ void ggml_hexagon_session::flush_batch(size_t min_ops) {
|
||||
op_batch->reset();
|
||||
}
|
||||
|
||||
void ggml_hexagon_session::enqueue_op(const htp_opnode & node, bool allow_fuse) {
|
||||
void ggml_hexagon_session::enqueue_op(const htp_opnode & node, bool fusable) {
|
||||
auto register_tensor = [&](const ggml_tensor * t) {
|
||||
if (!t) return;
|
||||
auto * sbuf = static_cast<ggml_hexagon_shared_buffer *>(t->buffer->context);
|
||||
@@ -2000,7 +2003,7 @@ void ggml_hexagon_session::enqueue_op(const htp_opnode & node, bool allow_fuse)
|
||||
}
|
||||
|
||||
const bool fits_tensors = op_batch->fit_tensors(node);
|
||||
if (opt_opfusion && allow_fuse && fits_tensors && op_batch->try_fuse(node)) {
|
||||
if (opt_opfusion && fits_tensors && op_batch->try_fuse(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2015,7 +2018,8 @@ void ggml_hexagon_session::enqueue_op(const htp_opnode & node, bool allow_fuse)
|
||||
}
|
||||
}
|
||||
|
||||
op_batch->add_op(node, opt_profile || (opt_opfusion && allow_fuse));
|
||||
const bool mark_fusable = opt_opfusion && fusable;
|
||||
op_batch->add_op(node, opt_profile || mark_fusable, mark_fusable);
|
||||
}
|
||||
|
||||
void ggml_hexagon_session::enqueue_mdev_group() {
|
||||
@@ -2104,7 +2108,7 @@ void ggml_hexagon_session::enqueue_allreduce(
|
||||
this, dst, rank, n_ranks, false, false, /*is_shard_ok=*/ false,
|
||||
ar_node.kparams<htp_allreduce_kernel_params>());
|
||||
|
||||
this->enqueue_op(ar_node);
|
||||
this->enqueue_op(ar_node, /*fusable=*/ true);
|
||||
}
|
||||
|
||||
void ggml_hexagon_session::mmap_buffers() {
|
||||
@@ -2629,6 +2633,30 @@ static void ggml_hexagon_graph_repack(const ggml_cgraph * graph, ggml_hexagon_se
|
||||
}
|
||||
}
|
||||
|
||||
static void ggml_hexagon_graph_append_opnode(
|
||||
const ggml_hexagon_session * sess,
|
||||
std::vector<htp_opnode> & nodes,
|
||||
htp_opnode && node
|
||||
) {
|
||||
const ggml_tensor * n = node.node;
|
||||
const ggml_tensor * scale = ggml_get_src_scale(n, 0);
|
||||
const bool fused_scale = scale != nullptr &&
|
||||
(node.opcode == HTP_OP_MUL_MAT || node.opcode == HTP_OP_MUL_MAT_ID) &&
|
||||
(node.kparams<htp_mm_kernel_params>()->scale_mask != 0);
|
||||
if (fused_scale) {
|
||||
node.inputs.push_back(scale);
|
||||
}
|
||||
if (nodes.empty() || !opt_opfusion || !htp_fusion_try_fuse(sess, nodes.back(), node)) {
|
||||
nodes.push_back(std::move(node));
|
||||
}
|
||||
|
||||
if (scale && !fused_scale) {
|
||||
htp_opnode scale_node = htp_mm_make_scale_opnode(n, scale);
|
||||
GGML_ASSERT(htp_kparams_solve(sess, scale_node));
|
||||
nodes.push_back(std::move(scale_node));
|
||||
}
|
||||
}
|
||||
|
||||
static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, ggml_cgraph * graph) {
|
||||
auto sess = static_cast<ggml_hexagon_session *>(backend->context);
|
||||
|
||||
@@ -2662,9 +2690,7 @@ static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, gg
|
||||
|
||||
htp_opnode node(opcode, n);
|
||||
GGML_ASSERT(htp_kparams_solve(sess, node));
|
||||
if (nodes.empty() || !opt_opfusion || !htp_fusion_try_fuse(sess, nodes.back(), node)) {
|
||||
nodes.push_back(std::move(node));
|
||||
}
|
||||
ggml_hexagon_graph_append_opnode(sess, nodes, std::move(node));
|
||||
}
|
||||
|
||||
if (opt_opfusion) {
|
||||
@@ -2677,7 +2703,7 @@ static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, gg
|
||||
}
|
||||
|
||||
for (const auto & node : sess->cached_nodes) {
|
||||
sess->enqueue_op(node, false);
|
||||
sess->enqueue_op(node);
|
||||
}
|
||||
|
||||
if (sess->last_error > HTP_STATUS_OK) {
|
||||
@@ -3233,10 +3259,7 @@ static bool ggml_backend_hexagon_device_supports_op(ggml_backend_dev_t dev, cons
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ggml_get_src_scale(op, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// src_scale(op, 1) is an activation quantization hint for quantized-activation backends, ignored for F32/F16 activations
|
||||
bool supp = false;
|
||||
if (ggml_op_is_empty(op->op) || ggml_is_empty(op)) {
|
||||
supp = true;
|
||||
@@ -3636,6 +3659,8 @@ static void ggml_hexagon_init(ggml_backend_reg * reg) {
|
||||
"please update hexagon_type to match ggml_type");
|
||||
static_assert((unsigned int) HTP_TYPE_Q2_0 == (unsigned int) GGML_TYPE_Q2_0,
|
||||
"please update hexagon_type to match ggml_type");
|
||||
static_assert((unsigned int) HTP_TYPE_F8_E4M3 == (unsigned int) GGML_TYPE_F8_E4M3,
|
||||
"please update hexagon_type to match ggml_type");
|
||||
static_assert((unsigned int) HTP_TYPE_BF16 == (unsigned int) GGML_TYPE_BF16,
|
||||
"please update hexagon_type to match ggml_type");
|
||||
|
||||
@@ -3653,6 +3678,7 @@ static void ggml_hexagon_init(ggml_backend_reg * reg) {
|
||||
const char * str_nhmx = getenv("GGML_HEXAGON_NHMX");
|
||||
const char * str_vtcm_size = getenv("GGML_HEXAGON_VTCM_SIZE");
|
||||
const char * str_mm_select = getenv("GGML_HEXAGON_MM_SELECT");
|
||||
const char * str_mm_fwht = getenv("GGML_HEXAGON_MM_FWHT");
|
||||
const char * str_fa_select = getenv("GGML_HEXAGON_FA_SELECT");
|
||||
const char * str_fa_split = getenv("GGML_HEXAGON_FA_SPLIT");
|
||||
const char * str_li_select = getenv("GGML_HEXAGON_LI_SELECT");
|
||||
@@ -3727,6 +3753,7 @@ static void ggml_hexagon_init(ggml_backend_reg * reg) {
|
||||
opt_nhmx = str_nhmx ? atoi(str_nhmx) : opt_nhmx;
|
||||
opt_vtcm_size = str_vtcm_size ? parse_size(str_vtcm_size) : opt_vtcm_size;
|
||||
opt_mm_select = str_mm_select ? atoi(str_mm_select) : opt_mm_select;
|
||||
opt_mm_fwht = str_mm_fwht ? atoi(str_mm_fwht) : opt_mm_fwht;
|
||||
opt_fa_select = str_fa_select ? atoi(str_fa_select) : opt_fa_select;
|
||||
opt_fa_split = str_fa_split ? atoi(str_fa_split) : opt_fa_split;
|
||||
opt_li_select = str_li_select ? atoi(str_li_select) : opt_li_select;
|
||||
@@ -3954,10 +3981,6 @@ static void ggml_hexagon_init(ggml_backend_reg * reg) {
|
||||
for (size_t i = 0; i < opt_ndev; i++) {
|
||||
total_sessions += opt_device_configs[i].mdev_group.size();
|
||||
}
|
||||
if (!str_mm_select && hw_arch == 73 && total_sessions > 1) {
|
||||
opt_mm_select = 2;
|
||||
GGML_LOG_INFO("ggml-hex: defaulting MM_SELECT=2 on multi-session v73 hardware\n");
|
||||
}
|
||||
if (!str_fa_select && hw_arch == 73 && total_sessions > 1) {
|
||||
opt_fa_select = 2;
|
||||
GGML_LOG_INFO("ggml-hex: defaulting FA_SELECT=2 on multi-session v73 hardware\n");
|
||||
|
||||
@@ -21,6 +21,7 @@ extern size_t opt_mbuf_static;
|
||||
extern size_t opt_mbuf_total;
|
||||
|
||||
extern int opt_mm_select;
|
||||
extern int opt_mm_fwht;
|
||||
extern int opt_fa_select;
|
||||
extern int opt_fa_split;
|
||||
extern int opt_li_select;
|
||||
@@ -154,4 +155,38 @@ uint32_t htp_session_mdev_count(const struct ggml_hexagon_session * sess);
|
||||
|
||||
htp_op_code htp_op_remap(const struct ggml_tensor * t);
|
||||
|
||||
enum htp_mm_scale_mode {
|
||||
HTP_MM_SCALE_NONE = 0,
|
||||
HTP_MM_SCALE_PER_TENSOR,
|
||||
HTP_MM_SCALE_PER_CHANNEL,
|
||||
HTP_MM_SCALE_PER_EXPERT,
|
||||
HTP_MM_SCALE_PER_CHANNEL_EXPERT,
|
||||
};
|
||||
|
||||
// classify weight scale (src_scale(op, 0)) of GGML_OP_MUL_MAT / GGML_OP_MUL_MAT_ID
|
||||
static inline enum htp_mm_scale_mode htp_get_mm_scale_mode(const struct ggml_tensor * op) {
|
||||
const struct ggml_tensor * scale = ggml_get_src_scale(op, 0);
|
||||
if (!scale) {
|
||||
return HTP_MM_SCALE_NONE;
|
||||
}
|
||||
if (ggml_is_scalar(scale)) {
|
||||
return HTP_MM_SCALE_PER_TENSOR;
|
||||
}
|
||||
if (op->op == GGML_OP_MUL_MAT_ID) {
|
||||
const int64_t n_out = op->src[0]->ne[1];
|
||||
const int64_t n_expert = op->src[0]->ne[2];
|
||||
if (scale->ne[0] == n_out && scale->ne[1] == n_expert && scale->ne[2] == 1 && scale->ne[3] == 1) {
|
||||
return HTP_MM_SCALE_PER_CHANNEL_EXPERT;
|
||||
}
|
||||
if (ggml_is_vector(scale) && scale->ne[0] == n_expert) {
|
||||
return HTP_MM_SCALE_PER_EXPERT;
|
||||
}
|
||||
GGML_ABORT("invalid MUL_MAT_ID weight scale shape");
|
||||
}
|
||||
if (ggml_is_vector(scale) && scale->ne[0] == op->src[0]->ne[1]) {
|
||||
return HTP_MM_SCALE_PER_CHANNEL;
|
||||
}
|
||||
GGML_ABORT("invalid MUL_MAT weight scale shape");
|
||||
}
|
||||
|
||||
#endif // HTP_COMMON_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ enum htp_fusion_flags {
|
||||
HTP_FUSE_GDN_STATE = (1 << 15), // 32768
|
||||
HTP_FUSE_CONCAT_SSM_CONV = (1 << 16), // 65536
|
||||
HTP_FUSE_MUL_MAT_NX_GLU = (1 << 17), // 131072
|
||||
HTP_FUSE_RMS_NORM_MUL_MM = (1 << 18), // 262144
|
||||
};
|
||||
|
||||
static inline bool htp_fusion_enabled(int flag) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -80,90 +80,9 @@ bool htp_kparams_solve_allreduce(
|
||||
struct htp_allreduce_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_rms_norm_mul(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * src1,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_unary_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_rms_norm_mul_add(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * src1,
|
||||
const struct ggml_tensor * src2,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_unary_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_matmul_add(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * src1,
|
||||
const struct ggml_tensor * bias,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_mm_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_mmnx(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * act,
|
||||
const struct ggml_tensor * dst,
|
||||
int32_t n_weights,
|
||||
struct htp_mm_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_mmnx_glu(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * w_gate,
|
||||
const struct ggml_tensor * w_up,
|
||||
const struct ggml_tensor * act,
|
||||
const struct ggml_tensor * dst,
|
||||
uint8_t glu_op,
|
||||
struct htp_mm_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_mmidnx(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * act,
|
||||
const struct ggml_tensor * dst,
|
||||
int32_t n_weights,
|
||||
struct htp_mm_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_repeat_get_rows(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * src1,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_get_rows_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_unary_mul_glu(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
uint32_t op,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * src1,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_glu_kernel_params * kparams
|
||||
);
|
||||
|
||||
bool htp_kparams_solve_upscale(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
const struct ggml_tensor * src0,
|
||||
const struct ggml_tensor * dst,
|
||||
struct htp_upscale_kernel_params * kparams
|
||||
);
|
||||
|
||||
static inline bool htp_kparams_solve_upscale(
|
||||
const struct ggml_hexagon_session * sess,
|
||||
struct htp_opnode htp_mm_make_scale_opnode(
|
||||
const struct ggml_tensor * op,
|
||||
struct htp_upscale_kernel_params * kparams
|
||||
) {
|
||||
return htp_kparams_solve_upscale(sess, op->src[0], op, kparams);
|
||||
}
|
||||
const struct ggml_tensor * scale
|
||||
);
|
||||
|
||||
#endif // HTP_KPARAMS_H
|
||||
|
||||
@@ -23,7 +23,8 @@ bool htp_rows_stride(const int64_t * ne, const size_t * nb, size_t * stride) {
|
||||
|
||||
bool htp_matmul_can_collapse(const struct ggml_tensor * src0, const struct ggml_tensor * src1, const struct ggml_tensor * dst) {
|
||||
size_t s1, sd;
|
||||
return (dst->op == GGML_OP_MUL_MAT || dst->op == GGML_OP_ADD) &&
|
||||
return (dst->op == GGML_OP_MUL_MAT || dst->op == GGML_OP_ADD ||
|
||||
dst->op == GGML_OP_GLU || dst->op == GGML_OP_MUL) &&
|
||||
src0->ne[2] == 1 && src0->ne[3] == 1 && src1->ne[2] * src1->ne[3] > 1 &&
|
||||
src1->nb[0] == ggml_type_size(src1->type) && htp_rows_stride(src1->ne, src1->nb, &s1) &&
|
||||
dst->nb[0] == ggml_type_size(dst->type) && htp_rows_stride(dst->ne, dst->nb, &sd);
|
||||
@@ -427,26 +428,16 @@ void htp_lightning_indexer_collapse_tensors(
|
||||
}
|
||||
}
|
||||
|
||||
void htp_lower_opnode(const struct ggml_hexagon_session * sess, htp_opnode & node, struct ggml_tensor * scratch) {
|
||||
const uint32_t n_hvx = htp_session_n_hvx(sess);
|
||||
const size_t n_in = node.inputs.size();
|
||||
const size_t n_out = node.outputs.size();
|
||||
|
||||
ggml_tensor in_mat[HTP_OP_MAX_INPUTS] = {};
|
||||
ggml_tensor out_mat[HTP_OP_MAX_OUTPUTS] = {};
|
||||
bool in_dirty[HTP_OP_MAX_INPUTS] = {};
|
||||
bool out_dirty[HTP_OP_MAX_OUTPUTS] = {};
|
||||
|
||||
for (size_t i = 0; i < n_in; ++i) {
|
||||
if (node.inputs[i]) {
|
||||
in_dirty[i] = ggml_hexagon_tensor_is_lowered_f16(node.inputs[i]);
|
||||
in_mat[i] = htp_tensor_lower_f16(node.inputs[i]);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < n_out; ++i) {
|
||||
out_dirty[i] = ggml_hexagon_tensor_is_lowered_f16(node.outputs[i]);
|
||||
out_mat[i] = htp_tensor_lower_f16(node.outputs[i]);
|
||||
}
|
||||
static void htp_collapse_opnode_tensors(
|
||||
uint32_t n_hvx,
|
||||
const htp_opnode & node,
|
||||
ggml_tensor (& in_mat)[HTP_OP_MAX_INPUTS],
|
||||
ggml_tensor (& out_mat)[HTP_OP_MAX_OUTPUTS],
|
||||
bool (& in_dirty)[HTP_OP_MAX_INPUTS],
|
||||
bool (& out_dirty)[HTP_OP_MAX_OUTPUTS]
|
||||
) {
|
||||
const size_t n_in = node.inputs.size();
|
||||
const size_t n_out = node.outputs.size();
|
||||
|
||||
if (htp_op_is_unary(node.opcode) && htp_unary_is_elementwise(node.opcode)) {
|
||||
if (n_in >= 1 && n_out >= 1 &&
|
||||
@@ -497,8 +488,9 @@ void htp_lower_opnode(const struct ggml_hexagon_session * sess, htp_opnode & nod
|
||||
}
|
||||
}
|
||||
} else if (node.opcode == HTP_OP_MUL_MAT_NX) {
|
||||
const size_t n_w = n_out;
|
||||
if (n_w > 0 && n_in == n_w + 1) {
|
||||
const size_t n_w = n_out;
|
||||
const size_t norm_extra = (node.kparams<htp_mm_kernel_params>()->norm_w_idx != 0) ? 1 : 0;
|
||||
if (n_w > 0 && (n_in == n_w + 1 + norm_extra || n_in == 2 * n_w + 1 + norm_extra)) {
|
||||
bool can_collapse = true;
|
||||
for (size_t i = 0; i < n_w; ++i) {
|
||||
if (!htp_matmul_can_collapse(&in_mat[i], &in_mat[n_w], &out_mat[i])) {
|
||||
@@ -516,7 +508,8 @@ void htp_lower_opnode(const struct ggml_hexagon_session * sess, htp_opnode & nod
|
||||
}
|
||||
}
|
||||
} else if (node.opcode == HTP_OP_MUL_MAT_NX_GLU) {
|
||||
if (n_in == 3 && n_out == 1 &&
|
||||
const size_t norm_extra = (node.kparams<htp_mm_kernel_params>()->norm_w_idx != 0) ? 1 : 0;
|
||||
if ((n_in == 3 + norm_extra || n_in == 5 + norm_extra) && n_out == 1 &&
|
||||
htp_matmul_can_collapse(&in_mat[0], &in_mat[2], &out_mat[0]) &&
|
||||
htp_matmul_can_collapse(&in_mat[1], &in_mat[2], &out_mat[0])) {
|
||||
in_mat[2] = htp_tensor_collapse_rows(&in_mat[2]);
|
||||
@@ -591,6 +584,30 @@ void htp_lower_opnode(const struct ggml_hexagon_session * sess, htp_opnode & nod
|
||||
out_dirty[0] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void htp_lower_opnode(const struct ggml_hexagon_session * sess, htp_opnode & node, struct ggml_tensor * scratch) {
|
||||
const uint32_t n_hvx = htp_session_n_hvx(sess);
|
||||
const size_t n_in = node.inputs.size();
|
||||
const size_t n_out = node.outputs.size();
|
||||
|
||||
ggml_tensor in_mat[HTP_OP_MAX_INPUTS] = {};
|
||||
ggml_tensor out_mat[HTP_OP_MAX_OUTPUTS] = {};
|
||||
bool in_dirty[HTP_OP_MAX_INPUTS] = {};
|
||||
bool out_dirty[HTP_OP_MAX_OUTPUTS] = {};
|
||||
|
||||
for (size_t i = 0; i < n_in; ++i) {
|
||||
if (node.inputs[i]) {
|
||||
in_dirty[i] = ggml_hexagon_tensor_is_lowered_f16(node.inputs[i]);
|
||||
in_mat[i] = htp_tensor_lower_f16(node.inputs[i]);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < n_out; ++i) {
|
||||
out_dirty[i] = ggml_hexagon_tensor_is_lowered_f16(node.outputs[i]);
|
||||
out_mat[i] = htp_tensor_lower_f16(node.outputs[i]);
|
||||
}
|
||||
|
||||
htp_collapse_opnode_tensors(n_hvx, node, in_mat, out_mat, in_dirty, out_dirty);
|
||||
|
||||
size_t n_scratch = 0;
|
||||
auto commit_tensor = [&](const ggml_tensor & m) -> const ggml_tensor * {
|
||||
@@ -714,13 +731,19 @@ static bool htp_lower_is_mm_opcode(uint32_t opcode) {
|
||||
opcode == HTP_OP_MUL_MAT_NX_GLU || opcode == HTP_OP_MUL_MAT_ID_NX;
|
||||
}
|
||||
|
||||
static const ggml_tensor * htp_lower_orig_mm_for_output(const htp_opnode & node, const ggml_tensor * tensor) {
|
||||
static const ggml_tensor * htp_lower_orig_mm_for_output(const htp_opnode & node, const ggml_tensor * tensor, uint32_t * out_w_idx) {
|
||||
if (out_w_idx) {
|
||||
*out_w_idx = 0;
|
||||
}
|
||||
if (!htp_lower_is_mm_opcode(node.opcode)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (node.opcode == HTP_OP_MUL_MAT_NX || node.opcode == HTP_OP_MUL_MAT_ID_NX) {
|
||||
for (size_t p = 0; p < node.outputs.size(); ++p) {
|
||||
if (node.outputs[p] == tensor) {
|
||||
if (out_w_idx) {
|
||||
*out_w_idx = (uint32_t) p;
|
||||
}
|
||||
if (p == 0) {
|
||||
return node.node;
|
||||
}
|
||||
@@ -732,10 +755,14 @@ static const ggml_tensor * htp_lower_orig_mm_for_output(const htp_opnode & node,
|
||||
return node.node;
|
||||
}
|
||||
|
||||
static bool htp_lower_mm_blocks_output_f16(const ggml_tensor * orig_mm) {
|
||||
static bool htp_lower_mm_blocks_output_f16(const htp_opnode & owner, const ggml_tensor * orig_mm, uint32_t w_idx) {
|
||||
if (!orig_mm) {
|
||||
return false;
|
||||
}
|
||||
const auto * kp = owner.kparams<htp_mm_kernel_params>();
|
||||
if (((kp->scale_mask >> w_idx) & 1u) == 0 && ggml_get_src_scale(orig_mm, 0) != nullptr) {
|
||||
return true;
|
||||
}
|
||||
if (ggml_prec_get_acc(orig_mm) == GGML_PREC_F32) {
|
||||
return true;
|
||||
}
|
||||
@@ -752,14 +779,21 @@ static bool htp_lower_respect_prec_hints(
|
||||
const std::unordered_map<const ggml_tensor *, std::vector<size_t>> & root_users
|
||||
) {
|
||||
if (htp_lower_is_mm_opcode(owner.opcode)) {
|
||||
const ggml_tensor * orig_mm = htp_lower_orig_mm_for_output(owner, r);
|
||||
if (htp_lower_mm_blocks_output_f16(orig_mm)) {
|
||||
uint32_t w_idx = 0;
|
||||
const ggml_tensor * orig_mm = htp_lower_orig_mm_for_output(owner, r, &w_idx);
|
||||
if (owner.opcode == HTP_OP_MUL_MAT_NX_GLU && orig_mm && owner.inputs.size() >= 2 && orig_mm->src[0] == owner.inputs[1]) {
|
||||
w_idx = 1;
|
||||
}
|
||||
if (htp_lower_mm_blocks_output_f16(owner, orig_mm, w_idx)) {
|
||||
return false;
|
||||
}
|
||||
if (owner.opcode == HTP_OP_MUL_MAT_NX_GLU) {
|
||||
for (const ggml_tensor * f : owner.fused) {
|
||||
if (f && f->op == GGML_OP_MUL_MAT && htp_lower_mm_blocks_output_f16(f)) {
|
||||
return false;
|
||||
if (f && f->op == GGML_OP_MUL_MAT) {
|
||||
const uint32_t f_idx = (owner.inputs.size() >= 2 && f->src[0] == owner.inputs[1]) ? 1u : 0u;
|
||||
if (htp_lower_mm_blocks_output_f16(owner, f, f_idx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -769,9 +803,12 @@ static bool htp_lower_respect_prec_hints(
|
||||
auto oit = owner_idx.find(in_root);
|
||||
if (oit != owner_idx.end()) {
|
||||
const htp_opnode & node = nodes[oit->second];
|
||||
if (htp_lower_is_mm_opcode(node.opcode) &&
|
||||
htp_lower_mm_blocks_output_f16(htp_lower_orig_mm_for_output(node, in_root))) {
|
||||
return false;
|
||||
if (htp_lower_is_mm_opcode(node.opcode)) {
|
||||
uint32_t w_idx = 0;
|
||||
const ggml_tensor * orig_mm = htp_lower_orig_mm_for_output(node, in_root, &w_idx);
|
||||
if (htp_lower_mm_blocks_output_f16(node, orig_mm, w_idx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1201,7 +1238,7 @@ void htp_lower_graph(const struct ggml_hexagon_session * sess, const struct ggml
|
||||
}
|
||||
for (const ggml_tensor * inp : tnode->inputs) {
|
||||
const ggml_tensor * inp_root = inp ? htp_tensor_root(inp) : nullptr;
|
||||
if (inp_root && can_lower(inp_root) && is_selected_root(inp_root) && apply_root(inp_root)) {
|
||||
if (inp_root && can_lower(inp_root) && apply_root(inp_root)) {
|
||||
expanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "htp/allreduce-ops.h"
|
||||
#include "htp/argsort-ops.h"
|
||||
#include "htp/binary-ops.h"
|
||||
#include "htp/conv2d-ops.h"
|
||||
#include "htp/cumsum-ops.h"
|
||||
#include "htp/diag-ops.h"
|
||||
#include "htp/dsv4-hc-ops.h"
|
||||
@@ -11,11 +12,13 @@
|
||||
#include "htp/gated-delta-net-ops.h"
|
||||
#include "htp/get-rows-ops.h"
|
||||
#include "htp/glu-ops.h"
|
||||
#include "htp/im2col-ops.h"
|
||||
#include "htp/lightning-indexer-ops.h"
|
||||
#include "htp/matmul-ops.h"
|
||||
#include "htp/pad-ops.h"
|
||||
#include "htp/repeat-ops.h"
|
||||
#include "htp/roll-ops.h"
|
||||
#include "htp/set-rows-ops.h"
|
||||
#include "htp/softmax-ops.h"
|
||||
#include "htp/solve-tri-ops.h"
|
||||
#include "htp/ssm-conv.h"
|
||||
@@ -48,6 +51,7 @@ std::string htp_opnode::name() const {
|
||||
}
|
||||
}
|
||||
case HTP_OP_MUL_MAT_ID_NX: return "MUL_MAT_ID_NX";
|
||||
case HTP_OP_MUL_ID: return "MUL_ID";
|
||||
case HTP_OP_ADD:
|
||||
case HTP_OP_SUB:
|
||||
case HTP_OP_MUL:
|
||||
@@ -64,6 +68,15 @@ std::string htp_opnode::name() const {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!node) {
|
||||
switch (opcode) {
|
||||
case HTP_OP_ADD: return "ADD";
|
||||
case HTP_OP_SUB: return "SUB";
|
||||
case HTP_OP_MUL: return "MUL";
|
||||
case HTP_OP_DIV: return "DIV";
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -161,10 +174,11 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
const auto * kparams = node.kparams<htp_mm_kernel_params>();
|
||||
int32_t type = kparams->kernel_type;
|
||||
if (htp_mm_kernel_is_hmx_w8a8(type)) {
|
||||
snprintf(str, max_size, "hmx-w8a8 nhvx %u vtcm %u", (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
snprintf(str, max_size, "hmx-w8a8%s nhvx %u vtcm %u",
|
||||
kparams->norm_w_idx ? "+norm" : "", (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else {
|
||||
const char * path = "unknown";
|
||||
if (type == HTP_MM_KERNEL_HMX_2D || type == HTP_MM_KERNEL_HMX_BATCHED) {
|
||||
if (htp_mm_kernel_is_hmx_f16(type)) {
|
||||
path = (kparams->tile_size > 0) ? "hmx-tiled" : "hmx-flat";
|
||||
} else if (type == HTP_MM_KERNEL_HVX_F16_F16_VTCM || type == HTP_MM_KERNEL_HVX_F32_F32_VTCM ||
|
||||
type == HTP_MM_KERNEL_HVX_BF16_F32_VTCM) {
|
||||
@@ -172,16 +186,17 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
} else if (type == HTP_MM_KERNEL_HVX_QUANT_ROW || type == HTP_MM_KERNEL_HVX_QUANT_BLOCK) {
|
||||
path = "hvx-tiled";
|
||||
}
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u", path, (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
snprintf(str, max_size, "%s%s nhvx %u vtcm %u", path, kparams->norm_w_idx ? "+norm" : "",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
}
|
||||
} else if (node.opcode == HTP_OP_FLASH_ATTN_EXT) {
|
||||
const auto * kparams = node.kparams<htp_fa_kernel_params>();
|
||||
const char * path = "unknown";
|
||||
int32_t type = kparams->kernel_type;
|
||||
if (type == HTP_FA_KERNEL_HMX_F16) {
|
||||
path = kparams->u.hmx.pipeline ? "hmx-f16-pipe" : "hmx-f16-seq";
|
||||
path = (kparams->flags & HTP_FA_FLAG_PIPELINE) ? "hmx-f16-pipe" : "hmx-f16-seq";
|
||||
} else if (type == HTP_FA_KERNEL_HMX_W8A8) {
|
||||
path = kparams->u.hmx.pipeline ? "hmx-w8a8-pipe" : "hmx-w8a8-seq";
|
||||
path = (kparams->flags & HTP_FA_FLAG_PIPELINE) ? "hmx-w8a8-pipe" : "hmx-w8a8-seq";
|
||||
} else if (type == HTP_FA_KERNEL_HVX) {
|
||||
path = "hvx";
|
||||
}
|
||||
@@ -194,11 +209,14 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
snprintf(str, max_size, "idx %d count %d", (int) node.node->op_params[0], (int) node.dst()->ne[1]);
|
||||
} else if ((node.opcode == HTP_OP_FENCE || node.opcode == HTP_OP_CPY_FENCE) && node.node) {
|
||||
snprintf(str, max_size, "seq 0x%x", (uint32_t) node.node->op_params[0]);
|
||||
} else if (node.opcode == HTP_OP_ALLREDUCE && node.node) {
|
||||
snprintf(str, max_size, "seq 0x%x -> 0x%x", (uint32_t) node.node->op_params[0], (uint32_t) node.node->op_params[1]);
|
||||
} else if ((node.opcode == HTP_OP_ALLREDUCE || node.opcode == HTP_OP_ALLREDUCE_ADD) && node.node) {
|
||||
const auto * kparams = node.kparams<htp_allreduce_kernel_params>();
|
||||
snprintf(str, max_size, "seq 0x%x -> 0x%x nhvx %u vtcm %u",
|
||||
(uint32_t) node.node->op_params[0], (uint32_t) node.node->op_params[1],
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_SSM_CONV) {
|
||||
const auto * kparams = node.kparams<htp_ssm_conv_kernel_params>();
|
||||
const char * mode = kparams->token_major
|
||||
const char * mode = (kparams->flags & HTP_SSM_CONV_FLAG_TOKEN_MAJOR)
|
||||
? (kparams->n_t == 1 ? "tok-decode" : "tok-prefill")
|
||||
: (kparams->n_t == 1 ? "decode" : "prefill");
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u", mode,
|
||||
@@ -236,7 +254,7 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->n_tokens_tile,
|
||||
(unsigned int) kparams->kv_block, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_MUL || node.opcode == HTP_OP_ADD || node.opcode == HTP_OP_ADD_ID ||
|
||||
node.opcode == HTP_OP_SUB || node.opcode == HTP_OP_DIV) {
|
||||
node.opcode == HTP_OP_MUL_ID || node.opcode == HTP_OP_SUB || node.opcode == HTP_OP_DIV) {
|
||||
const auto * kparams = node.kparams<htp_binary_kernel_params>();
|
||||
snprintf(str, max_size, "nhvx %u vtcm %u", (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_ARGSORT || node.opcode == HTP_OP_TOP_K) {
|
||||
@@ -273,16 +291,43 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
snprintf(str, max_size, "%s nhvx %u tile %u x%u vtcm %u", ktype_str, (unsigned int) kparams->n_hvx, (unsigned int) kparams->tile_cols, (unsigned int) kparams->n_col_tiles, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_FILL) {
|
||||
const auto * kparams = node.kparams<htp_fill_kernel_params>();
|
||||
snprintf(str, max_size, "%s nhvx %u", kparams->kernel_type == HTP_FILL_KERNEL_CONTIGUOUS ? "contig" : "strided", (unsigned int) kparams->n_hvx);
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u", kparams->kernel_type == HTP_FILL_KERNEL_CONTIGUOUS ? "contig" : "strided",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_ROLL) {
|
||||
const auto * kparams = node.kparams<htp_roll_kernel_params>();
|
||||
snprintf(str, max_size, "k%d nhvx %u", (int) kparams->kernel_type, (unsigned int) kparams->n_hvx);
|
||||
snprintf(str, max_size, "k%d nhvx %u vtcm %u", (int) kparams->kernel_type,
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_DIAG) {
|
||||
const auto * kparams = node.kparams<htp_diag_kernel_params>();
|
||||
snprintf(str, max_size, "nhvx %u chunk %u vtcm %u", (unsigned int) kparams->n_hvx, (unsigned int) kparams->chunk_elems, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_SOLVE_TRI) {
|
||||
const auto * kparams = node.kparams<htp_solve_tri_kernel_params>();
|
||||
snprintf(str, max_size, "%s nhvx %u", kparams->batched ? "batched" : "chunked", (unsigned int) kparams->n_hvx);
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u", (kparams->flags & HTP_SOLVE_TRI_FLAG_BATCHED) ? "batched" : "chunked",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_SUM_ROWS || node.opcode == HTP_OP_SUM || node.opcode == HTP_OP_ARGMAX) {
|
||||
const auto * kparams = node.kparams<htp_sum_rows_kernel_params>();
|
||||
snprintf(str, max_size, "nhvx %u vtcm %u", (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_SET_ROWS) {
|
||||
const auto * kparams = node.kparams<htp_set_rows_kernel_params>();
|
||||
snprintf(str, max_size, "nhvx %u vtcm %u", (unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_CONV_2D || node.opcode == HTP_OP_CONV_3D) {
|
||||
const auto * kparams = node.kparams<htp_conv2d_kernel_params>();
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u",
|
||||
kparams->kernel_type == HTP_CONV2D_KERNEL_HMX_WINDOW ? "window" : "tiled",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_CONV_2D_DW) {
|
||||
const auto * kparams = node.kparams<htp_conv2d_dw_kernel_params>();
|
||||
snprintf(str, max_size, "k%d nhvx %u vtcm %u", (int) kparams->kernel_type,
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_IM2COL || node.opcode == HTP_OP_IM2COL_3D) {
|
||||
const auto * kparams = node.kparams<htp_im2col_kernel_params>();
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u",
|
||||
kparams->kernel_type == HTP_IM2COL_KERNEL_PATCHEMBED_DMA ? "patchembed" : "blocked",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_REPEAT) {
|
||||
const auto * kparams = node.kparams<htp_repeat_kernel_params>();
|
||||
snprintf(str, max_size, "%s nhvx %u vtcm %u", kparams->pipelined ? "pipe" : "tiled",
|
||||
(unsigned int) kparams->n_hvx, (unsigned int) kparams->vtcm_size);
|
||||
} else if (node.opcode == HTP_OP_UPSCALE) {
|
||||
const auto * kparams = node.kparams<htp_upscale_kernel_params>();
|
||||
const char * ktype_str = "unknown";
|
||||
@@ -290,7 +335,7 @@ static std::string format_kernel_params(const htp_opnode & node) {
|
||||
case HTP_UPSCALE_KERNEL_NEAREST: ktype_str = "nearest"; break;
|
||||
case HTP_UPSCALE_KERNEL_NEAREST_2X: ktype_str = "nearest-2x"; break;
|
||||
case HTP_UPSCALE_KERNEL_NEAREST_4X: ktype_str = "nearest-4x"; break;
|
||||
case HTP_UPSCALE_KERNEL_BILINEAR: ktype_str = kparams->align_corners ? "bilinear-ac" : "bilinear"; break;
|
||||
case HTP_UPSCALE_KERNEL_BILINEAR: ktype_str = (kparams->flags & HTP_UPSCALE_FLAG_ALIGN_CORNERS) ? "bilinear-ac" : "bilinear"; break;
|
||||
case HTP_UPSCALE_KERNEL_BILINEAR_2X: ktype_str = "bilinear-2x"; break;
|
||||
case HTP_UPSCALE_KERNEL_BILINEAR_AA: ktype_str = "bilinear-aa"; break;
|
||||
case HTP_UPSCALE_KERNEL_BICUBIC: ktype_str = "bicubic"; break;
|
||||
|
||||
@@ -91,6 +91,13 @@ struct htp_opnode {
|
||||
// Build inputs (preserving optional nullptrs)
|
||||
if (htp_is_hadamard(this->node)) {
|
||||
this->inputs.push_back(this->node->src[1]);
|
||||
} else if (this->node->op == GGML_OP_MUL_MAT) {
|
||||
this->inputs.push_back(this->node->src[0]);
|
||||
this->inputs.push_back(this->node->src[1]);
|
||||
} else if (this->node->op == GGML_OP_MUL_MAT_ID) {
|
||||
this->inputs.push_back(this->node->src[0]);
|
||||
this->inputs.push_back(this->node->src[1]);
|
||||
this->inputs.push_back(this->node->src[2]);
|
||||
} else if (this->node->op != GGML_OP_FILL) {
|
||||
int n_inputs = n_active_src(this->node);
|
||||
for (int i = 0; i < n_inputs; i++) {
|
||||
|
||||
@@ -1602,6 +1602,54 @@ static void repack_tiled_nvfp4(void * data, const ggml_tensor * t, size_t offset
|
||||
}
|
||||
}
|
||||
|
||||
// --- F8_E4M3 (1024 B tile: 32x32 in 4-K-grouped vrmpy byte order, lossless) ---
|
||||
|
||||
static void repack_f8_e4m3_to_tiled(ggml_tensor * t, const void * data, size_t offset, size_t size) {
|
||||
repack_to_tiled_grid_32<uint8_t, 32>(t, data, offset, size, HTP_TENSOR_TILE_SIZE_F8_E4M3,
|
||||
[](uint8_t * tile_dst, const uint8_t * src_slice, int64_t ne0, int64_t ne1, int64_t row_stride, int ct, int kt) {
|
||||
for (int p = 0; p < 8; p++) {
|
||||
const int64_t c_base = (int64_t) kt * 32 + p * 4;
|
||||
for (int row = 0; row < 32; row++) {
|
||||
const int64_t r = (int64_t) ct * 32 + row;
|
||||
const uint8_t * r_ptr = (r < ne1) ? &src_slice[r * row_stride] : nullptr;
|
||||
uint8_t * dst = tile_dst + p * 128 + row * 4;
|
||||
if (r_ptr && c_base + 4 <= ne0) {
|
||||
memcpy(dst, r_ptr + c_base, 4);
|
||||
} else {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
dst[j] = (r_ptr && c_base + j < ne0) ? r_ptr[c_base + j] : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void unpack_f8_e4m3_from_tiled(void * data, const ggml_tensor * t, size_t offset, size_t size) {
|
||||
unpack_from_tiled_grid_32<uint8_t, 32>(data, t, offset, size, HTP_TENSOR_TILE_SIZE_F8_E4M3,
|
||||
[](uint8_t * dst_slice, const uint8_t * tile_src, int64_t ne0, int64_t start_row, int64_t end_row, int64_t row_stride, int ct, int kt) {
|
||||
for (int p = 0; p < 8; p++) {
|
||||
const int64_t c_base = (int64_t) kt * 32 + p * 4;
|
||||
for (int row = 0; row < 32; row++) {
|
||||
const int64_t r = (int64_t) ct * 32 + row;
|
||||
if (r >= start_row && r < end_row) {
|
||||
uint8_t * r_ptr = dst_slice + (r - start_row) * row_stride;
|
||||
const uint8_t * src = tile_src + p * 128 + row * 4;
|
||||
if (c_base + 4 <= ne0) {
|
||||
memcpy(r_ptr + c_base, src, 4);
|
||||
} else {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (c_base + j < ne0) {
|
||||
r_ptr[c_base + j] = src[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --- Top-level Repack / Unpack Dispatchers ---
|
||||
|
||||
void htp_repack_tensor_tiled(ggml_tensor * tensor, const void * data, size_t size) {
|
||||
@@ -1631,6 +1679,9 @@ void htp_repack_tensor_tiled(ggml_tensor * tensor, const void * data, size_t siz
|
||||
case GGML_TYPE_NVFP4:
|
||||
repack_nvfp4_tiled(tensor, data, 0, size);
|
||||
break;
|
||||
case GGML_TYPE_F8_E4M3:
|
||||
repack_f8_e4m3_to_tiled(tensor, data, 0, size);
|
||||
break;
|
||||
case GGML_TYPE_IQ2_XXS:
|
||||
repack_iq2_xxs_tiled(tensor, data, 0, size);
|
||||
break;
|
||||
@@ -1698,6 +1749,9 @@ void htp_unpack_tensor_tiled(void * data, const ggml_tensor * tensor, size_t off
|
||||
case GGML_TYPE_NVFP4:
|
||||
repack_tiled_nvfp4(data, tensor, offset, size);
|
||||
break;
|
||||
case GGML_TYPE_F8_E4M3:
|
||||
unpack_f8_e4m3_from_tiled(data, tensor, offset, size);
|
||||
break;
|
||||
case GGML_TYPE_IQ2_XXS:
|
||||
repack_tiled_iq2_xxs(data, tensor, offset, size);
|
||||
break;
|
||||
|
||||
@@ -17,7 +17,11 @@ static inline bool htp_is_tiled_weight_type(enum ggml_type type) {
|
||||
type == GGML_TYPE_Q2_K || type == GGML_TYPE_Q3_K ||
|
||||
type == GGML_TYPE_Q4_K || type == GGML_TYPE_Q5_K ||
|
||||
type == GGML_TYPE_F16 || type == GGML_TYPE_F32 ||
|
||||
type == GGML_TYPE_BF16;
|
||||
type == GGML_TYPE_BF16 || type == GGML_TYPE_F8_E4M3;
|
||||
}
|
||||
|
||||
static inline bool htp_is_quantized_weight_type(enum ggml_type type) {
|
||||
return ggml_is_quantized(type) || type == GGML_TYPE_F8_E4M3;
|
||||
}
|
||||
|
||||
static inline bool htp_is_tiled_weight_tensor(const struct ggml_tensor * t) {
|
||||
@@ -30,7 +34,7 @@ static inline bool htp_is_tiled_weight_tensor(const struct ggml_tensor * t) {
|
||||
if (t->ne[0] < 32 || (t->ne[0] % 32 != 0) || t->ne[3] != 1) {
|
||||
return false;
|
||||
}
|
||||
if (!ggml_is_quantized(t->type)) {
|
||||
if (!htp_is_quantized_weight_type(t->type)) {
|
||||
return t->ne[1] > 1;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -23,6 +23,9 @@ add_library(${HTP_LIB} SHARED
|
||||
hmx-queue.c
|
||||
htp-tensor.c
|
||||
matmul-ops.c
|
||||
matmul-hmx-w8a8.c
|
||||
matmul-hmx-f16.c
|
||||
matmul-hvx.c
|
||||
flash-attn-ops.c
|
||||
gated-delta-net-ops.c
|
||||
binary-ops.c
|
||||
|
||||
@@ -21,7 +21,6 @@ struct htp_allreduce_context {
|
||||
uint32_t n_dsts;
|
||||
uint32_t nelem;
|
||||
uint32_t ne0;
|
||||
uint32_t ne1;
|
||||
uint32_t row_size_aligned;
|
||||
uint32_t rank_elem_start;
|
||||
uint32_t rank_nelem;
|
||||
@@ -251,38 +250,6 @@ DEFINE_ALLREDUCE_THREAD_DMA_2D(add_f32, float, hvx_add_f32_aaa, 1, 0)
|
||||
DEFINE_ALLREDUCE_THREAD_DMA_2D(add_bcast_f16, __fp16, hvx_add_f16_aaa, 1, 1)
|
||||
DEFINE_ALLREDUCE_THREAD_DMA_2D(add_bcast_f32, float, hvx_add_f32_aaa, 1, 1)
|
||||
|
||||
static int validate_allreduce(
|
||||
struct htp_ops_context * octx,
|
||||
const struct htp_allreduce_kernel_params * kparams,
|
||||
uint32_t n_ranks
|
||||
) {
|
||||
if (kparams->n_hvx == 0 || (uint32_t) kparams->n_hvx > octx->ctx->n_hvx) {
|
||||
return HTP_STATUS_INVAL_PARAMS;
|
||||
}
|
||||
octx->n_hvx = (uint32_t) kparams->n_hvx;
|
||||
|
||||
if (kparams->vtcm_size_per_hvx <= 0 || kparams->vtcm_size <= 0) {
|
||||
return HTP_STATUS_INVAL_PARAMS;
|
||||
}
|
||||
|
||||
const bool has_add = (octx->op == HTP_OP_ALLREDUCE_ADD);
|
||||
const size_t n_vtcm_buffers = htp_allreduce_vtcm_buffer_count(
|
||||
n_ranks, octx->n_hvx, has_add, kparams->is_row_bcast != 0);
|
||||
const size_t vtcm_size = n_vtcm_buffers * (size_t) kparams->vtcm_size_per_hvx;
|
||||
if (vtcm_size != (size_t) kparams->vtcm_size) {
|
||||
return HTP_STATUS_INVAL_PARAMS;
|
||||
}
|
||||
if (vtcm_size > octx->ctx->vtcm_size) {
|
||||
return HTP_STATUS_VTCM_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (octx->dst->type != HTP_TYPE_F16 && octx->dst->type != HTP_TYPE_F32) {
|
||||
return HTP_STATUS_NO_SUPPORT;
|
||||
}
|
||||
|
||||
return HTP_STATUS_OK;
|
||||
}
|
||||
|
||||
int op_allreduce(struct htp_ops_context * octx) {
|
||||
if (octx->ctx->mdev.count > 1 && octx->ctx->mdev.idx > 0) {
|
||||
return HTP_STATUS_OK;
|
||||
@@ -294,28 +261,24 @@ int op_allreduce(struct htp_ops_context * octx) {
|
||||
const uint32_t rank = (uint32_t) kparams->rank;
|
||||
const uint32_t n_ranks = (uint32_t) kparams->n_ranks;
|
||||
|
||||
if (n_ranks < 2 || n_ranks > HTP_ALLREDUCE_MAX_RANKS || rank >= n_ranks) {
|
||||
return HTP_STATUS_INVAL_PARAMS;
|
||||
}
|
||||
|
||||
const uint32_t fence_seq_entry = (uint32_t) octx->op_params[0];
|
||||
const uint32_t fence_seq_exit = (uint32_t) octx->op_params[1];
|
||||
|
||||
const struct htp_tensor * my_sync = octx->src[n_ranks + rank];
|
||||
atomic_uint * my_fence = (atomic_uint *) (uintptr_t) my_sync->data;
|
||||
|
||||
const int status = validate_allreduce(octx, kparams, n_ranks);
|
||||
if (status != HTP_STATUS_OK) {
|
||||
if (status == HTP_STATUS_NO_SUPPORT) {
|
||||
FARF(ERROR, "ggml-hex: allreduce unsupported type %d : rank %u\n", dst->type, rank);
|
||||
}
|
||||
htp_fence_write(my_fence, fence_seq_exit, status);
|
||||
return status;
|
||||
if (!htp_ops_context_set_n_hvx(octx, (uint32_t) kparams->n_hvx)) {
|
||||
htp_fence_write(my_fence, fence_seq_exit, HTP_STATUS_INVAL_PARAMS);
|
||||
return HTP_STATUS_INVAL_PARAMS;
|
||||
}
|
||||
if ((size_t) kparams->vtcm_size > octx->ctx->vtcm_size) {
|
||||
htp_fence_write(my_fence, fence_seq_exit, HTP_STATUS_VTCM_TOO_SMALL);
|
||||
return HTP_STATUS_VTCM_TOO_SMALL;
|
||||
}
|
||||
|
||||
const bool has_add = (octx->op == HTP_OP_ALLREDUCE_ADD);
|
||||
const uint32_t nelem = dst->ne[0] * dst->ne[1] * dst->ne[2] * dst->ne[3];
|
||||
const int32_t mode = kparams->mode;
|
||||
const bool sharded_fanout = (kparams->flags & HTP_ALLREDUCE_FLAG_SHARDED_FANOUT) != 0;
|
||||
|
||||
// 1. Entry Barrier: Synchronize all ranks before reading
|
||||
struct htp_thread_trace * tr0 = &octx->ctx->trace[0];
|
||||
@@ -368,14 +331,13 @@ int op_allreduce(struct htp_ops_context * octx) {
|
||||
actx.n_dsts = (uint32_t) kparams->n_dsts ? (uint32_t) kparams->n_dsts : n_ranks;
|
||||
actx.nelem = nelem;
|
||||
actx.ne0 = (uint32_t) kparams->ne0;
|
||||
actx.ne1 = (uint32_t) kparams->ne1;
|
||||
actx.row_size_aligned = (uint32_t) kparams->row_size_aligned;
|
||||
actx.rank_elem_start = (uint32_t) kparams->rank_elem_start;
|
||||
actx.rank_nelem = (uint32_t) kparams->rank_nelem;
|
||||
actx.elems_per_hvx = elems_per_hvx;
|
||||
actx.block_elems = block_elems;
|
||||
actx.vtcm_size_per_hvx = vtcm_size_per_hvx;
|
||||
actx.is_row_bcast = (kparams->is_row_bcast != 0);
|
||||
actx.is_row_bcast = (kparams->flags & HTP_ALLREDUCE_FLAG_ROW_BCAST) != 0;
|
||||
|
||||
work_queue_func_t reduce_fun = NULL;
|
||||
switch (kparams->kernel_type) {
|
||||
@@ -388,7 +350,7 @@ int op_allreduce(struct htp_ops_context * octx) {
|
||||
break;
|
||||
case HTP_ALLREDUCE_KERNEL_DMA_2D:
|
||||
if (has_add) {
|
||||
if (kparams->is_row_bcast) {
|
||||
if (actx.is_row_bcast) {
|
||||
reduce_fun = (dst->type == HTP_TYPE_F16) ? allreduce_thread_dma_2d_add_bcast_f16 : allreduce_thread_dma_2d_add_bcast_f32;
|
||||
} else {
|
||||
reduce_fun = (dst->type == HTP_TYPE_F16) ? allreduce_thread_dma_2d_add_f16 : allreduce_thread_dma_2d_add_f32;
|
||||
@@ -430,7 +392,7 @@ int op_allreduce(struct htp_ops_context * octx) {
|
||||
htp_trace_event_start(tr0, HTP_TRACE_EVT_FENCE, (uint16_t) fence_seq_exit);
|
||||
|
||||
// drain fan-out DMA writes before exit barrier
|
||||
if (mode == HTP_ALLREDUCE_SHARDED_FANOUT) {
|
||||
if (sharded_fanout) {
|
||||
asm volatile ("syncht" : : : "memory");
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user