Skip to content

fix blis dynamic lib name, avoid bli_init output at runtime#689

Open
bung87 wants to merge 1 commit intomratsim:masterfrom
bung87:master
Open

fix blis dynamic lib name, avoid bli_init output at runtime#689
bung87 wants to merge 1 commit intomratsim:masterfrom
bung87:master

Conversation

@bung87
Copy link
Copy Markdown
Contributor

@bung87 bung87 commented Feb 8, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved cross-platform compatibility for BLIS library loading on Windows, macOS, and Linux.
    • Removed verbose initialization status message from startup output.
  • Improvements

    • Added ability to check BLIS initialization status during runtime.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @bung87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the integration of the BLIS backend by addressing two key areas: suppressing verbose initialization output and improving the robustness of dynamic library loading. These changes enhance the user experience by reducing console clutter and bolster cross-platform compatibility for the BLIS library.

Highlights

  • Suppress BLIS initialization output: The explicit echo statement for bli_init()'s return value has been replaced with discard, preventing unnecessary console output during runtime.
  • Enhance dynamic library naming for BLIS: Introduced platform-specific prefixes (e.g., "lib" for Linux/macOS) and expanded suffix handling to include .dylib for macOS, ensuring correct dynamic library loading across different operating systems.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/arraymancer/tensor/backend/blis.nim
    • The bli_init() function call no longer prints its initialization status to the console, using discard instead of echo.
  • src/arraymancer/tensor/backend/blis_api.nim
    • Implemented a blisPrefix constant to correctly prepend "lib" to the library name on non-Windows systems.
    • Extended the blisSuffix logic to specifically handle .dylib for macOS, alongside .dll for Windows and .so for other Unix-like systems.
    • Modified the libblis constant to dynamically construct the library name using the new blisPrefix and blisSuffix for improved platform compatibility.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

This PR refines BLIS backend integration by removing initialization status output while preserving the initialization call, and adding cross-platform dynamic library naming support (Windows, macOS, Linux) with a new bli_is_initialized() binding.

Changes

Cohort / File(s) Summary
BLIS Initialization Behavior
src/arraymancer/tensor/backend/blis.nim
Removed print statement during BLIS initialization; now silently performs bli_init() with result discarded instead of echoing status.
BLIS Platform-Specific Bindings
src/arraymancer/tensor/backend/blis_api.nim
Added OS-specific library naming conventions: blisPrefix ("lib" on Unix-like systems, empty on Windows) and blisSuffix (".so", ".dylib", or ".dll" based on platform). Updated libblis constant to use composed prefix/suffix. Added new bli_is_initialized(): bool procedure binding.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through platform lands,
Where libraries dance in different strands—
Windows, Mac, and Linux too,
Now BLIS knows just what to do!
Silent init, no echo needed,
Cross-platform binding succeeds! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and accurately describes the two main changes: fixing BLIS dynamic library naming across platforms and suppressing the bli_init output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the dynamic library name for BLIS to correctly support different operating systems (Windows, macOS, Linux) and suppresses the output from bli_init during initialization. While the library name fix is good, suppressing the bli_init output by discarding its return value is risky as it hides potential initialization errors. I've added a suggestion to properly handle the return value. I've also suggested a small refactoring to make the platform-specific constants more concise.

static: echo "--USING BLIS--"
include ./blis_api
echo "Blis initialization status: " & $bli_init()
discard bli_init()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

By discarding the return value of bli_init(), you are ignoring potential initialization errors. This could lead to silent failures at runtime if BLIS fails to initialize correctly. It's better to check the return code and raise an exception on failure to ensure the library is properly initialized before use.

let err = bli_init()
doAssert err == BLIS_SUCCESS, "BLIS initialization failed with error: " & $err

Comment on lines +124 to +134
when defined(windows):
const blisPrefix = ""
else:
const blisPrefix = "lib"

when defined(windows):
const blisSuffix = ".dll"
elif defined(macosx):
const blisSuffix = ".dylib"
else:
const blisSuffix = ".so" #MacOS & Linux
const blisSuffix = ".so"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

These two when blocks can be combined into a single, more concise expression using a tuple assignment. This improves readability and reduces code duplication.

const (blisPrefix, blisSuffix) = when defined(windows):
  ("", ".dll")
elif defined(macosx):
  ("lib", ".dylib")
else: # Linux and others
  ("lib", ".so")

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/arraymancer/tensor/backend/blis_api.nim (1)

140-140: ⚠️ Potential issue | 🟡 Minor

Remove the unused bli_is_initialized binding or document future use.

The binding is currently unused in the codebase. While the Nim bool return type correctly maps to BLIS's bool_t (which is C99 bool in modern BLIS, post-July 2020), the lack of a minimum BLIS version constraint in the project means older versions with bool_t as an integer type could theoretically be used. If this binding is not needed, remove it; if planned for future use, add a comment explaining the intent.

🧹 Nitpick comments (1)
src/arraymancer/tensor/backend/blis.nim (1)

18-18: Consider checking bli_init() result at least in debug mode.

