Skip to content

XUANTIE-RV/shl

Repository files navigation

SHL

SHL is a C and C++ neural-network operator library. This public distribution contains the portable reference backend and its test programs.

Scope

Included:

  • Backend-neutral C API and data types.
  • Portable reference implementations.
  • Unit, performance, bare-metal, smoke, and conformance test sources.
  • CMake package installation and small examples.

Architecture-specific optimized backend implementations are intentionally not part of this distribution. Backend-oriented test sources are retained so an external backend SDK can run the same conformance cases without exposing its implementation.

Requirements

  • CMake 3.21 or newer.
  • A C++17 compiler.
  • GoogleTest for unit tests; CMake can fetch the public upstream project.
  • Google Benchmark for benchmarks; CMake can fetch the public upstream project.
  • LibTorch when unit tests are enabled. Pass its extracted root as LIBTORCH_PATH.
  • For RISC-V execution tests: a riscv64-linux-gnu-* or riscv64-unknown-linux-gnu-* GCC toolchain, qemu-riscv64, and a matching RISC-V LibTorch distribution for the full unit suite.

Build the reference library

cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DSHL_BUILD_TESTS=OFF \
  -DSHL_BUILD_BENCHMARKS=OFF \
  -DSHL_BUILD_EXAMPLES=ON \
  -DSHL_INSTALL=ON
cmake --build build -j

The reference backend is always selected in this distribution. The generated libraries are libshl_ref.so and libshl_ref.a.

Cross-compile and test on RISC-V with QEMU

The full RISC-V suite uses the same portable GoogleTest sources as x86 and a matching RISC-V LibTorch distribution. The public toolchain auto-detects the compiler, sysroot, and qemu-riscv64:

cmake -S . -B build-riscv \
  -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/riscv64-linux-gnu.cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DSHL_BUILD_TESTS=ON \
  -DSHL_BUILD_QEMU_TESTS=OFF \
  -DSHL_BUILD_BENCHMARKS=OFF \
  -DSHL_BUILD_EXAMPLES=OFF \
  -DLIBTORCH_PATH=/path/to/riscv64/libtorch
cmake --build build-riscv --target shl_qemu_unit_tests -j

In this snapshot, CTest discovers the same 1824 named tests on x86 and RISC-V. The aggregate target above runs all tests in one QEMU process to avoid loading LibTorch 1824 times. CTest still exposes every case for filtering and reruns:

ctest --test-dir build-riscv -N -L riscv
ctest --test-dir build-riscv -L riscv -R ReLU --output-on-failure

The Makefile shortcut is:

make test_riscv_qemu RISCV_LIBTORCH_PATH=/path/to/riscv64/libtorch

A lightweight test without LibTorch remains available as make test_riscv_qemu_smoke. For tools outside PATH, set SHL_RISCV_TOOLCHAIN_PREFIX, SHL_QEMU_RISCV64, and SHL_RISCV_SYSROOT.

Run unit tests

cmake -S . -B build-test \
  -DCMAKE_BUILD_TYPE=Release \
  -DSHL_BUILD_TESTS=ON \
  -DSHL_BUILD_BENCHMARKS=OFF \
  -DLIBTORCH_PATH=/path/to/libtorch
cmake --build build-test -j
ctest --test-dir build-test --output-on-failure

See docs/testing.md for the public test tiers and optional conformance sources.

Install and consume

cmake --install build --prefix /tmp/shl-install

A consuming project can use:

find_package(shl REQUIRED)
target_link_libraries(my_target PRIVATE shl::shl)

Source provenance

This branch is a history-free public snapshot derived from an immutable internal release. See OPEN_SOURCE_PROVENANCE.md for the exact source commit and filtering policy.

License

Licensed under the Apache License, Version 2.0. See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors