Bladeren bron

refactor(build)!: rename MBR_* options and variables to BSR_*

BREAKING CHANGE: All CMake options, environment variables, and internal
identifiers have been renamed from `MBR_*` prefix to `BSR_*` for
consistency with the BSRoformer project name.

Renamed CMake options:
- MBR_BUILD_TESTS -> BSR_BUILD_TESTS
- MBR_BUILD_CLI -> BSR_BUILD_CLI

Renamed environment variables:
- MBR_MODEL_PATH -> BSR_MODEL_PATH
- MBR_TEST_DATA_DIR -> BSR_TEST_DATA_DIR
- MBR_FORCE_CPU -> BSR_FORCE_CPU
- MBR_TEST_ATOL -> BSR_TEST_ATOL
- MBR_TEST_RTOL -> BSR_TEST_RTOL

Users must update their build scripts and environment variables.
No compatibility aliases are provided.
沉默の金 4 maanden geleden
bovenliggende
commit
61107f0c55

+ 18 - 19
.github/workflows/build.yml

@@ -223,8 +223,8 @@ jobs:
             -DGGML_VULKAN=${{ matrix.backend == 'vulkan' && 'ON' || 'OFF' }} \
             -DCMAKE_C_COMPILER_LAUNCHER=sccache \
             -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-            -DMBR_BUILD_TESTS=ON \
-            -DMBR_BUILD_CLI=ON
+            -DBSR_BUILD_TESTS=ON \
+            -DBSR_BUILD_CLI=ON
             
       - name: Configure (Windows)
         if: runner.os == 'Windows'
@@ -235,8 +235,8 @@ jobs:
             -DGGML_VULKAN=${{ matrix.backend == 'vulkan' && 'ON' || 'OFF' }} `
             -DCMAKE_C_COMPILER_LAUNCHER=sccache `
             -DCMAKE_CXX_COMPILER_LAUNCHER=sccache `
-            -DMBR_BUILD_TESTS=ON `
-            -DMBR_BUILD_CLI=ON
+            -DBSR_BUILD_TESTS=ON `
+            -DBSR_BUILD_CLI=ON
             
       # ----- Build -----
       - name: Build (Unix)
@@ -251,18 +251,17 @@ jobs:
       - name: Run Unit Tests
         if: matrix.test
         env:
-          MBR_MODEL_PATH: ${{ github.workspace }}/model.gguf
-          MBR_TEST_DATA_DIR: ${{ github.workspace }}/test_data
-          MBR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
+          BSR_MODEL_PATH: ${{ github.workspace }}/model.gguf
+          BSR_TEST_DATA_DIR: ${{ github.workspace }}/test_data
+          BSR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
         run: ctest --test-dir build -C Release -V --output-on-failure --timeout 300
         
       - name: Run Unit Tests (BS Roformer)
         if: matrix.test
         env:
-          MBR_MODEL_PATH: ${{ github.workspace }}/model_bs.gguf
-          MBR_TEST_DATA_DIR: ${{ github.workspace }}/test_data_bs
-          MBR_ARCHITECTURE: bs
-          MBR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
+          BSR_MODEL_PATH: ${{ github.workspace }}/model_bs.gguf
+          BSR_TEST_DATA_DIR: ${{ github.workspace }}/test_data_bs
+          BSR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
         run: ctest --test-dir build -C Release -V --output-on-failure --timeout 300
         
       # ----- CLI Tests -----
@@ -270,8 +269,8 @@ jobs:
         if: matrix.test
         shell: bash
         env:
-          MBR_MODEL_PATH: ${{ github.workspace }}/model.gguf
-          MBR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
+          BSR_MODEL_PATH: ${{ github.workspace }}/model.gguf
+          BSR_FORCE_CPU: ${{ runner.os == 'macOS' && '1' || '' }}
         run: |
           echo "=== CLI Test Suite ==="
           
@@ -331,7 +330,7 @@ jobs:
           # 4. Run full inference
           echo "[4/4] Running inference..."
           # Use absolute paths for input/output to avoid directory issues
-          ABS_MODEL=$(readlink -f "$MBR_MODEL_PATH" || echo "$(pwd)/model.gguf")
+          ABS_MODEL=$(readlink -f "$BSR_MODEL_PATH" || echo "$(pwd)/model.gguf")
           ABS_INPUT=$(readlink -f cli_test_input.wav || echo "$(pwd)/cli_test_input.wav")
           ABS_OUTPUT=$(readlink -f cli_test_output.wav || echo "$(pwd)/cli_test_output.wav")
           
@@ -479,8 +478,8 @@ jobs:
             -DCMAKE_C_COMPILER_LAUNCHER=sccache \
             -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
             -DCMAKE_CUDA_COMPILER_LAUNCHER=sccache \
-            -DMBR_BUILD_TESTS=OFF \
-            -DMBR_BUILD_CLI=ON
+            -DBSR_BUILD_TESTS=OFF \
+            -DBSR_BUILD_CLI=ON
             
       - name: Build
         run: cmake --build build --config Release -j $(nproc)
@@ -600,8 +599,8 @@ jobs:
             "-DCMAKE_CUDA_ARCHITECTURES=$cudaArchs" `
             -DCMAKE_C_COMPILER_LAUNCHER=sccache `
             -DCMAKE_CXX_COMPILER_LAUNCHER=sccache `