The init result is now silently discarded. If initialization fails, downstream BLAS calls will fail with no diagnostic. For consistency with the bli_finalize() handling on lines 21-24, consider:

Suggested change
-  discard bli_init()
+  when defined(debug):
+    echo "Blis initialization status: " & $bli_init()
+  else:
+    discard bli_init()

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR fixes two real cross-platform bugs in the BLIS backend: the library filename on Windows (libblis.dllblis.dll) and macOS (.so.dylib), and removes the noisy echo on startup. It also adds a bli_is_initialized C binding. The platform-name fixes are correct and necessary. However, there are a couple of issues to address before merging:

  • bli_is_initialized is not exported (* marker missing). The PR description promises users can check BLIS initialization status at runtime, but without the export marker the proc is inaccessible to any code outside the include chain.
  • Silent discard of bli_init() in all build modes: The existing quit_blis proc already uses a when defined(debug) / else split to log or discard. The new discard bli_init() drops that pattern entirely, meaning a failed BLIS initialization produces no diagnostic even in debug builds.
  • The return type of bli_is_initialized is declared as Nim bool, which matches modern BLIS (C99 bool) but would be an ABI mismatch against older builds that return bool_t (gint_t/int). A compatibility note or version guard would be prudent.

Confidence Score: 3/5

  • Safe to merge for the platform fixes, but the missing export on bli_is_initialized makes the advertised feature unusable and should be resolved first.
  • The library name fixes are correct and are genuine bug fixes. The startup-echo removal is reasonable. However, bli_is_initialized is not exported so the stated feature doesn't work, and bli_init() error handling is now weaker than the existing quit_blis pattern. Neither issue would cause a crash, but one silently breaks the promised API and the other drops useful debug information.
  • src/arraymancer/tensor/backend/blis_api.nim — missing export marker on bli_is_initialized

Important Files Changed

Filename Overview
src/arraymancer/tensor/backend/blis_api.nim Fixes cross-platform library names (Windows prefix, macOS .dylib), adds bli_is_initialized binding — but the new proc is not exported with * and its return type may mismatch older BLIS ABI versions.
src/arraymancer/tensor/backend/blis.nim Removes noisy startup echo by discarding bli_init() return value unconditionally; silently drops the error even in debug builds, unlike the symmetric quit_blis pattern which logs under defined(debug).

Sequence Diagram

sequenceDiagram
    participant App
    participant blis.nim
    participant blis_api.nim
    participant libblis (dynamic)

    App->>blis.nim: module loaded (when defined(blis))
    blis.nim->>blis_api.nim: include (resolves libblis path per OS)
    Note over blis_api.nim: Windows: blis.dll<br/>macOS: libblis.dylib<br/>Linux: libblis.so
    blis.nim->>libblis (dynamic): bli_init() [return discarded]
    blis.nim->>App: ready
    App-->>libblis (dynamic): bli_gemm / bli_gemv calls
    App->>blis.nim: process exit → quit_blis()
    blis.nim->>libblis (dynamic): bli_finalize() [logged in debug mode]
Loading

Comments Outside Diff (2)

  1. src/arraymancer/tensor/backend/blis_api.nim, line 140 (link)

    bli_is_initialized not exported — unusable externally

    The PR description says this change "Added ability to check BLIS initialization status during runtime," but bli_is_initialized lacks a * export marker, unlike the public API procs bli_gemm and bli_gemv (lines 142–197) which all carry *. Since blis_api.nim is included (not imported) into blis.nim, only symbols explicitly exported with * from blis.nim's scope are accessible to downstream consumers. Without the export marker, no user code can actually call this proc to check initialization status, making the stated improvement a no-op.

  2. src/arraymancer/tensor/backend/blis_api.nim, line 140 (link)

    bli_is_initialized return type may mismatch older BLIS ABI

    In BLIS versions prior to mid-2019 the function was declared as:

    bool_t bli_is_initialized( void );  // bool_t = gint_t (typically int32_t/int64_t)

    Later versions changed it to C99 bool (1 byte). Nim's bool is 1 byte, matching the newer C99 signature. However, if a user links against an older BLIS build where the function returns a 4- or 8-byte integer, the return value will be read incorrectly. It may be worth adding a comment noting the minimum required BLIS version, or using cint with a conversion to guard against this.

Last reviewed commit: e54dd0b

static: echo "--USING BLIS--"
include ./blis_api
echo "Blis initialization status: " & $bli_init()
discard bli_init()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Initialization error silently discarded in all build modes

bli_init() returns a BlisError that can signal BLIS_FAILURE (-2). The existing quit_blis proc correctly logs the result under defined(debug) and only discards in release mode. The new discard bli_init() deviates from this pattern and drops the return value unconditionally — so a failed initialization will produce no warning even in debug builds, leading to confusing downstream errors.

Consider mirroring the same debug/release pattern already used for bli_finalize():

Suggested change
discard bli_init()
when defined(debug):
echo "Blis initialization status: " & $bli_init()
else:
discard bli_init()

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.

1 participant