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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions crates/celox-runtime/src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ impl Shared {
timing.waits.push((other, completed, start, trace.nanos()));
}
}
if !aborted {
// A failed producer publishes its abort before its progress. The
// acquire above may satisfy the wait without entering the loop,
// so reload abort after observing that progress.
if !aborted && !self.abort.0.load(Ordering::Acquire) {
if let (Some(trace), Some(timing)) = (trace, &mut timing) {
timing.start = trace.nanos();
}
Expand Down Expand Up @@ -640,19 +643,25 @@ mod tests {
#[test]
fn failures_skip_pending_work_and_report_the_first_task() {
let (schedule, predecessors) = chain_schedule();
let mut pool = LanePool::new(3).unwrap();
let runner = recorder(predecessors.clone(), Some(0));
assert_eq!(
pool.run(&schedule, &runner),
Err(LaneTaskFailure { task: 0, code: 7 })
);
// Dependents of the failed task never ran.
assert!(!runner.done[1].load(Ordering::Acquire));
assert!(!runner.done[3].load(Ordering::Acquire));
// The pool remains usable after a failure.
let runner = recorder(predecessors, None);
pool.run(&schedule, &runner).unwrap();
assert_eq!(runner.calls.load(Ordering::Relaxed), 4);
for idle_spin in [Duration::ZERO, LanePool::DEFAULT_IDLE_SPIN] {
let mut pool = LanePool::with_idle_spin(3, idle_spin).unwrap();
// Exercise both parked and spinning workers across failure/recovery
// epochs: a dependent can observe progress just as abort is set.
for _ in 0..2000 {
let runner = recorder(predecessors.clone(), Some(0));
assert_eq!(
pool.run(&schedule, &runner),
Err(LaneTaskFailure { task: 0, code: 7 })
);
// Dependents of the failed task never ran.
assert!(!runner.done[1].load(Ordering::Acquire));
assert!(!runner.done[3].load(Ordering::Acquire));
// The pool remains usable after a failure.
let runner = recorder(predecessors.clone(), None);
pool.run(&schedule, &runner).unwrap();
assert_eq!(runner.calls.load(Ordering::Relaxed), 4);
}
}
}

#[test]
Expand Down
46 changes: 46 additions & 0 deletions crates/celox-test-suite/src/sv/cases/hierarchy.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,49 @@
(top Top)
(assert_eq added 256)
(assert_eq negated 65535))

(case bits_query_parameter_overrides
; IEEE 1800-2023 20.6.2: fixed-size type and variable queries are constants.
(source "bits_parameter_overrides.sv" #"
module Sub #(parameter int W = 1)(output int y); assign y = W; endmodule
module Top(output int type_bits, variable_bits, combined_bits);
typedef logic [3:0] nibble_t;
logic [11:0] value;
Sub #(.W($bits(nibble_t))) type_instance(.y(type_bits));
Sub #($bits(value)) variable_instance(.y(variable_bits));
Sub #(.W($bits(nibble_t) + $bits(value))) combined_instance(.y(combined_bits));
endmodule
"#)
(top Top)
(eval)
(assert_eq type_bits 4)
(assert_eq variable_bits 12)
(assert_eq combined_bits 16))

(case bits_query_parameter_overrides_follow_caller_specialization
(source "specialized_bits_parameter_overrides.sv" #"
package Types; typedef logic [8:0] word_t; endpackage
module Sub #(parameter int W = 1)(output int y); assign y = W; endmodule
module Caller #(parameter int N = 2)(output int variable_bits, type_bits, array_bits);
import Types::*;
logic [N-1:0] value;
logic [N-1:0] memory [3];
typedef logic [N:0] local_t;
Sub #(.W($bits(value))) variable_instance(.y(variable_bits));
Sub #(.W($bits(local_t) + $bits(word_t))) type_instance(.y(type_bits));
Sub #(.W($bits(memory))) array_instance(.y(array_bits));
endmodule
module Top(output int default_var, default_type, default_array,
output int override_var, override_type, override_array);
Caller default_instance(default_var, default_type, default_array);
Caller #(.N(5)) override_instance(override_var, override_type, override_array);
endmodule
"#)
(top Top)
(eval)
(assert_eq default_var 2)
(assert_eq default_type 12)
(assert_eq default_array 6)
(assert_eq override_var 5)
(assert_eq override_type 15)
(assert_eq override_array 15))
8 changes: 8 additions & 0 deletions crates/celox/tests/frontends/systemverilog/hierarchy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use super::*;

sv_backends! {
fn bits_query_parameter_overrides_follow_caller_specialization(sim) {
@case "hierarchy::bits_query_parameter_overrides_follow_caller_specialization";
}

fn bits_query_parameter_overrides(sim) {
@case "hierarchy::bits_query_parameter_overrides";
}

fn parameter_patterns_keep_original_declarations_and_isolated_bindings(sim) { @case "hierarchy::parameter_patterns_keep_original_declarations_and_isolated_bindings"; }
fn parameter_patterns_preserve_enclosing_expressions(sim) { @case "hierarchy::parameter_patterns_preserve_enclosing_expressions"; }
fn widens_small_parameters_preserving_four_state_bits(sim) {
Expand Down
7 changes: 7 additions & 0 deletions docs/benchmarks/heliodor.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ host vCPU (`HELIODOR_CELOX_THREADS`, default `nproc`). Its own job keeps the
comparison groups' time budgets unchanged. The dashboard shows it as
"multi-threaded" next to single-threaded native execution.

`celox-tiered` also uses `HELIODOR_CELOX_THREADS` on both AArch64 and x86-64.
It starts on the interpreter and adopts native kernels with parallel execution
enabled once compilation finishes. The scheduler can keep sequential kernels
when parallel execution is not worthwhile. Set `HELIODOR_CELOX_THREADS=1` for
the previous single-threaded tiered configuration. Earlier tiered measurements
used one simulation thread; account for this when comparing historical timings.

Recent complete eight-hart runs total 10–13 hours on x86-64 and 17–18 hours on
AArch64. AArch64 four-hart runs total 5–7 hours, so splitting them into equivalent
execution modes preserves useful same-CPU comparisons with time for builds.
Expand Down
6 changes: 6 additions & 0 deletions docs/ja/benchmarks/heliodor.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ Linux バージョンはシミュレーション内で起動するゲストの
別ジョブにすることで、比較グループの実行時間の上限は変わりません。ダッシュボードでは
シングルスレッドの native 実行と並べて「multi-threaded」として表示します。

`celox-tiered` も AArch64・x86-64 の両方で `HELIODOR_CELOX_THREADS` を使います。
インタープリターで実行を始め、コンパイル完了後に並列実行を有効にした native カーネルへ移行します。
並列化の効果が小さい処理には、スケジューラーが逐次カーネルを選ぶことがあります。
従来のシングルスレッド設定で測定する場合は `HELIODOR_CELOX_THREADS=1` を指定してください。
過去の tiered 計測はシミュレーションを1スレッドで実行していたため、履歴との比較ではこの違いに注意してください。

直近の完走結果では、8 hart の合計は x86-64 で 10〜13 時間、AArch64 で 17〜18 時間です。
AArch64 の 4 hart も合計 5〜7 時間なので、同じ実行方式のペアに分け、ビルド時間を確保しつつ
Celox と Veryl-CC を同じ CPU で比較します。別グループ間では同じ CPU を保証しません。
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview",
"test": "vitest run",
"typecheck": "node test/generate-sidecars.mjs && tsc -p .",
"test:vite-components": "vitest run test/vite-plugin-cache.test.ts test/generated-dts.test.ts test/vite-assertion-bytes.test.ts test/vite-plugin-cache-real.test.ts test/vite-plugin-watch.test.ts test/sidecar-orphans.test.ts test/sidecar-lock.test.ts && vitest run --config test/fixtures/injected-components/vitest.config.ts && node test/fixtures/injected-components/dependency-e2e.mjs && node test/fixtures/source-watch/watch-e2e.mjs && node test/fixtures/source-watch/build-watch-e2e.mjs && node test/fixtures/source-watch/component-watch-e2e.mjs",
"test:vite-components": "vitest run test/vite-plugin-cache.test.ts test/generated-dts.test.ts test/vite-assertion-bytes.test.ts test/vite-plugin-cache-real.test.ts test/vite-plugin-watch.test.ts test/sidecar-orphans.test.ts test/sidecar-lock.test.ts && node test/fixtures/injected-components/cache-e2e.mjs && node test/fixtures/injected-components/dependency-e2e.mjs && node test/fixtures/source-watch/watch-e2e.mjs && node test/fixtures/source-watch/build-watch-e2e.mjs && node test/fixtures/source-watch/component-watch-e2e.mjs",
"test:lsp-components": "pnpm run test:vite-components && node test/fixtures/injected-components/lsp-e2e.mjs",
"test:e2e": "pnpm run build && playwright test",
"test:watch": "vitest",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const vitest = join(
dirname(fileURLToPath(import.meta.resolve("vitest/package.json"))),
"vitest.mjs",
);
for (const layout of ["internal", "external"]) {
const cache = mkdtempSync(join(tmpdir(), "celox-vitest-cache-"));
const client =
layout === "external"
? mkdtempSync(join(import.meta.dirname, ".cache-client-"))
: undefined;
try {
for (const phase of ["cold", "warm"]) {
const result = spawnSync(
process.execPath,
[
vitest,
"run",
"--config",
join(import.meta.dirname, "vitest.config.ts"),
"--fsModuleCachePath",
cache,
],
{
cwd: import.meta.dirname,
env: { ...process.env, CELOX_TEST_EXTERNAL_VITE_ROOT: client ?? "" },
encoding: "utf8",
timeout: 120_000,
},
);
process.stdout.write(result.stdout ?? "");
process.stderr.write(result.stderr ?? "");
assert.ifError(result.error);
assert.equal(
result.status,
0,
`${layout} ${phase} module-cache run failed`,
);
}
} finally {
rmSync(cache, { recursive: true, force: true });
if (client) rmSync(client, { recursive: true, force: true });
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import celox from "@celox-sim/vite-plugin";
import { resolve } from "node:path";
import type { Plugin } from "vite";
import celox from "@celox-sim/vite-plugin";
import { normalizePath, type Plugin } from "vite";
import { defineConfig } from "vitest/config";

const virtualTbStep: Plugin = {
Expand All @@ -14,7 +14,7 @@ const virtualTbStep: Plugin = {
};

export default defineConfig({
root: import.meta.dirname,
root: process.env.CELOX_TEST_EXTERNAL_VITE_ROOT || import.meta.dirname,
resolve: {
alias: {
"@fixture/tb-helper": resolve(
Expand All @@ -26,8 +26,11 @@ export default defineConfig({
plugins: [
virtualTbStep,
celox({
projectRoot: import.meta.dirname,
testbenchComponents: "./tb-components.ts",
}),
],
test: { include: ["entry.test.ts"] },
test: {
include: [normalizePath(resolve(import.meta.dirname, "entry.test.ts"))],
},
});
148 changes: 147 additions & 1 deletion packages/playground/test/vite-plugin-watch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { EventEmitter } from "node:events";
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
import {
mkdirSync,
mkdtempSync,
rmSync,
utimesSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { normalizePath } from "vite";
Expand Down Expand Up @@ -1045,3 +1051,143 @@ test.each([true, false])(
expect(watcher.add).not.toHaveBeenCalled();
},
);

// Vitest's persistent module cache replays imports as URLs rooted at Vite's
// root, rather than their original paths relative to the importer.
test("cached root-relative imports retain their generated module identity", async () => {
const root = mkdtempSync(join(tmpdir(), "celox-cached-import-"));
roots.push(root);
mkdirSync(join(root, "src"));
writeFileSync(join(root, "src", "Main.veryl"), "module Main {}\n");
writeFileSync(join(root, "Veryl.toml"), "[project]\nname = 'test'\n");
const { plugin, context } = await initialize(root);
for (const [url, file] of [
["/src/Main.veryl", join(root, "src", "Main.veryl")],
[
"/src/Main.veryl?dse=preserveAllPorts",
`${join(root, "src", "Main.veryl")}?dse=preserveAllPorts`,
],
["/Veryl.toml?celox-project", `${join(root, "Veryl.toml")}?celox-project`],
[
"/src/Main.veryl?celox-watch",
`${join(root, "src", "Main.veryl")}?celox-watch`,
],
]) {
const id = (plugin.resolveId as Function)(url, join(root, "index.html"));
expect(id).toBe(normalizePath(file!));
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}
expect((plugin.resolveId as Function)("/missing.veryl")).toBeUndefined();
});

// A project outside Vite's root is replayed through the /@fs/ URL namespace.
test("cached external project imports retain their generated module identity", async () => {
const root = mkdtempSync(join(tmpdir(), "celox-external-cache-"));
const client = mkdtempSync(join(tmpdir(), "celox-external-client-"));
roots.push(root, client);
writeFileSync(join(root, "Main.veryl"), "module Main {}\n");
writeFileSync(join(root, "Veryl.toml"), "[project]\nname = 'test'\n");
const plugin = celox({ projectRoot: root });
const context = { addWatchFile: vi.fn(), warn: vi.fn() };
await (plugin.configResolved as Function)({ root: client });
await (plugin.buildStart as Function).call(context);
for (const query of ["", "?dse=preserveAllPorts", "?celox-watch"]) {
const file = normalizePath(join(root, "Main.veryl")) + query;
const id = (plugin.resolveId as Function)(
`/@fs/${file.replace(/^\//, "")}`,
join(client, "index.html"),
);
expect(id).toBe(file);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}
const project = `${normalizePath(join(root, "Veryl.toml"))}?celox-project`;
const id = (plugin.resolveId as Function)(
`/@fs/${project.replace(/^\//, "")}`,
);
expect(id).toBe(project);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
});

// Both the host-absolute and Vite-root-relative paths exist. Their existence
// alone must not let an unrelated host file take over a cached project URL.
test("cached URLs prefer the project over colliding host paths", async () => {
const client = mkdtempSync(join(tmpdir(), "celox-collision-client-"));
const host = mkdtempSync(join(tmpdir(), "celox-collision-host-"));
roots.push(client, host);
const urlRoot = normalizePath(host).replace(/^[A-Z]:/i, "");
const project = join(client, urlRoot.replace(/^\//, ""));
mkdirSync(project, { recursive: true });
for (const dir of [host, project]) {
writeFileSync(join(dir, "Main.veryl"), "module Main {}\n");
writeFileSync(join(dir, "Veryl.toml"), "[project]\nname = 'test'\n");
}
const plugin = celox({ projectRoot: project });
const context = { addWatchFile: vi.fn(), warn: vi.fn() };
await (plugin.configResolved as Function)({ root: client });
await (plugin.buildStart as Function).call(context);
for (const [name, query] of [
["Main.veryl", ""],
["Main.veryl", "?dse=preserveAllPorts"],
["Main.veryl", "?celox-watch"],
["Veryl.toml", "?celox-project"],
]) {
const file = normalizePath(join(project, name!)) + query;
const url = `${urlRoot}/${name}${query}`;
const id = (plugin.resolveId as Function)(url, join(client, "index.html"));
expect(id).toBe(file);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}

// Canonical absolute project IDs must stay stable even if their root-relative
// lookalikes also exist. Explicit /@fs/ URLs retain their absolute meaning.
const mirror = join(
client,
normalizePath(project)
.replace(/^[A-Z]:/i, "")
.replace(/^\//, ""),
);
mkdirSync(mirror, { recursive: true });
writeFileSync(join(mirror, "Main.veryl"), "module Main {}\n");
writeFileSync(join(mirror, "Veryl.toml"), "[project]\nname = 'other'\n");
for (const name of ["Main.veryl", "Veryl.toml?celox-project"]) {
const file = normalizePath(join(project, name));
expect((plugin.resolveId as Function)(file)).toBe(file);
}
const hostFile = normalizePath(join(host, "Main.veryl"));
expect(
(plugin.resolveId as Function)(`/@fs/${hostFile.replace(/^\//, "")}`),
).toBe(hostFile);
});

test.each([false, true])(
"cached prefix-shaped URLs fall back to the Vite root (filesystem root=%s)",
async (filesystemRoot) => {
const project = mkdtempSync(join(tmpdir(), "celox-prefix-project-"));
roots.push(project);
const client = join(project, "client");
const url = filesystemRoot
? `/celox-prefix-${project.split(/[\\/]/).at(-1)}/Main.veryl`
: normalizePath(join(project, "Main.veryl")).replace(/^[A-Z]:/i, "");
const rooted = join(client, url.replace(/^[A-Z]:/i, "").replace(/^\//, ""));
mkdirSync(dirname(rooted), { recursive: true });
writeFileSync(rooted, "module Main {}\n");
const plugin = celox({ projectRoot: filesystemRoot ? "/" : project });
// Resolution does not need buildStart; do not generate sidecars at '/'.
await (plugin.configResolved as Function)({ root: client });
for (const query of ["", "?dse=preserveAllPorts", "?celox-watch"]) {
expect((plugin.resolveId as Function)(url + query)).toBe(
normalizePath(rooted) + query,
);
}
expect(
(plugin.resolveId as Function)(`/@fs/${url.replace(/^\//, "")}`),
).toBeUndefined();
if (!filesystemRoot) {
// Once the canonical project file exists, keep that identity even though
// the cached-root lookalike exists too.
writeFileSync(join(project, "Main.veryl"), "module Main {}\n");
const canonical = normalizePath(join(project, "Main.veryl"));
expect((plugin.resolveId as Function)(canonical)).toBe(canonical);
}
},
);
Loading
Loading