-            -DMBR_BUILD_TESTS=OFF `
-            -DMBR_BUILD_CLI=ON
+            -DBSR_BUILD_TESTS=OFF `
+            -DBSR_BUILD_CLI=ON
           cmake --build build --config Release -j $env:NUMBER_OF_PROCESSORS
         
       - name: Upload Artifacts
@@ -641,4 +640,4 @@ jobs:
         with:
           name: BSRoformer-windows-cuda-${{ matrix.cuda_version }}
           path: release\mel-band-roformer\
-          retention-days: 30
+          retention-days: 30

+ 42 - 22
CMakeLists.txt

@@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 #================================================
 
 option(GGML_CUDA "Enable CUDA backend" ON)
-option(MBR_BUILD_TESTS "Build tests" OFF)
-option(MBR_BUILD_CLI "Build CLI application" ON)
+option(BSR_BUILD_TESTS "Build tests" OFF)
+option(BSR_BUILD_CLI "Build CLI application" ON)
 
 #================================================
 # Dependencies - GGML (Flexible Resolution)
@@ -63,13 +63,13 @@ endif()
 # Core Library
 #================================================
 
-set(MBR_SOURCES
+set(BSR_SOURCES
     src/model.cpp
     src/utils.cpp
     src/inference.cpp
 )
 
-add_library(bs_roformer STATIC ${MBR_SOURCES})
+add_library(bs_roformer STATIC ${BSR_SOURCES})
 
 target_include_directories(bs_roformer PUBLIC
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -81,8 +81,6 @@ target_include_directories(bs_roformer PRIVATE
 
 target_link_libraries(bs_roformer PUBLIC ggml)
 if(GGML_CUDA AND TARGET ggml-cuda)
-    target_link_libraries(bs_roformer PUBLIC ggml-cuda)
-    
     # Fix for CI: Link against CUDA stubs if the driver is not present
     # This prevents errors like "libcuda.so.1 needed by ... not found" during linking
     find_package(CUDAToolkit REQUIRED)
@@ -113,30 +111,52 @@ endif()
 # DLL Copy Helper (Windows)
 #================================================
 
-function(mbr_copy_ggml_dlls target_name)
+function(bsr_copy_ggml_runtime_dlls target_name)
     if(NOT WIN32)
         return()
     endif()
-    
-    set(GGML_DLL_TARGETS ggml ggml-base ggml-cpu ggml-cuda ggml-vulkan)
-    
-    foreach(dll_target ${GGML_DLL_TARGETS})
-        if(TARGET ${dll_target})
-            add_custom_command(TARGET ${target_name} POST_BUILD
-                COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                    $<TARGET_FILE:${dll_target}>
-                    $<TARGET_FILE_DIR:${target_name}>
-                COMMENT "Copying ${dll_target}.dll for ${target_name}"
-            )
+
+    if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
+        add_custom_command(TARGET ${target_name} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E copy_if_different
+                $<TARGET_RUNTIME_DLLS:${target_name}>
+                $<TARGET_FILE_DIR:${target_name}>
+            COMMAND_EXPAND_LISTS
+            COMMENT "Copying runtime DLLs for ${target_name}"
+        )
+        return()
+    endif()
+
+    set(ggml_dll_targets ggml ggml-base ggml-cpu ggml-cuda ggml-vulkan)
+    set(runtime_dll_files)
+
+    foreach(dll_target IN LISTS ggml_dll_targets)
+        if(NOT TARGET ${dll_target})
+            continue()
+        endif()
+
+        get_target_property(dll_target_type ${dll_target} TYPE)
+        if(dll_target_type STREQUAL "SHARED_LIBRARY" OR dll_target_type STREQUAL "MODULE_LIBRARY")
+            list(APPEND runtime_dll_files $<TARGET_FILE:${dll_target}>)
         endif()
     endforeach()
+
+    if(runtime_dll_files)
+        add_custom_command(TARGET ${target_name} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E copy_if_different
+                ${runtime_dll_files}
+                $<TARGET_FILE_DIR:${target_name}>
+            COMMAND_EXPAND_LISTS
+            COMMENT "Copying GGML runtime DLLs for ${target_name}"
+        )
+    endif()
 endfunction()
 
 #================================================
 # CLI Application
 #================================================
 
-if(MBR_BUILD_CLI)
+if(BSR_BUILD_CLI)
     # audio.cpp implements AudioFile utilities (using dr_wav)
     add_executable(bs_roformer-cli 
         cli/main.cpp 
@@ -152,17 +172,17 @@ if(MBR_BUILD_CLI)
         target_compile_options(bs_roformer-cli PRIVATE /W3 /utf-8)
     endif()
     
-    mbr_copy_ggml_dlls(bs_roformer-cli)
+    bsr_copy_ggml_runtime_dlls(bs_roformer-cli)
 endif()
 
 #================================================
 # Tests (Optional)
 #================================================
 
-if(MBR_BUILD_TESTS)
+if(BSR_BUILD_TESTS)
     enable_testing()
     add_subdirectory(tests)
     message(STATUS "Tests: ENABLED")
 else()
-    message(STATUS "Tests: DISABLED (use -DMBR_BUILD_TESTS=ON to enable)")
+    message(STATUS "Tests: DISABLED (use -DBSR_BUILD_TESTS=ON to enable)")
 endif()

+ 7 - 5
README.md

@@ -101,7 +101,7 @@ cmake -B build -DGGML_CUDA=ON
 cmake --build build --config Release --parallel
 
 # Enable Tests
-cmake -B build -DGGML_CUDA=ON -DMBR_BUILD_TESTS=ON
+cmake -B build -DGGML_CUDA=ON -DBSR_BUILD_TESTS=ON
 cmake --build build --config Release --parallel
 ```
 
@@ -110,8 +110,10 @@ cmake --build build --config Release --parallel
 | Option | Default | Description |
 |--------|---------|-------------|
 | `GGML_CUDA` | `ON` | Enable CUDA backend |
-| `MBR_BUILD_CLI` | `ON` | Build command line tool |
-| `MBR_BUILD_TESTS` | `OFF` | Build test suite |
+| `BSR_BUILD_CLI` | `ON` | Build command line tool |
+| `BSR_BUILD_TESTS` | `OFF` | Build test suite |
+
+> **Breaking Change:** build/test prefixes were renamed from `MBR_*` to `BSR_*` with no compatibility aliases.
 
 ---
 
@@ -272,8 +274,8 @@ Lightweight audio processing based on [dr_libs](https://github.com/mackron/dr_li
 
 ```bash
 # Set environment variables
-$env:MBR_MODEL_PATH = "models/model.gguf"
-$env:MBR_TEST_DATA_DIR = "test_data"
+$env:BSR_MODEL_PATH = "models/model.gguf"
+$env:BSR_TEST_DATA_DIR = "test_data"
 
 # Run all tests
 ctest --test-dir build -C Release

+ 5 - 5
README.zh.md

@@ -101,7 +101,7 @@ cmake -B build -DGGML_CUDA=ON
 cmake --build build --config Release --parallel
 
 # 启用测试
-cmake -B build -DGGML_CUDA=ON -DMBR_BUILD_TESTS=ON
+cmake -B build -DGGML_CUDA=ON -DBSR_BUILD_TESTS=ON
 cmake --build build --config Release --parallel
 ```
 
@@ -110,8 +110,8 @@ cmake --build build --config Release --parallel
 | 选项 | 默认值 | 说明 |
 |------|--------|------|
 | `GGML_CUDA` | `ON` | 启用 CUDA 后端 |
-| `MBR_BUILD_CLI` | `ON` | 构建命令行工具 |
-| `MBR_BUILD_TESTS` | `OFF` | 构建测试套件 |
+| `BSR_BUILD_CLI` | `ON` | 构建命令行工具 |
+| `BSR_BUILD_TESTS` | `OFF` | 构建测试套件 |
 
 ---
 
@@ -272,8 +272,8 @@ Chunk N+1:              [CPU预处理] → [GPU推理] → [CPU后处理]
 
 ```bash
 # 设置环境变量
-$env:MBR_MODEL_PATH = "models/model.gguf"
-$env:MBR_TEST_DATA_DIR = "test_data"
+$env:BSR_MODEL_PATH = "models/model.gguf"
+$env:BSR_TEST_DATA_DIR = "test_data"
 
 # 运行所有测试
 ctest --test-dir build -C Release

+ 1 - 1
src/model.cpp

@@ -19,7 +19,7 @@ BSRoformer::~BSRoformer() {
 
 void BSRoformer::Initialize(const std::string& model_path) {
     // Use best available backend, but allow forcing CPU
-    if (std::getenv("MBR_FORCE_CPU")) {
+    if (std::getenv("BSR_FORCE_CPU")) {
         backend_ = ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, NULL);
     } else {
         backend_ = ggml_backend_init_best();

+ 11 - 12
tests/CMakeLists.txt

@@ -14,7 +14,7 @@ target_include_directories(test_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 #================================================
 
 # Helper: Add a test with common configuration
-function(mbr_add_test name)
+function(bsr_add_test name)
     if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp")
         return()
     endif()
@@ -24,25 +24,24 @@ function(mbr_add_test name)
     add_test(NAME ${name} COMMAND ${name})
     
     # Copy DLLs on Windows
-    mbr_copy_ggml_dlls(${name})
+    bsr_copy_ggml_runtime_dlls(${name})
 endfunction()
 
 # Core tests (no external data required)
-# Core tests (no external data required)
-# mbr_add_test(test_audio) -> test_audio needs src/audio.cpp
+# bsr_add_test(test_audio) -> test_audio needs src/audio.cpp
 add_executable(test_audio test_audio.cpp ../src/audio.cpp)
 target_link_libraries(test_audio PRIVATE test_common)
 target_include_directories(test_audio PRIVATE ../src ../third_party)
 add_test(NAME test_audio COMMAND test_audio)
-mbr_copy_ggml_dlls(test_audio)
-mbr_add_test(test_component_stft)
+bsr_copy_ggml_runtime_dlls(test_audio)
+bsr_add_test(test_component_stft)
 
 # Component tests (require model + test data)
-mbr_add_test(test_component_bandsplit)
-mbr_add_test(test_component_layers)
-mbr_add_test(test_component_mask)
+bsr_add_test(test_component_bandsplit)
+bsr_add_test(test_component_layers)
+bsr_add_test(test_component_mask)
 
 # Integration tests
-mbr_add_test(test_inference)
-mbr_add_test(test_chunking_logic)
-mbr_add_test(test_stft_consistency)
+bsr_add_test(test_inference)
+bsr_add_test(test_chunking_logic)
+bsr_add_test(test_stft_consistency)

+ 11 - 11
tests/README.md

@@ -20,7 +20,7 @@ This directory contains the test suite for the MelBandRoformer/BSRoformer C++ im
 
 ```powershell
 # Configure with tests enabled
-cmake -B build -DGGML_CUDA=ON -DMBR_BUILD_TESTS=ON
+cmake -B build -DGGML_CUDA=ON -DBSR_BUILD_TESTS=ON
 
 # Build
 cmake --build build --config Release --parallel 14
@@ -54,8 +54,8 @@ Set environment variables and run:
 
 ```powershell
 # Set environment variables
-$env:MBR_MODEL_PATH = "path/to/model.gguf"
-$env:MBR_TEST_DATA_DIR = "path/to/test_data"
+$env:BSR_MODEL_PATH = "path/to/model.gguf"
+$env:BSR_TEST_DATA_DIR = "path/to/test_data"
 
 # Run all tests
 ctest --test-dir build -C Release
@@ -71,10 +71,10 @@ ctest --test-dir build -C Release --output-on-failure
 
 | Variable | Description | Example |
 |----------|-------------|---------|
-| `MBR_MODEL_PATH` | Path to GGUF model file | `models/MelBandRoformer-228M-Vocals-v1-FP16.gguf` |
-| `MBR_TEST_DATA_DIR` | Test data directory (containing `activations/` subdirectory) | `test_data` |
-| `MBR_TEST_ATOL` | Absolute tolerance (optional) | `0.01` |
-| `MBR_TEST_RTOL` | Relative tolerance (optional) | `0.01` |
+| `BSR_MODEL_PATH` | Path to GGUF model file | `models/MelBandRoformer-228M-Vocals-v1-FP16.gguf` |
+| `BSR_TEST_DATA_DIR` | Test data directory (containing `activations/` subdirectory) | `test_data` |
+| `BSR_TEST_ATOL` | Absolute tolerance (optional) | `0.01` |
+| `BSR_TEST_RTOL` | Relative tolerance (optional) | `0.01` |
 
 ## Test Data Structure
 
@@ -107,22 +107,22 @@ test_data/
 2. Use utilities from `test_common.h`
 3. Add to `tests/CMakeLists.txt`:
    ```cmake
-   mbr_add_test(test_xxx)
+   bsr_add_test(test_xxx)
    ```
 
 ## Troubleshooting
 
 ### Test fails: Model file not found
 
-Ensure `MBR_MODEL_PATH` points to a valid `.gguf` file.
+Ensure `BSR_MODEL_PATH` points to a valid `.gguf` file.
 
 ### Test fails: Test data not found
 
-Ensure `MBR_TEST_DATA_DIR` points to a directory containing the `activations/` subdirectory.
+Ensure `BSR_TEST_DATA_DIR` points to a directory containing the `activations/` subdirectory.
 
 ### Numerical mismatch
 
 For quantized models, relax the tolerance:
 ```powershell
-$env:MBR_TEST_ATOL = "0.05"
+$env:BSR_TEST_ATOL = "0.05"
 ```

+ 1 - 1
tests/test_chunking_logic.cpp

@@ -24,7 +24,7 @@ int main(int argc, char* argv[]) {
     
     // We use load_npy directly as they might not be in activations/
     // We use load_npy directly as they are in tests/ directory
-    // Use data_dir (from MBR_TEST_DATA_DIR or default)
+    // Use data_dir (from BSR_TEST_DATA_DIR or default)
     std::string in_path = data_dir + "/chunk_in.npy";
     std::string out_path = data_dir + "/chunk_out.npy";
 

+ 4 - 4
tests/test_common.h

@@ -16,22 +16,22 @@
 // 配置获取
 //======================================================
 inline std::string GetTestDataDir() {
-    const char* env = std::getenv("MBR_TEST_DATA_DIR");
+    const char* env = std::getenv("BSR_TEST_DATA_DIR");
     return env ? env : ".";
 }
 
 inline std::string GetModelPath() {
-    const char* env = std::getenv("MBR_MODEL_PATH");
+    const char* env = std::getenv("BSR_MODEL_PATH");
     return env ? env : "bs_roformer.gguf";
 }
 
 inline float GetToleranceAtol() {
-    const char* env = std::getenv("MBR_TEST_ATOL");
+    const char* env = std::getenv("BSR_TEST_ATOL");
     return env ? std::stof(env) : 1e-3f;
 }
 
 inline float GetToleranceRtol() {
-    const char* env = std::getenv("MBR_TEST_RTOL");
+    const char* env = std::getenv("BSR_TEST_RTOL");
     return env ? std::stof(env) : 1e-2f;
 }
 

+ 2 - 2
tests/test_component_layers.cpp

@@ -18,12 +18,12 @@
  */
 
 std::string GetModelPath() {
-    const char* env = std::getenv("MBR_MODEL_PATH");
+    const char* env = std::getenv("BSR_MODEL_PATH");
     return env ? env : "bs_roformer.gguf";
 }
 
 std::string GetTestDataDir() {
-    const char* env = std::getenv("MBR_TEST_DATA_DIR");
+    const char* env = std::getenv("BSR_TEST_DATA_DIR");
     return env ? env : ".";
 }
 

+ 2 - 2
tests/test_inference.cpp

@@ -14,12 +14,12 @@
  */
 
 std::string GetModelPath() {
-    const char* env = std::getenv("MBR_MODEL_PATH");
+    const char* env = std::getenv("BSR_MODEL_PATH");
     return env ? env : "bs_roformer.gguf";
 }
 
 std::string GetTestDataDir() {
-    const char* env = std::getenv("MBR_TEST_DATA_DIR");
+    const char* env = std::getenv("BSR_TEST_DATA_DIR");
     return env ? env : ".";
 }
 

+ 1 - 1
tests/test_stft_consistency.cpp

@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
         model.Initialize(model_path);
     } catch (const std::exception& e) {
         std::cerr << "Failed to load model: " << e.what() << std::endl;
-        std::cerr << "Ensure MBR_MODEL_PATH is set correctly or bs_roformer.gguf exists." << std::endl;
+        std::cerr << "Ensure BSR_MODEL_PATH is set correctly or bs_roformer.gguf exists." << std::endl;
         return 1;
     }