Skip to content

fix: replace NSLog with CACTUS_LOG for iOS NPU debuggability#328

Merged
HenryNdubuaku merged 1 commit intocactus-compute:mainfrom
KayaanT:fix/ios-npu-diagnostics
Feb 9, 2026
Merged

fix: replace NSLog with CACTUS_LOG for iOS NPU debuggability#328
HenryNdubuaku merged 1 commit intocactus-compute:mainfrom
KayaanT:fix/ios-npu-diagnostics

Conversation

@KayaanT
Copy link
Copy Markdown
Contributor

@KayaanT KayaanT commented Feb 7, 2026

Summary

Closes #321

  • Replace all 9 NSLog calls in npu_ane.mm with CACTUS_LOG_ERROR so errors go to stderr (captured in cactus_test.log on iOS) instead of the system log (invisible)
  • Add load/path diagnostic logging to ANEEncoder::load(), ANEPrefill::load(), and is_npu_available()
  • Add .mlpackage directory validation before CoreML compilation attempts
  • Fix silent file copy failures in iOS test harness (configure_xcode.rb) with proper error capture and fprintf(stderr, ...) logging
  • Enable DEBUG log level in generated iOS test AppDelegate so NPU diagnostics appear in test output

Test plan

  • cactus build compiles successfully on macOS
  • cactus test --ios on physical iPhone — check cactus_test.log shows NPU diagnostic messages

…actus-compute#321)

On physical iOS devices, stdout/stderr is redirected to cactus_test.log
but NSLog goes to the system log, making all CoreML/ANE errors invisible.
This replaces all NSLog calls with CACTUS_LOG_ERROR (which writes to
stderr), adds load/path diagnostics, mlpackage directory validation,
and fixes silent file copy failures in the iOS test harness.

Signed-off-by: Kayaan Tharani <[email protected]>
Copilot AI review requested due to automatic review settings February 7, 2026 23:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves iOS NPU (ANE) debuggability by routing CoreML/ANE errors and diagnostics through the project’s CACTUS_LOG_* logger (stderr), and by strengthening the iOS test harness’ logging/copy diagnostics so failures show up in cactus_test.log.

Changes:

  • Replace NSLog usage in npu_ane.mm with CACTUS_LOG_ERROR and add additional NPU load/availability diagnostics.
  • Add .mlpackage directory validation before attempting CoreML compilation.
  • Improve iOS test harness file-copy error reporting and enable DEBUG logging level for richer NPU diagnostics in test output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/ios/configure_xcode.rb Generates an AppDelegate that captures stderr reliably, logs copy failures, and enables DEBUG logging for test runs.
cactus/npu/npu_ane.mm Switches CoreML/ANE error reporting to CACTUS_LOG_*, adds model path/load diagnostics, and validates .mlpackage directories before compilation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

NSString* path = [NSString stringWithUTF8String:model_path.c_str()];

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
CACTUS_LOG_ERROR("npu", "ANEEncoder model file not found: " << model_path);
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

These messages say "model file not found", but the NPU models can be .mlpackage directories. Consider wording this as "model path not found" (or explicitly handle file vs directory) to avoid misleading diagnostics.

Suggested change
CACTUS_LOG_ERROR("npu", "ANEEncoder model file not found: " << model_path);
CACTUS_LOG_ERROR("npu", "ANEEncoder model path not found: " << model_path);

Copilot uses AI. Check for mistakes.
NSString* path = [NSString stringWithUTF8String:model_path.c_str()];

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
CACTUS_LOG_ERROR("npu", "ANEPrefill model file not found: " << model_path);
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Same as the encoder path check above: this message says "model file not found", but .mlpackage models are directories. Consider changing this to "model path not found" (or reporting whether the path exists but is not the expected type).

Suggested change
CACTUS_LOG_ERROR("npu", "ANEPrefill model file not found: " << model_path);
CACTUS_LOG_ERROR("npu", "ANEPrefill model path not found: " << model_path);

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 65
NSURL* compiledURL = [MLModel compileModelAtURL:modelURL error:&error];
if (error) {
NSLog(@"[CactusANE] Error compiling model: %@", error);
CACTUS_LOG_ERROR("npu", "ANE model compilation failed: " << [[error localizedDescription] UTF8String]);
return self;
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The new CoreML error logs use localizedDescription, which often drops important debugging context (domain/code/userInfo) that NSLog(@"%@", error) used to include. Consider logging error.description (or include error.domain + error.code) so failures are diagnosable from stderr logs, and apply consistently to the other CoreML error logs in this file.

Copilot uses AI. Check for mistakes.
@HenryNdubuaku HenryNdubuaku merged commit cae036e into cactus-compute:main Feb 9, 2026
6 of 8 checks passed
ncylich pushed a commit that referenced this pull request Feb 24, 2026
…321) (#328)

On physical iOS devices, stdout/stderr is redirected to cactus_test.log
but NSLog goes to the system log, making all CoreML/ANE errors invisible.
This replaces all NSLog calls with CACTUS_LOG_ERROR (which writes to
stderr), adds load/path diagnostics, mlpackage directory validation,
and fixes silent file copy failures in the iOS test harness.

Signed-off-by: Kayaan Tharani <[email protected]>
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.

iOS NPU

3 participants