fix: replace NSLog with CACTUS_LOG for iOS NPU debuggability#328
Conversation
…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]>
There was a problem hiding this comment.
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
NSLogusage innpu_ane.mmwithCACTUS_LOG_ERRORand add additional NPU load/availability diagnostics. - Add
.mlpackagedirectory validation before attempting CoreML compilation. - Improve iOS test harness file-copy error reporting and enable
DEBUGlogging 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); |
There was a problem hiding this comment.
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.
| CACTUS_LOG_ERROR("npu", "ANEEncoder model file not found: " << model_path); | |
| CACTUS_LOG_ERROR("npu", "ANEEncoder model path not found: " << model_path); |
| NSString* path = [NSString stringWithUTF8String:model_path.c_str()]; | ||
|
|
||
| if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { | ||
| CACTUS_LOG_ERROR("npu", "ANEPrefill model file not found: " << model_path); |
There was a problem hiding this comment.
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).
| CACTUS_LOG_ERROR("npu", "ANEPrefill model file not found: " << model_path); | |
| CACTUS_LOG_ERROR("npu", "ANEPrefill model path not found: " << model_path); |
| 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; |
There was a problem hiding this comment.
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.
…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]>
Summary
Closes #321
NSLogcalls innpu_ane.mmwithCACTUS_LOG_ERRORso errors go to stderr (captured incactus_test.logon iOS) instead of the system log (invisible)ANEEncoder::load(),ANEPrefill::load(), andis_npu_available().mlpackagedirectory validation before CoreML compilation attemptsconfigure_xcode.rb) with proper error capture andfprintf(stderr, ...)loggingDEBUGlog level in generated iOS test AppDelegate so NPU diagnostics appear in test outputTest plan
cactus buildcompiles successfully on macOScactus test --ioson physical iPhone — checkcactus_test.logshows NPU diagnostic messages