Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

Release 2026-10-13 (2): a discrete GPU's results reach the CPU again (issue #17), janas-bench says that the GPU reads a prompt in every configuration (issue #16)

camauri605b286a3b29
diff --git a/ChangeLog.md b/ChangeLog.md
index ce11efe..855c912 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -2,6 +2,18 @@
> Curated, user-facing summary of completed work, newest first.
+## [2026-10-13] - janas-bench says what the GPU does
+
+- **`janas-bench` says that the GPU reads a prompt in every configuration** (issue #16, a Radeon 780M): with the fast prompt a prompt's blocks of 64 tokens or more go to the GPU whether a row says "+ GPU" or not, so that a prompt gives the same results in each, and the rows without it had been read as the CPU alone, the GPU as of no help where it read Qwen3-4B's prompt 5.2 times faster (477 against 92 tokens/s). A note under the table now says so; "+ GPU" is the GPU's part in the shorter passes.
+- **`JANAS_GPU_VERBOSE` puts the calls the GPU does whole on lines of their own** ("gpu alone"): the CPU waits there with nothing to do, and they had been counted as a GPU late, with a share that does not apply to them. Reporting only: the share is learned as before.
+- **The hardware page tells what testers found**: on the 780M subgroups of 32 (`JANAS_GPU_SG=32`) cost 14% against the 64 the engine chooses, and on discrete cards the defect of issue #17.
+
+
+## [2026-10-13] - A discrete GPU's results reach the CPU again
+
+- **On a GPU with memory of its own the products' results reach the CPU again** (issue #17, reported and diagnosed by xpil on a Quadro RTX 5000, with the fix's first form and its test): since the release of 10 October the engine registered its output buffers with the GPU, so that one sharing the host's memory writes them in place, but on a discrete card a registration is a copy in the card's memory, and the CPU went on reading what its buffers held before. Results are written in place only where the GPU shares the host's memory; elsewhere they come back through the staging buffer, as before 10 October. `test_gpu_output_copy` checks it on any GPU (`JANAS_GPU_COPY=1` gives an integrated one the copy path): -12345 instead of 256 before the fix, 256 with it. On that path Qwen3-4B read a prompt in blocks of 64 tokens with the most likely token as read token by token at 0 of 64 positions before the fix (mean difference of the logits 5.73), and at 61 with it (0.098, the fast prompt's usual rounding).
+
+
## [2026-10-13] - The GPU's passes of a few tokens
- **Qwen3.8-27B's drafts verified on the GPU a little faster, 7.7 tokens/s in two runs against 7.6 and 7.0** (`JANAS_GPU_SHORT=1`, 64 tokens of code): no chain longer than the GPU's shaders of a few vectors take (a ninth token doubled the pass: 854 ms against 437 for 5), and the recurrent layers' betas and decays read their inputs a quarter as often (3.7 ms a pass of 8 tokens where they took 13.5), with the same results to the bit.
diff --git a/docs/hardware.md b/docs/hardware.md
index 55867c2..70cf76c 100644
--- a/docs/hardware.md
+++ b/docs/hardware.md
@@ -6,7 +6,7 @@
bin/x86_64-linux/janas-bench qwen3-4b
```
-It takes the model as `janas-chat` does: a name of the models Janas knows (downloaded, after asking, if it is not there yet), a `.jns` file, or nothing, and then the list to choose from; the model's prediction file comes with it as in the chat (`--no-mtp`: without). Close what you can before running it: it measures the machine you give it, and a browser with thirty tabs is part of the machine. It tries the configurations the machine offers — how many threads, which cores, with and without the GPU — on real passes of the model, keeps the fastest, writes them into `~/.cache/janas` so the next start begins from them, and leaves a report in the current directory. On the development laptop that report says, among other things (10 October 2026, ten models), that a single token and a prompt go fastest on the performance cores' 12 threads, while a draft check - a few tokens at once - goes fastest on all the usable cores: the kinds of pass want different threads, which is why each is tuned on its own.
+It takes the model as `janas-chat` does: a name of the models Janas knows (downloaded, after asking, if it is not there yet), a `.jns` file, or nothing, and then the list to choose from; the model's prediction file comes with it as in the chat (`--no-mtp`: without). Close what you can before running it: it measures the machine you give it, and a browser with thirty tabs is part of the machine. It tries the configurations the machine offers — how many threads, which cores, with and without the GPU — on real passes of the model, keeps the fastest, writes them into `~/.cache/janas` so the next start begins from them, and leaves a report in the current directory. With the fast prompt the GPU reads a prompt's blocks in every configuration, so a row without "+ GPU" is not the CPU alone; the report says so under its table. On the development laptop that report says, among other things (10 October 2026, ten models), that a single token and a prompt go fastest on the performance cores' 12 threads, while a draft check - a few tokens at once - goes fastest on all the usable cores: the kinds of pass want different threads, which is why each is tuned on its own.
## Helping it run on more hardware
@@ -39,12 +39,14 @@ The [hardware report form](https://github.com/prabanta-dev/janas/issues/new?temp
**What is most wanted, in order.**
1. **CPUs without AVX-VNNI**, and **AMD** — the arithmetic has a path for them and it is the least exercised of all.
-2. **Discrete GPUs** (NVIDIA, AMD, Intel Arc). The GPU support is correct - bit for bit on a reply's tokens, and on a prompt as close to the references as the CPU - and it pays where it was measured: on the development laptop's integrated GPU, with the fast prompt, Qwen3-4B reads a prompt 2.6 times faster than without the GPU (85 to 220 tokens/s; before the fast prompt, 83 to 107), and on an RTX 5080 (issue #15) Qwen3-4B read 13% faster and, with the GPU on single tokens too, replied 11-16% faster. Every other card is unknown, and the fast prompt has not run on a discrete one yet (`JANAS_GPU_FAST_PROMPT=0` turns it off if it misbehaves). **Careful:** a GPU driver reset takes the desktop with it. Start with `janas-bench`, not with a long chat.
+2. **Discrete GPUs** (NVIDIA, AMD, Intel Arc). The GPU support is correct where it was checked - bit for bit on a reply's tokens, and on a prompt as close to the references as the CPU - and it pays where it was measured: on the development laptop's integrated GPU, with the fast prompt, Qwen3-4B reads a prompt 2.6 times faster than without the GPU (85 to 220 tokens/s; before the fast prompt, 83 to 107), and on an RTX 5080 (issue #15) Qwen3-4B read 13% faster and, with the GPU on single tokens too, replied 11-16% faster. From the release of 10 October to that of 13 October a discrete card's results stayed in its own memory, where the CPU never read them (issue #17, corrupted output on a Quadro RTX 5000); fixed since, and checked here on the path such a card takes, not yet on one. Every other card is unknown, and the fast prompt has not been seen working on a discrete one yet (`JANAS_GPU_FAST_PROMPT=0` turns it off if it misbehaves). **Careful:** a GPU driver reset takes the desktop with it. Start with `janas-bench`, not with a long chat.
3. **Machines with 16 GB or less.** The engine is supposed to trade quality for memory on its own — fewer bits per weight, light experts not in memory left out — and the thresholds for that were measured on 32 GB.
4. **Slower disks.** Everything assumes an NVMe SSD; on a SATA disk the engine should still work and simply wait more, but nobody has watched it do so.
5. **Windows on other machines.** The Windows build has run on one laptop, the development one (Windows 11, build 26300), where its tests pass and it is as fast as on Linux; `janas-bench`'s report from any other is welcome.
6. **Other models** of the supported families. A file that will not convert, or converts and then answers nonsense, is a useful bug.
+**What testers found so far.** On a Radeon 780M (Ryzen 7 255, issue #16) the GPU read Qwen3-4B's prompt 5.2 times faster than the CPU alone (477 against 92 tokens/s, the second with `JANAS_GPU_FAST_PROMPT=0`), and subgroups of 32 (`JANAS_GPU_SG=32`) instead of the 64 the engine chose cost 14% (405 against 470 tokens/s): the default is right there. On a Quadro RTX 5000 (issue #17) the defect above.
+
**What not to bother with yet:** macOS (not supported), and models outside the Qwen3, Qwen3.5, Qwen3.6, Qwen3-Next and Gemma 4 families (they are refused with a message).
Patches are welcome too, but a measurement from a machine nobody here can buy is worth more than most patches.
diff --git a/src/bench/main.c b/src/bench/main.c
index d60d9de..e31f3da 100644
--- a/src/bench/main.c
+++ b/src/bench/main.c
@@ -16,6 +16,10 @@
* the configurations measured on a warm cache, as a
* chat runs after its first minutes)
*
+ * With the fast prompt the GPU reads a prompt's blocks in every
+ * configuration, "+ GPU" or not, and the report says so under the table;
+ * "+ GPU" is its part in the shorter passes.
+ *
* The model is taken as janas-chat takes it (common/model_pick.c): a .jns
* file, a name of the catalog (qwen3-4b), downloaded if it is not there
* yet, or nothing, and then the list to choose from. Its prediction file
@@ -434,6 +438,18 @@ int main(int argc, char **argv)
out("%-22s %8.1f tok/s %6.1f tok/s %12s %12s %8.1f%%\n", name,
r->prefill, r->decode, mt, ms, r->hits);
}
+ /* the fast prompt runs on the GPU in every row, so that a prompt gives
+ the same results whatever the configuration: the rows without
+ "+ GPU" are not the CPU alone (issue #16 read them so, and found the
+ GPU of no help where it read the prompt 5.2 times faster) */
+ int cpu_rows = 0;
+ for (int c = 0; c < nc; c++)
+ cpu_rows += !gp[c];
+ if (cpu_rows && janas_llm_model_gpu_prompts(m))
+ out("note: in every row the GPU reads a prompt's blocks of %d "
+ "tokens or more (the fast prompt); \"+ GPU\" also gives it a "
+ "part in the shorter passes\n",
+ JANAS_GPU_FAST_N);
janas_llm_model_force(m, -1);
char tune[512];
int32_t tn;
diff --git a/src/llm/gpu.c b/src/llm/gpu.c
index db22a87..7294ad9 100644
--- a/src/llm/gpu.c
+++ b/src/llm/gpu.c
@@ -749,21 +749,33 @@ void janas_gpu_destroy(struct janas_gpu *g)
if (g->verbose)
fprintf(stderr, "gpu begin: convert %.3f s, submit %.3f s\n", g->t_conv,
g->t_sub);
- for (int i = 0; g->verbose && i < SHARE_SLOTS; i++)
- if (g->share[i].calls)
+ /* the key: (group's products << 48) ^ (rows << 24) ^ (columns << 8) ^
+ vectors, of its first product. Calls with every row on the GPU (the
+ fast prompt's) apart: there the CPU waits having nothing to do, and
+ neither "late" nor the share says anything (issue #16 read them as a
+ GPU always behind) */
+ for (int i = 0; g->verbose && i < SHARE_SLOTS; i++) {
+ const struct share *s = &g->share[i];
+ if (!s->calls)
+ continue;
+ double c = 1e6 / s->calls;
+ if (s->alone == s->calls)
+ fprintf(stderr,
+ "gpu alone: key %016llx, %u calls with every row on the "
+ "GPU; us/call: begin %.0f wait %.0f copy %.0f\n",
+ (unsigned long long)s->key, s->calls, c * s->t_begin,
+ c * s->t_wait, c * s->t_copy);
+ else
fprintf(
stderr,
- "gpu share: key %016llx, %u calls, GPU late in %u, "
- "share %.2f (mean %.2f); us/call: begin %.0f cpu %.0f "
- "wait %.0f copy %.0f\n",
- (unsigned long long)g->share[i].key, g->share[i].calls,
- g->share[i].waits, g->share[i].f,
- (double)g->share[i].rows_gpu /
- (double)(g->share[i].rows_all ? g->share[i].rows_all : 1),
- 1e6 * g->share[i].t_begin / g->share[i].calls,
- 1e6 * g->share[i].t_cpu / g->share[i].calls,
- 1e6 * g->share[i].t_wait / g->share[i].calls,
- 1e6 * g->share[i].t_copy / g->share[i].calls);
+ "gpu share: key %016llx, %u calls (%u with every row on "
+ "the GPU), GPU late in %u of the others, share %.2f "
+ "(mean %.2f); us/call: begin %.0f cpu %.0f wait %.0f "
+ "copy %.0f\n",
+ (unsigned long long)s->key, s->calls, s->alone, s->waits, s->f,
+ (double)s->rows_gpu / (double)(s->rows_all ? s->rows_all : 1),
+ c * s->t_begin, c * s->t_cpu, c * s->t_wait, c * s->t_copy);
+ }
if (g->ka_running) {
atomic_store(&g->ka_stop, 1);
pthread_join(g->ka, NULL);
@@ -1070,6 +1082,7 @@ static int copy_to_device(struct janas_gpu *g, const void *p, size_t bytes)
rg->bytes = bytes;
rg->addr = janas_g_buffer_address(g, rg->buf);
rg->coherent = 1;
+ rg->host_shared = 0;
g->n_reg++;
return 0;
@@ -1135,6 +1148,7 @@ int janas_gpu_import(struct janas_gpu *g, const void *p, size_t bytes)
rg->bytes = bytes;
rg->addr = janas_g_buffer_address(g, rg->buf);
rg->coherent = 1;
+ rg->host_shared = 1;
g->n_reg++;
return 0;
}
@@ -1182,6 +1196,7 @@ void *janas_gpu_alloc(struct janas_gpu *g, size_t bytes)
rg->addr = janas_g_buffer_address(g, rg->buf);
rg->coherent = (g->mp.memoryTypes[t].propertyFlags &
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
+ rg->host_shared = 1;
g->n_reg++;
return p;
}
@@ -1368,11 +1383,14 @@ int janas_gpu_begin(struct janas_gpu *g, const struct janas_matvec_task *tasks,
n_xc++;
}
/* an output the GPU shares (the engine's buffers, imported at
- load): written there, rows as the CPU lays them out, no copy */
+ load): written there, rows as the CPU lays them out, no copy.
+ Not a card's copy of it, which the GPU's writes would never
+ leave - the CPU read what was there before (issue #17): through
+ the stage then */
size_t ystr = t->y_stride ? t->y_stride : t->rows;
const struct region *yr = janas_g_find_region(
g, t->y, ((nv - 1) * ystr + gpu_rows[i]) * sizeof(float));
- if (yr) {
+ if (yr && yr->host_shared) {
if (janas_g_record_task(
g, &bound, t, gpu_rows[i], g->xs.addr + xc[k].off,
yr->addr +
@@ -2038,7 +2056,7 @@ static int experts_id(struct janas_gpu *g, struct janas_pool *pool,
janas_g_find_region(g, t[i].w, read_bytes(&t[i], t[i].rows));
const struct region *yr = janas_g_find_region(
g, t[i].y, ((nv - 1) * ys + t[i].rows) * sizeof(float));
- if (!wr || !yr)
+ if (!wr || !yr || !yr->host_shared) /* outputs written in place */
return -1;
uint32_t *e = tb + 12 * ng++;
janas_g_push_addr(
@@ -2164,7 +2182,8 @@ int janas_gpu_dense_mm(struct janas_gpu *g, int bf16, const void *w,
janas_g_find_region(g, w, rows * cols * (bf16 ? 2 : 4));
const struct region *xr = janas_g_find_region(g, x, n * cols * 4);
const struct region *yr = janas_g_find_region(g, y, n * rows * 4);
- if (!wr || !xr || !yr)
+ /* x read and y written in place: the host's own memory only */
+ if (!wr || !xr || !yr || !xr->host_shared || !yr->host_shared)
return -1;
if (g->vkResetCommandBuffer(g->cb, 0) != VK_SUCCESS)
return -1;
@@ -2330,7 +2349,10 @@ void janas_gpu_matvec_group(struct janas_gpu *g, struct janas_pool *pool,
if (nv >= g->full_n) {
if (g->verbose && sh) {
sh->calls++;
- sh->waits += (uint32_t)waited;
+ if (any == all)
+ sh->alone++;
+ else
+ sh->waits += (uint32_t)waited;
sh->t_begin += t1 - t0;
sh->t_cpu += t2 - t1;
sh->t_wait += g->t_waited;
@@ -2352,7 +2374,10 @@ void janas_gpu_matvec_group(struct janas_gpu *g, struct janas_pool *pool,
}
/* late GPU: less next time; early: more */
sh->calls++;
- sh->waits += (uint32_t)waited;
+ if (any == all)
+ sh->alone++; /* reported apart; the share learns as before */
+ else
+ sh->waits += (uint32_t)waited;
if (waited && sh->f <= 0.05f) {
sh->off = 256; /* not worth it for this shape: retry later */
return;
diff --git a/src/llm/gpu.h b/src/llm/gpu.h
index 945b567..a840d7f 100644
--- a/src/llm/gpu.h
+++ b/src/llm/gpu.h
@@ -146,5 +146,10 @@ size_t janas_gpu_min_n(const struct janas_gpu *g);
beyond which a product goes to the slower shaders of many vectors: 8,
or 0 without them. */
size_t janas_gpu_few_max(const struct janas_gpu *g);
+/* Whether the GPU reads and writes the host's memory in place (an
+ integrated GPU with the host-memory import, not JANAS_GPU_COPY): what the
+ whole token needs, and what makes the engine's buffers worth importing.
+ On a card with memory of its own an import is a copy. */
+int janas_gpu_shares_host(const struct janas_gpu *g);
#endif
diff --git a/src/llm/gpu_impl.h b/src/llm/gpu_impl.h
index 73b2f56..31309ea 100644
--- a/src/llm/gpu_impl.h
+++ b/src/llm/gpu_impl.h
@@ -104,6 +104,10 @@ struct region {
VkDeviceMemory mem;
VkDeviceAddress addr;
int coherent; /* allocated regions: else flushed after host writes */
+ /* the host's own memory (imported, or the driver's mapped): what the
+ GPU writes there the CPU reads. 0: a copy in a card's own memory
+ (copy_to_device), which the GPU's writes never leave */
+ int host_shared;
};
struct stage {
@@ -202,7 +206,9 @@ struct janas_gpu {
struct share {
uint64_t key;
float f;
- uint32_t calls, waits;
+ /* alone: calls with every row on the GPU, where the CPU waits
+ having nothing to do; waits: the others the GPU was late in */
+ uint32_t calls, waits, alone;
double t_begin, t_cpu, t_wait, t_copy; /* seconds, verbose only */
uint64_t rows_gpu, rows_all;
uint32_t off; /* calls left on the CPU alone */
diff --git a/src/llm/gpu_token.h b/src/llm/gpu_token.h
index a1df0cb..d025010 100644
--- a/src/llm/gpu_token.h
+++ b/src/llm/gpu_token.h
@@ -144,8 +144,4 @@ int janas_gpu_tok_run(struct janas_gpu *g, struct janas_gpu_tok *t,
uint32_t src, uint32_t dst, uint32_t replay,
uint32_t log_row);
-/* Whether the GPU reads the host's memory in place (an integrated GPU with
- the host-memory import, not JANAS_GPU_COPY): what the token needs. */
-int janas_gpu_shares_host(const struct janas_gpu *g);
-
#endif
diff --git a/src/llm/model_load.c b/src/llm/model_load.c
index 8133fe3..da0bf54 100644
--- a/src/llm/model_load.c
+++ b/src/llm/model_load.c
@@ -1206,9 +1206,14 @@ struct janas_llm_model *janas_llm_model_load(const char *path,
/* the products' outputs too, so that the GPU writes them where the
engine reads them: through a staging buffer they cost a copy on
one thread, 0.4-2.8 ms a block of a layer on Qwen3-4B (9 Oct
- 2026). One that cannot be shared keeps the copy. */
- for (int i = 0; i < m->n_out; i++)
- janas_gpu_import(m->gpu, m->out[i].p, m->out[i].bytes);
+ 2026). One that cannot be shared keeps the copy. Only where the
+ GPU shares the host's memory: on a card with memory of its own an
+ import is a copy there, which the GPU's writes never left - the
+ CPU read stale outputs, a Quadro RTX 5000 garbled its answers
+ (issue #17) */
+ if (janas_gpu_shares_host(m->gpu))
+ for (int i = 0; i < m->n_out; i++)
+ janas_gpu_import(m->gpu, m->out[i].p, m->out[i].bytes);
}
janas_m_init_tuner(m);
return m;
diff --git a/tests/test_gpu_output_copy.c b/tests/test_gpu_output_copy.c
new file mode 100644
index 0000000..57a397f
--- /dev/null
+++ b/tests/test_gpu_output_copy.c
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ Copyright (C) 2026 Maurizio Cammalleri */
+/*
+ * test_gpu_output_copy.c - on a GPU with memory of its own the engine's
+ * buffers, imported, are copies on the card: a product whose output is one
+ * of them must still reach the host (issue #17, reported with this test's
+ * first form by xpil: a Quadro RTX 5000's outputs stayed on the card and
+ * the CPU read what was there before). JANAS_GPU_COPY=1 gives any GPU that
+ * path. A Q4_K row of 256 ones times 256 ones is 256; a dense product of
+ * ones over 64 columns is 64; the host's buffers start at -12345.
+ * Every buffer lives until the GPU is gone: a region is never dropped, and
+ * a buffer freed and allocated again at its address would be read from
+ * the old one's copy (the staged product read the first one's output as
+ * its weights, 13 Oct 2026). Skipped without a GPU.
+ */
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common/pool.h"
+#include "llm/gpu.h"
+#include "llm/matvec.h"
+#include "llm/quant.h"
+
+static void *kept[8];
+static int n_kept;
+
+/* aligned, and freed only after the GPU (see above) */
+static void *buffer(size_t bytes)
+{
+ void *p = aligned_alloc(4096, bytes);
+ if (p && n_kept < 8)
+ kept[n_kept++] = p;
+ return p;
+}
+
+static int product(struct janas_gpu *g, struct janas_pool *pool, int imported)
+{
+ const size_t rows = 1, cols = 256, bytes = 4096;
+ struct janas_block_q4k *w = buffer(bytes);
+ float *y = buffer(4096);
+ memset(w, 0, bytes);
+ w[0].d = janas_fp32_to_fp16(1.0f);
+ for (int i = 0; i < 4; i++)
+ w[0].scales[i] = 1;
+ for (int i = 8; i < 12; i++)
+ w[0].scales[i] = 1;
+ memset(w[0].qs, 0x11, sizeof(w[0].qs));
+ float xf[256], ref = 0;
+ for (int i = 0; i < 256; i++)
+ xf[i] = 1.0f;
+ struct janas_block_q8k x;
+ janas_q8k_quantize(xf, &x, cols);
+ for (int i = 0; i < 1024; i++)
+ y[i] = -12345.0f;
+ struct janas_matvec_task t = {.type = JANAS_Q4_K,
+ .w = w,
+ .x = &x,
+ .y = &ref,
+ .rows = rows,
+ .cols = cols,
+ .n_vec = 1};
+ janas_matvec_q4k_group(pool, &t, 1);
+ t.y = y;
+ int rc = 0, waited = 0;
+ size_t nr = rows;
+ if (janas_gpu_import(g, w, bytes) != 0 ||
+ (imported && janas_gpu_import(g, y, 4096) != 0) ||
+ janas_gpu_begin(g, &t, &nr, 1) < 0 ||
+ janas_gpu_finish(g, &waited) != 0) {
+ printf("FAIL: the %s product did not run\n",
+ imported ? "imported" : "staged");
+ rc = 1;
+ } else if (y[0] != ref) {
+ printf("FAIL: %s output %g, the CPU's %g%s\n",
+ imported ? "imported" : "staged", y[0], ref,
+ y[0] == -12345.0f ? " (never written back)" : "");
+ rc = 1;
+ }
+ return rc;
+}
+
+static int dense(struct janas_gpu *g)
+{
+ const size_t rows = 64, cols = 64, n = 64;
+ float *w = buffer(16384), *x = buffer(16384), *y = buffer(16384);
+ for (size_t i = 0; i < rows * cols; i++)
+ w[i] = x[i] = 1.0f;
+ for (size_t i = 0; i < 4096; i++)
+ y[i] = -12345.0f;
+ int rc = 0;
+ if (janas_gpu_import(g, w, 16384) != 0 ||
+ janas_gpu_import(g, x, 16384) != 0 ||
+ janas_gpu_import(g, y, 16384) != 0) {
+ printf("FAIL: dense buffers not imported\n");
+ rc = 1;
+ } else if (janas_gpu_dense_mm(g, 0, w, x, y, rows, cols, n, 1.0f) == 0) {
+ /* run, then right: refusing (the CPU's then) is right too */
+ for (size_t i = 0; i < rows * n && !rc; i++)
+ if (y[i] != 64.0f) {
+ printf("FAIL: dense output %zu is %g, not 64\n", i, y[i]);
+ rc = 1;
+ }
+ }
+ return rc;
+}
+
+int main(void)
+{
+ const char *e = getenv("JANAS_GPU");
+ if (e && atoi(e) == 0) {
+ printf("test_gpu_output_copy: GPU disabled, skipped\n");
+ return 0;
+ }
+ setenv("JANAS_GPU_COPY", "1", 1); /* a card's path, on any GPU */
+ char err[256];
+ struct janas_gpu *g = janas_gpu_create(err, sizeof(err));
+ if (!g) {
+ printf("test_gpu_output_copy: no GPU (%s), skipped\n", err);
+ return 0;
+ }
+ struct janas_pool *pool = janas_pool_create(4, NULL);
+ int rc = product(g, pool, 1) | product(g, pool, 0) | dense(g);
+ janas_pool_destroy(pool);
+ janas_gpu_destroy(g);
+ for (int i = 0; i < n_kept; i++)
+ free(kept[i]);
+ if (!rc)
+ printf("test_gpu_output_copy: ok\n");
+ return rc;
+}