Skip to content

runtime: remember source modules that failed to compile - #1525

Open
pvelesko wants to merge 5 commits into
mainfrom
2026-08-29-github-1507-remember-failed-modules
Open

runtime: remember source modules that failed to compile#1525
pvelesko wants to merge 5 commits into
mainfrom
2026-08-29-github-1507-remember-failed-modules

Conversation

@pvelesko

Copy link
Copy Markdown
Collaborator

When a module's device program failed to build or link, chipstar::Device::getOrCreateModule recorded nothing (only successes go into SrcModToCompiledMod_), so every later API call touching a symbol of that module compiled it again from scratch; found with Kokkos_CoreUnitTest_HIP on Aurora PVC, where each hipMemcpyToSymbol repeated an 11 minute compile that failed, until the test timed out. The first attempt's error is now kept in FailedSrcMods_ next to SrcModToCompiledMod_ and thrown again on every later request for the same source module, and a failed build or link is reported as hipErrorSharedObjectInitFailed in both backends instead of hipErrorInitializationError (OpenCL) and hipErrorTbd (Level Zero). The Level Zero relink fallback no longer routes through the error table, whose missing zeModuleDynamicLink entry turned a link failure into abort(). TestFix1507FailedModuleNotRecompiled drives a launch and hipMemcpyToSymbol at a module with an unresolved extern __device__ function and checks both error codes, the second call's latency, and that the runtime log holds a single module cache lookup (before the fix: two lookups and hipErrorNotInitialized).

Fixes #1507

@pvelesko

Copy link
Copy Markdown
Collaborator Author

/run-aurora-ci

… every use

A source module whose device program fails to build is compiled again by
every later API call touching one of its symbols, and the failure is
reported as hipErrorNotInitialized (OpenCL) or hipErrorTbd (Level Zero).
The test drives a launch and hipMemcpyToSymbol at a module with an
unresolved extern __device__ function and expects
hipErrorSharedObjectInitFailed from both, a prompt second return, and a
single module-cache lookup in the runtime log.

Fails today with two lookups and hipErrorNotInitialized.
chipstar::Device::getOrCreateModule only recorded a source module on a
successful compile, so a module whose device program failed to build or
link was compiled again from scratch by every later API call touching
one of its symbols. With Kokkos_CoreUnitTest_HIP on Aurora PVC that was
an 11 minute compile-and-fail cycle per hipMemcpyToSymbol until the test
timed out.

Keep the CHIPError thrown by the first attempt in FailedSrcMods_ next to
SrcModToCompiledMod_ and throw it again on every later request for the
same source module. Report a failed program build or link as
hipErrorSharedObjectInitFailed in both backends instead of
hipErrorInitializationError (OpenCL) and hipErrorTbd (Level Zero). The
Level Zero relink fallback no longer goes through the error table, whose
missing zeModuleDynamicLink entry turned a link failure into abort(),
and zeModuleCreate's ZE_RESULT_ERROR_MODULE_LINK_FAILURE gets a mapping.

Fixes #1507
…Recompiled

The test required hipErrorSharedObjectInitFailed from both calls, which is
what OpenCL reports when clLinkProgram rejects the unresolved symbol. Level
Zero builds the module inside zeModuleCreate and fails it there with
ZE_RESULT_ERROR_MODULE_BUILD_FAILURE, which the runtime reports as
hipErrorInvalidImage, so on Aurora PVC the test failed although the runtime
fix worked:

  first call: hipErrorInvalidImage in 20.2 ms
  second call: hipErrorInvalidImage in 0.0 ms
  compile attempts logged: 1
  FAILED: first call returned hipErrorInvalidImage, expected hipErrorSharedObjectInitFailed
  FAILED: second call returned hipErrorInvalidImage, expected hipErrorSharedObjectInitFailed

Accept either code for the first call and require the second call to return
the same code, keeping the single compile attempt and prompt second call
assertions that are the point of the test.
…edModuleNotRecompiled

The error a broken module surfaces as depends on where the device compiler
gives up. Intel OpenCL fails clBuildProgram (hipErrorSharedObjectInitFailed),
Level Zero fails zeModuleCreate (hipErrorInvalidImage), and Mali builds the
program with an empty log, silently dropping the kernel that calls the
unresolved function, so the runtime only notices when it binds the source
module's kernels to the program and reports hipErrorLaunchFailure from
Module::getKernelByName. Both "run on Mali" lanes failed the test on that
code alone; the property under test held: one compile attempt, second call
back in 0.1 ms with the same error.

Require the first call to fail with anything but hipSuccess and keep the
checks that carry the fix: the second call returns the first call's error,
promptly, and exactly one compile attempt is logged.
…FailedModuleNotRecompiled

A device compiler that accepts the broken module (Mali does) stores a binary
in the test's private cache directory, so rmdir() fails and every run leaks
a /tmp/TestFix1507-cache.XXXXXX directory on the runner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Level Zero: a module whose link fails is recompiled from scratch on every later API call instead of being remembered as failed

1 participant