metalcv 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metalcv-0.1.0/.github/workflows/ci.yml +129 -0
- metalcv-0.1.0/.github/workflows/release.yml +104 -0
- metalcv-0.1.0/.gitignore +36 -0
- metalcv-0.1.0/CMakeLists.txt +234 -0
- metalcv-0.1.0/LICENSE +21 -0
- metalcv-0.1.0/PKG-INFO +256 -0
- metalcv-0.1.0/README.md +197 -0
- metalcv-0.1.0/assets/benchmark-dark.svg +42 -0
- metalcv-0.1.0/assets/benchmark-light.svg +42 -0
- metalcv-0.1.0/assets/logo-dark.svg +11 -0
- metalcv-0.1.0/assets/logo-light.svg +11 -0
- metalcv-0.1.0/assets/logo-mark-dark.svg +5 -0
- metalcv-0.1.0/assets/logo-mark.svg +5 -0
- metalcv-0.1.0/benchmarks/bench_all.py +505 -0
- metalcv-0.1.0/include/metalcv/buffer_pool.hpp +125 -0
- metalcv-0.1.0/include/metalcv/decoder.hpp +99 -0
- metalcv-0.1.0/include/metalcv/metal_processor.hpp +85 -0
- metalcv-0.1.0/include/metalcv/metalcv.hpp +178 -0
- metalcv-0.1.0/include/metalcv/opencv_adapter.hpp +155 -0
- metalcv-0.1.0/include/metalcv/types.hpp +247 -0
- metalcv-0.1.0/pyproject.toml +56 -0
- metalcv-0.1.0/python/metalcv/__init__.py +964 -0
- metalcv-0.1.0/python/metalcv/decord.py +115 -0
- metalcv-0.1.0/python/metalcv/py.typed +0 -0
- metalcv-0.1.0/src/bindings/dlpack_export.mm +775 -0
- metalcv-0.1.0/src/bindings/module.mm +384 -0
- metalcv-0.1.0/src/decoder/bitstream_utils.hpp +815 -0
- metalcv-0.1.0/src/decoder/metalcv_api.mm +204 -0
- metalcv-0.1.0/src/decoder/random_decoder.mm +1667 -0
- metalcv-0.1.0/src/decoder/stream_decoder.mm +2321 -0
- metalcv-0.1.0/src/decoder/vp9_init.mm +541 -0
- metalcv-0.1.0/src/metal/buffer_pool.mm +352 -0
- metalcv-0.1.0/src/metal/metal_processor.mm +1046 -0
- metalcv-0.1.0/src/shaders/fused_preprocess.metal +656 -0
- metalcv-0.1.0/tests/conftest.py +800 -0
- metalcv-0.1.0/tests/test_color_and_quality.py +199 -0
- metalcv-0.1.0/tests/test_cpp_opencv.py +411 -0
- metalcv-0.1.0/tests/test_dlpack_interop.py +353 -0
- metalcv-0.1.0/tests/test_optimization_regressions.py +1081 -0
- metalcv-0.1.0/tests/test_video_capture.py +273 -0
- metalcv-0.1.0/tests/test_video_reader.py +206 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
name: CI (Apple Silicon)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-check:
|
|
12
|
+
name: macOS arm64 / Python ${{ matrix.python-version }}
|
|
13
|
+
runs-on: macos-15
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout repository
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Ensure Metal toolchain is active
|
|
24
|
+
run: |
|
|
25
|
+
if ! xcrun -sdk macosx --find metal >/dev/null 2>&1; then
|
|
26
|
+
XCODE_APP=$(ls -d /Applications/Xcode*.app 2>/dev/null | sort -V | tail -n 1)
|
|
27
|
+
if [ -n "$XCODE_APP" ]; then
|
|
28
|
+
sudo xcode-select -s "$XCODE_APP/Contents/Developer"
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
xcrun -sdk macosx --find metal
|
|
32
|
+
xcrun -sdk macosx --find metallib
|
|
33
|
+
cmake --version
|
|
34
|
+
|
|
35
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
36
|
+
uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: ${{ matrix.python-version }}
|
|
39
|
+
|
|
40
|
+
- name: Build wheel (PEP 517 isolated)
|
|
41
|
+
env:
|
|
42
|
+
MACOSX_DEPLOYMENT_TARGET: "14.0"
|
|
43
|
+
run: |
|
|
44
|
+
python -m pip install --upgrade pip build
|
|
45
|
+
python -m build --wheel --outdir dist
|
|
46
|
+
|
|
47
|
+
- name: Install wheel & verify zero external dynamic dependencies
|
|
48
|
+
run: |
|
|
49
|
+
python -m pip install dist/metalcv-*.whl
|
|
50
|
+
python - <<'PY'
|
|
51
|
+
import os
|
|
52
|
+
import subprocess
|
|
53
|
+
import metalcv
|
|
54
|
+
from metalcv import decord
|
|
55
|
+
|
|
56
|
+
print("metalcv version:", metalcv.__version__)
|
|
57
|
+
print("decord shim:", decord.VideoReader)
|
|
58
|
+
print("codecs:", metalcv.probe_codecs())
|
|
59
|
+
|
|
60
|
+
so_path = metalcv._metalcv.__file__
|
|
61
|
+
print("extension binary:", so_path, f"({os.path.getsize(so_path) / 1024:.1f} KiB)")
|
|
62
|
+
out = subprocess.check_output(["otool", "-L", so_path], text=True)
|
|
63
|
+
print(out)
|
|
64
|
+
for line in out.splitlines()[1:]:
|
|
65
|
+
dep = line.strip().split(" ", 1)[0]
|
|
66
|
+
if dep.startswith("@"):
|
|
67
|
+
continue
|
|
68
|
+
assert dep.startswith("/System/Library/Frameworks/") or dep.startswith("/usr/lib/"), (
|
|
69
|
+
f"Unexpected external dynamic library dependency: {dep}"
|
|
70
|
+
)
|
|
71
|
+
print("Zero external runtime dependency check PASSED.")
|
|
72
|
+
PY
|
|
73
|
+
|
|
74
|
+
- name: Compile standalone pure-C++17 consumer (CMake)
|
|
75
|
+
if: matrix.python-version == '3.13'
|
|
76
|
+
run: |
|
|
77
|
+
mkdir -p /tmp/metalcv_cpp_smoke
|
|
78
|
+
cat <<'EOF' > /tmp/metalcv_cpp_smoke/main.cpp
|
|
79
|
+
#include <metalcv/metalcv.hpp>
|
|
80
|
+
#include <iostream>
|
|
81
|
+
int main() {
|
|
82
|
+
auto codecs = metalcv::probe_codec_support();
|
|
83
|
+
metalcv::PreprocessConfig cfg;
|
|
84
|
+
cfg.width = 224;
|
|
85
|
+
cfg.height = 224;
|
|
86
|
+
cfg.dtype = metalcv::DType::FLOAT16;
|
|
87
|
+
cfg.layout = metalcv::Layout::NCHW;
|
|
88
|
+
std::cout << "h264=" << codecs.h264 << " hevc=" << codecs.hevc
|
|
89
|
+
<< " frame_bytes=" << cfg.frame_bytes(1920, 1080) << "\n";
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
EOF
|
|
93
|
+
cat <<'EOF' > /tmp/metalcv_cpp_smoke/CMakeLists.txt
|
|
94
|
+
cmake_minimum_required(VERSION 3.20)
|
|
95
|
+
project(metalcv_cpp_smoke LANGUAGES CXX)
|
|
96
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
97
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
98
|
+
set(METALCV_BUILD_PYTHON OFF CACHE BOOL "" FORCE)
|
|
99
|
+
add_subdirectory("${GITHUB_WORKSPACE}" metalcv_build)
|
|
100
|
+
add_executable(smoke main.cpp)
|
|
101
|
+
target_link_libraries(smoke PRIVATE metalcv::metalcv)
|
|
102
|
+
target_compile_options(smoke PRIVATE -Wall -Wextra -Werror)
|
|
103
|
+
EOF
|
|
104
|
+
cmake -S /tmp/metalcv_cpp_smoke -B /tmp/metalcv_cpp_smoke/build -DGITHUB_WORKSPACE="$GITHUB_WORKSPACE"
|
|
105
|
+
cmake --build /tmp/metalcv_cpp_smoke/build -j
|
|
106
|
+
/tmp/metalcv_cpp_smoke/build/smoke
|
|
107
|
+
|
|
108
|
+
- name: Run full pytest suite if Metal GPU is available
|
|
109
|
+
if: matrix.python-version == '3.13'
|
|
110
|
+
run: |
|
|
111
|
+
HAS_METAL=$(python -c '
|
|
112
|
+
import ctypes, ctypes.util
|
|
113
|
+
metal = ctypes.CDLL("/System/Library/Frameworks/Metal.framework/Metal")
|
|
114
|
+
metal.MTLCreateSystemDefaultDevice.restype = ctypes.c_void_p
|
|
115
|
+
print("1" if metal.MTLCreateSystemDefaultDevice() else "0")
|
|
116
|
+
')
|
|
117
|
+
if [ "$HAS_METAL" = "1" ]; then
|
|
118
|
+
brew install ffmpeg
|
|
119
|
+
python -m pip install pytest numpy opencv-python av
|
|
120
|
+
pytest -v
|
|
121
|
+
else
|
|
122
|
+
echo "No virtualized Metal GPU device on this runner; skipping GPU runtime pytest."
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
- name: Upload built wheel
|
|
126
|
+
uses: actions/upload-artifact@v4
|
|
127
|
+
with:
|
|
128
|
+
name: metalcv-wheel-py${{ matrix.python-version }}
|
|
129
|
+
path: dist/metalcv-*.whl
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
name: Release to PyPI
|
|
2
|
+
|
|
3
|
+
# Publishes when a GitHub Release is published (e.g. for tag v0.1.0).
|
|
4
|
+
# Run it manually (workflow_dispatch) to build and check the wheels without uploading.
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
wheels:
|
|
13
|
+
name: Wheel / macOS arm64 / Python ${{ matrix.python-version }}
|
|
14
|
+
runs-on: macos-15
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: true
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Ensure Metal toolchain is active
|
|
24
|
+
run: |
|
|
25
|
+
if ! xcrun -sdk macosx --find metal >/dev/null 2>&1; then
|
|
26
|
+
XCODE_APP=$(ls -d /Applications/Xcode*.app 2>/dev/null | sort -V | tail -n 1)
|
|
27
|
+
if [ -n "$XCODE_APP" ]; then
|
|
28
|
+
sudo xcode-select -s "$XCODE_APP/Contents/Developer"
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
xcrun -sdk macosx --find metal
|
|
32
|
+
xcrun -sdk macosx --find metallib
|
|
33
|
+
|
|
34
|
+
- uses: actions/setup-python@v5
|
|
35
|
+
with:
|
|
36
|
+
python-version: ${{ matrix.python-version }}
|
|
37
|
+
|
|
38
|
+
- name: Build wheel
|
|
39
|
+
env:
|
|
40
|
+
MACOSX_DEPLOYMENT_TARGET: "14.0"
|
|
41
|
+
run: |
|
|
42
|
+
python -m pip install --upgrade pip build
|
|
43
|
+
python -m build --wheel --outdir dist
|
|
44
|
+
|
|
45
|
+
- name: Smoke test the built wheel
|
|
46
|
+
run: |
|
|
47
|
+
python -m pip install dist/metalcv-*.whl
|
|
48
|
+
cd /tmp && python -c "import metalcv; print(metalcv.__version__, metalcv.probe_codecs())"
|
|
49
|
+
|
|
50
|
+
- uses: actions/upload-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist-wheel-py${{ matrix.python-version }}
|
|
53
|
+
path: dist/metalcv-*.whl
|
|
54
|
+
|
|
55
|
+
sdist:
|
|
56
|
+
name: Source distribution
|
|
57
|
+
runs-on: macos-15
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v4
|
|
60
|
+
- uses: actions/setup-python@v5
|
|
61
|
+
with:
|
|
62
|
+
python-version: "3.13"
|
|
63
|
+
- name: Build sdist
|
|
64
|
+
run: |
|
|
65
|
+
python -m pip install --upgrade pip build
|
|
66
|
+
python -m build --sdist --outdir dist
|
|
67
|
+
- uses: actions/upload-artifact@v4
|
|
68
|
+
with:
|
|
69
|
+
name: dist-sdist
|
|
70
|
+
path: dist/metalcv-*.tar.gz
|
|
71
|
+
|
|
72
|
+
check:
|
|
73
|
+
name: Check distributions
|
|
74
|
+
needs: [wheels, sdist]
|
|
75
|
+
runs-on: ubuntu-latest
|
|
76
|
+
steps:
|
|
77
|
+
- uses: actions/download-artifact@v4
|
|
78
|
+
with:
|
|
79
|
+
pattern: dist-*
|
|
80
|
+
path: dist
|
|
81
|
+
merge-multiple: true
|
|
82
|
+
- name: twine check
|
|
83
|
+
run: |
|
|
84
|
+
python -m pip install --upgrade twine
|
|
85
|
+
ls -l dist
|
|
86
|
+
twine check --strict dist/*
|
|
87
|
+
|
|
88
|
+
publish:
|
|
89
|
+
name: Publish to PyPI
|
|
90
|
+
if: github.event_name == 'release'
|
|
91
|
+
needs: [check]
|
|
92
|
+
runs-on: ubuntu-latest
|
|
93
|
+
environment:
|
|
94
|
+
name: pypi
|
|
95
|
+
url: https://pypi.org/p/metalcv
|
|
96
|
+
permissions:
|
|
97
|
+
id-token: write # PyPI Trusted Publishing (no API token stored in the repo)
|
|
98
|
+
steps:
|
|
99
|
+
- uses: actions/download-artifact@v4
|
|
100
|
+
with:
|
|
101
|
+
pattern: dist-*
|
|
102
|
+
path: dist
|
|
103
|
+
merge-multiple: true
|
|
104
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
metalcv-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Build artifacts
|
|
2
|
+
build/
|
|
3
|
+
dist/
|
|
4
|
+
*.egg-info/
|
|
5
|
+
_skbuild/
|
|
6
|
+
*.so
|
|
7
|
+
*.dylib
|
|
8
|
+
*.a
|
|
9
|
+
*.o
|
|
10
|
+
*.air
|
|
11
|
+
*.metallib
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
|
|
17
|
+
# Python caches
|
|
18
|
+
__pycache__/
|
|
19
|
+
*.py[cod]
|
|
20
|
+
*$py.class
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.mypy_cache/
|
|
23
|
+
.ruff_cache/
|
|
24
|
+
|
|
25
|
+
# Generated test assets
|
|
26
|
+
tests/assets/
|
|
27
|
+
*.mp4
|
|
28
|
+
*.mov
|
|
29
|
+
*.mkv
|
|
30
|
+
*.webm
|
|
31
|
+
|
|
32
|
+
# macOS / IDEs
|
|
33
|
+
.DS_Store
|
|
34
|
+
.vscode/
|
|
35
|
+
.idea/
|
|
36
|
+
compile_commands.json
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
|
|
3
|
+
project(metalcv VERSION 0.1.0 LANGUAGES CXX OBJCXX)
|
|
4
|
+
|
|
5
|
+
if(NOT APPLE)
|
|
6
|
+
message(FATAL_ERROR "metalcv requires macOS on Apple Silicon (Metal + VideoToolbox).")
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
10
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
11
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
12
|
+
|
|
13
|
+
set(CMAKE_OBJCXX_STANDARD 17)
|
|
14
|
+
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
|
|
15
|
+
set(CMAKE_OBJCXX_EXTENSIONS OFF)
|
|
16
|
+
|
|
17
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
18
|
+
|
|
19
|
+
option(METALCV_BUILD_PYTHON "Build the _metalcv nanobind Python extension" ON)
|
|
20
|
+
option(METALCV_ENABLE_WARNINGS "Enable -Wall -Wextra compiler warnings" ON)
|
|
21
|
+
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
|
+
# Compile Metal shader into .metallib and embed as C++ header byte array
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
25
|
+
find_program(XCRUN_EXECUTABLE xcrun REQUIRED)
|
|
26
|
+
find_program(XXD_EXECUTABLE xxd REQUIRED)
|
|
27
|
+
|
|
28
|
+
set(METAL_SHADER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/fused_preprocess.metal")
|
|
29
|
+
set(METAL_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
|
30
|
+
file(MAKE_DIRECTORY "${METAL_GEN_DIR}")
|
|
31
|
+
|
|
32
|
+
set(METAL_AIR "${METAL_GEN_DIR}/fused_preprocess.air")
|
|
33
|
+
set(METAL_LIB "${METAL_GEN_DIR}/metalcv.metallib")
|
|
34
|
+
set(METAL_HDR "${METAL_GEN_DIR}/metalcv_metallib.h")
|
|
35
|
+
set(EMBED_SCRIPT "${METAL_GEN_DIR}/embed_metallib.cmake")
|
|
36
|
+
|
|
37
|
+
file(WRITE "${EMBED_SCRIPT}" [=[
|
|
38
|
+
file(SIZE "${INPUT}" FILE_SIZE)
|
|
39
|
+
execute_process(
|
|
40
|
+
COMMAND "${XXD}" -i
|
|
41
|
+
INPUT_FILE "${INPUT}"
|
|
42
|
+
OUTPUT_VARIABLE HEX_BYTES
|
|
43
|
+
RESULT_VARIABLE XXD_RES
|
|
44
|
+
)
|
|
45
|
+
if(NOT XXD_RES EQUAL 0)
|
|
46
|
+
message(FATAL_ERROR "xxd failed converting ${INPUT} to C byte array (exit ${XXD_RES})")
|
|
47
|
+
endif()
|
|
48
|
+
file(WRITE "${OUTPUT}"
|
|
49
|
+
"#pragma once\n\n"
|
|
50
|
+
"#include <cstddef>\n"
|
|
51
|
+
"#include <cstdint>\n\n"
|
|
52
|
+
"namespace metalcv {\n"
|
|
53
|
+
"namespace embedded {\n\n"
|
|
54
|
+
"inline constexpr uint8_t kFusedPreprocessMetallib[] = {\n"
|
|
55
|
+
"${HEX_BYTES}\n"
|
|
56
|
+
"};\n\n"
|
|
57
|
+
"inline constexpr size_t kFusedPreprocessMetallibSize = ${FILE_SIZE}u;\n\n"
|
|
58
|
+
"} // namespace embedded\n"
|
|
59
|
+
"} // namespace metalcv\n"
|
|
60
|
+
)
|
|
61
|
+
]=])
|
|
62
|
+
|
|
63
|
+
add_custom_command(
|
|
64
|
+
OUTPUT "${METAL_AIR}"
|
|
65
|
+
COMMAND "${XCRUN_EXECUTABLE}" -sdk macosx metal -O2 -c "${METAL_SHADER_SRC}" -o "${METAL_AIR}"
|
|
66
|
+
DEPENDS "${METAL_SHADER_SRC}"
|
|
67
|
+
COMMENT "Compiling Metal shader fused_preprocess.metal -> fused_preprocess.air"
|
|
68
|
+
VERBATIM
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
add_custom_command(
|
|
72
|
+
OUTPUT "${METAL_LIB}"
|
|
73
|
+
COMMAND "${XCRUN_EXECUTABLE}" -sdk macosx metallib "${METAL_AIR}" -o "${METAL_LIB}"
|
|
74
|
+
DEPENDS "${METAL_AIR}"
|
|
75
|
+
COMMENT "Linking Metal library fused_preprocess.air -> metalcv.metallib"
|
|
76
|
+
VERBATIM
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
add_custom_command(
|
|
80
|
+
OUTPUT "${METAL_HDR}"
|
|
81
|
+
COMMAND "${CMAKE_COMMAND}"
|
|
82
|
+
"-DXXD=${XXD_EXECUTABLE}"
|
|
83
|
+
"-DINPUT=${METAL_LIB}"
|
|
84
|
+
"-DOUTPUT=${METAL_HDR}"
|
|
85
|
+
-P "${EMBED_SCRIPT}"
|
|
86
|
+
DEPENDS "${METAL_LIB}" "${EMBED_SCRIPT}"
|
|
87
|
+
COMMENT "Embedding metalcv.metallib -> generated/metalcv_metallib.h"
|
|
88
|
+
VERBATIM
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
add_custom_target(metalcv_shaders DEPENDS "${METAL_HDR}")
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------------------
|
|
94
|
+
# Core C++ / Obj-C++ static library (metalcv::metalcv)
|
|
95
|
+
# ---------------------------------------------------------------------------
|
|
96
|
+
add_library(metalcv_core STATIC
|
|
97
|
+
src/metal/buffer_pool.mm
|
|
98
|
+
src/metal/metal_processor.mm
|
|
99
|
+
src/decoder/vp9_init.mm
|
|
100
|
+
src/decoder/stream_decoder.mm
|
|
101
|
+
src/decoder/random_decoder.mm
|
|
102
|
+
src/decoder/metalcv_api.mm
|
|
103
|
+
"${METAL_HDR}"
|
|
104
|
+
)
|
|
105
|
+
add_dependencies(metalcv_core metalcv_shaders)
|
|
106
|
+
add_library(metalcv::metalcv ALIAS metalcv_core)
|
|
107
|
+
|
|
108
|
+
target_include_directories(metalcv_core
|
|
109
|
+
PUBLIC
|
|
110
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
111
|
+
$<INSTALL_INTERFACE:include>
|
|
112
|
+
PRIVATE
|
|
113
|
+
"${METAL_GEN_DIR}"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
target_compile_features(metalcv_core PUBLIC cxx_std_17)
|
|
117
|
+
|
|
118
|
+
target_compile_options(metalcv_core
|
|
119
|
+
PRIVATE
|
|
120
|
+
$<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>
|
|
121
|
+
$<$<BOOL:${METALCV_ENABLE_WARNINGS}>:-Wall;-Wextra>
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
target_link_libraries(metalcv_core
|
|
125
|
+
PUBLIC
|
|
126
|
+
"-framework AVFoundation"
|
|
127
|
+
"-framework CoreMedia"
|
|
128
|
+
"-framework CoreVideo"
|
|
129
|
+
"-framework VideoToolbox"
|
|
130
|
+
"-framework Metal"
|
|
131
|
+
"-framework Foundation"
|
|
132
|
+
"-framework CoreFoundation"
|
|
133
|
+
"-framework IOSurface"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
set_target_properties(metalcv_core PROPERTIES
|
|
137
|
+
CXX_STANDARD 17
|
|
138
|
+
CXX_STANDARD_REQUIRED ON
|
|
139
|
+
OBJCXX_STANDARD 17
|
|
140
|
+
OBJCXX_STANDARD_REQUIRED ON
|
|
141
|
+
POSITION_INDEPENDENT_CODE ON
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# ---------------------------------------------------------------------------
|
|
145
|
+
# Python nanobind extension module (_metalcv)
|
|
146
|
+
# ---------------------------------------------------------------------------
|
|
147
|
+
if(METALCV_BUILD_PYTHON)
|
|
148
|
+
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module)
|
|
149
|
+
|
|
150
|
+
execute_process(
|
|
151
|
+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
152
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
153
|
+
OUTPUT_VARIABLE nanobind_ROOT
|
|
154
|
+
RESULT_VARIABLE _nb_cmake_res
|
|
155
|
+
)
|
|
156
|
+
if(NOT _nb_cmake_res EQUAL 0)
|
|
157
|
+
message(FATAL_ERROR "Failed to locate nanobind cmake_dir via ${Python_EXECUTABLE} -m nanobind --cmake_dir")
|
|
158
|
+
endif()
|
|
159
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
160
|
+
|
|
161
|
+
nanobind_add_module(
|
|
162
|
+
_metalcv
|
|
163
|
+
NB_STATIC
|
|
164
|
+
NOMINSIZE
|
|
165
|
+
src/bindings/dlpack_export.mm
|
|
166
|
+
src/bindings/module.mm
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
target_link_libraries(_metalcv PRIVATE metalcv_core)
|
|
170
|
+
|
|
171
|
+
target_compile_options(_metalcv
|
|
172
|
+
PRIVATE
|
|
173
|
+
$<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>
|
|
174
|
+
$<$<BOOL:${METALCV_ENABLE_WARNINGS}>:-Wall;-Wextra>
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
set_target_properties(_metalcv PROPERTIES
|
|
178
|
+
OBJCXX_STANDARD 17
|
|
179
|
+
OBJCXX_STANDARD_REQUIRED ON
|
|
180
|
+
OBJCXX_VISIBILITY_PRESET hidden
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
install(TARGETS _metalcv LIBRARY DESTINATION metalcv)
|
|
184
|
+
endif()
|
|
185
|
+
|
|
186
|
+
# ---------------------------------------------------------------------------
|
|
187
|
+
# Standalone C++ CMake package install / export (skipped during Python wheel builds)
|
|
188
|
+
# ---------------------------------------------------------------------------
|
|
189
|
+
if(NOT SKBUILD)
|
|
190
|
+
include(GNUInstallDirs)
|
|
191
|
+
include(CMakePackageConfigHelpers)
|
|
192
|
+
|
|
193
|
+
install(TARGETS metalcv_core
|
|
194
|
+
EXPORT metalcvTargets
|
|
195
|
+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
196
|
+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
197
|
+
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/metalcv"
|
|
201
|
+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
install(EXPORT metalcvTargets
|
|
205
|
+
FILE metalcvTargets.cmake
|
|
206
|
+
NAMESPACE metalcv::
|
|
207
|
+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/metalcv"
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
set(_cfg_in "${CMAKE_CURRENT_BINARY_DIR}/metalcvConfig.cmake.in")
|
|
211
|
+
file(WRITE "${_cfg_in}"
|
|
212
|
+
"@PACKAGE_INIT@\n"
|
|
213
|
+
"include(\"\${CMAKE_CURRENT_LIST_DIR}/metalcvTargets.cmake\")\n"
|
|
214
|
+
"check_required_components(metalcv)\n"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
configure_package_config_file(
|
|
218
|
+
"${_cfg_in}"
|
|
219
|
+
"${CMAKE_CURRENT_BINARY_DIR}/metalcvConfig.cmake"
|
|
220
|
+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/metalcv"
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
write_basic_package_version_file(
|
|
224
|
+
"${CMAKE_CURRENT_BINARY_DIR}/metalcvConfigVersion.cmake"
|
|
225
|
+
VERSION "${PROJECT_VERSION}"
|
|
226
|
+
COMPATIBILITY SameMajorVersion
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
install(FILES
|
|
230
|
+
"${CMAKE_CURRENT_BINARY_DIR}/metalcvConfig.cmake"
|
|
231
|
+
"${CMAKE_CURRENT_BINARY_DIR}/metalcvConfigVersion.cmake"
|
|
232
|
+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/metalcv"
|
|
233
|
+
)
|
|
234
|
+
endif()
|
metalcv-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ruijia Zhang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|