Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2015f6e
Merge branch 'main' into im-dev
Iainmon Apr 19, 2025
a4b140e
Add resizing function for images in ndarray.
Iainmon Apr 19, 2025
9593115
Add unsqueeze function to ndarray. Working with multiple batched images.
Iainmon Apr 19, 2025
4b2ee64
Add unsqueeze function to ndarray. Working with multiple batched images.
Iainmon Apr 19, 2025
5c46965
Image normalization working for vgg pre processing.
Iainmon Apr 19, 2025
9b45c24
Batched vgg preprocessing working for ndarray loaded images in [0,1].
Iainmon Apr 19, 2025
a60c9db
Video demo starter working well. going to implemented hard conv ops a…
Iainmon Apr 23, 2025
c93a047
Add vid loading.
Iainmon Apr 23, 2025
caa4d0d
Add vid loading working with MPS./VidStreamer nil 0
Iainmon Apr 23, 2025
347944a
Add good code for interactive demo example with video.
Iainmon Apr 23, 2025
6668e67
Add sobel image example. Going to try use CLion.
Iainmon Apr 26, 2025
45457a0
Change CMake system.
Iainmon Apr 26, 2025
0a3c5b8
Working on directory structure.
Iainmon Apr 26, 2025
b8999e5
Add webcam filter code.
Iainmon Apr 26, 2025
00a4cef
Add function stubs. Going to redo file system.
Iainmon Apr 26, 2025
3450b37
Remove folder
Iainmon Apr 26, 2025
dd2a0ea
Add folder to .gitignore.
Iainmon Apr 26, 2025
75d6d41
Make VidStreamer example work again.
Iainmon Apr 29, 2025
6721f4e
Fix model preprocessing script for vgg weights.
Iainmon Apr 30, 2025
064693e
Debug linux building issue. See new readme file in root directory.
Iainmon Apr 30, 2025
0d87ba2
Can compiler TorchTestBridge with Torch cmake module.
Iainmon Apr 30, 2025
c5a31fc
Add Torch cmake module to build config. Works for some tests on Mac.
Iainmon Apr 30, 2025
da83b3c
MyExample working in docker, except for segmentation fault.
Iainmon Apr 30, 2025
fd6ed8c
MyExample works on linux and mac
Iainmon Apr 30, 2025
e7acb44
Update readme for better instructions.
Iainmon Apr 30, 2025
3a90551
Merge branch 'main' into im-dev
Iainmon Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
presentation
libtorch_static
libtorch
target
docs
dependencies
build
cmake-build-debug
.git
learning
.cache
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ libtorch/
build-release/
libtorch_static/
examples/vgg/**/*.pt
segmentation_models.pytorch/
.idea/
cmake-build-debug/
libtorch_old/
142 changes: 72 additions & 70 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.31 FATAL_ERROR)
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# project(MyProject LANGUAGES CXX)

include(CMakePrintHelpers)
Expand All @@ -15,7 +15,7 @@ set(PROJECT_CACHE_DIR "${PROJECT_ROOT_DIR}/.cache")
set(LIBTORCH_DIR "${PROJECT_ROOT_DIR}/libtorch")
# set(LIBTORCH_STATIC_INSTALL_DIR "${PROJECT_ROOT_DIR}/libtorch_static")
set(BRIDGE_DIR "${PROJECT_ROOT_DIR}/bridge")

set(Torch_DIR "${PROJECT_ROOT_DIR}/libtorch")

find_package(chpl REQUIRED HINTS ${PROJECT_ROOT_DIR}/cmake/chapel)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake")
Expand All @@ -38,62 +38,16 @@ download_libtorch(
DESTINATION ${LIBTORCH_DIR}
)

include(FetchContent)
include(ExternalProject)


# if(NOT EXISTS "${LIBTORCH_STATIC_INSTALL_DIR}/lib/libtorch.a")
# ExternalProject_Add(
# pytorch
# GIT_REPOSITORY https://github.com/pytorch/pytorch.git
# GIT_TAG v2.6.0 # Example: specify a particular release
# UPDATE_COMMAND "" # Don’t auto-run 'git pull'
# PATCH_COMMAND "" # No custom patch step

# # DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/pytorch-download" # Where to download the repo

# # We need all PyTorch submodules. By default, ExternalProject won't do submodule init.
# # So we can do that in a separate step if we want a full build. For a minimal CPU build,
# # you might not need them all, but let's be safe:
# STEP_TARGETS clone
# # After 'clone', run "git submodule update --init --recursive"
# # to fetch all submodules.
# # We can use a little trick with COMMAND.
# # PATCH_COMMAND "git submodule update --init --recursive"

# # CMAKE_ARGS
# # -DBUILD_SHARED_LIBS=OFF # Build static libraries
# # -DBUILD_PYTHON=OFF # Don’t build Python bindings
# # -DBUILD_TEST=OFF # Don’t build tests
# # -DUSE_CUDA=OFF # Disable CUDA
# # -DUSE_CUDNN=OFF # Disable cuDNN
# # -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
# # # -DBUILD_BINARY=ON
# # # -DUSE_DISTRIBUTED=ON
# # # -DBUILD_STATIC_RUNTIME_BENCHMARK=ON
# # # -DBUILD_LITE_INTERPRETER=ON
# # # -DUSE_STATIC_MKL=ON
# # # -DSTATIC_DISPATCH_BACKEND=ON
# # # -DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON
# # # -DUSE_DISTRIBUTED=ON
# # # -DCMAKE_BUILD_TYPE=Release
# # -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
# # # -DCMAKE_POLICY_VERSION_MINIMUM=3.5
# CMAKE_ARGS
# -DBUILD_SHARED_LIBS=OFF # Build static libraries
# -DBUILD_PYTHON=OFF # Don’t build Python bindings
# -DBUILD_TEST=OFF # Don’t build tests
# -DUSE_CUDA=OFF # Disable CUDA
# -DUSE_CUDNN=OFF # Disable cuDNN
# -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
# -DCMAKE_BUILD_TYPE=Release
# # -DSTATIC_DISPATCH_BACKEND=ON
# -DCMAKE_INSTALL_PREFIX=${LIBTORCH_STATIC_INSTALL_DIR}
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5

# INSTALL_DIR ${LIBTORCH_STATIC_INSTALL_DIR} # Where to install
# )
# endif()
list(APPEND CMAKE_PREFIX_PATH "${LIBTORCH_DIR}/share/cmake")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23 -lm -ldl ${TORCH_CXX_FLAGS}")


cmake_print_variables(TORCH_LIBRARIES)
cmake_print_variables(TORCH_INCLUDE_DIRS)
cmake_print_variables(TORCH_INSTALL_PREFIX)
cmake_print_variables(TORCH_CXX_FLAGS)
cmake_print_variables(TORCH_LIBRARY)


file(GLOB CHAI_LIB_FILES "${PROJECT_ROOT_DIR}/lib/*.chpl")
Expand Down Expand Up @@ -151,18 +105,32 @@ function(watch)
)
endfunction()



# cmake_print_variables(CHAI_LIB_FILES)

add_library(bridge STATIC ${BRIDGE_DIR}/include/bridge.h ${BRIDGE_DIR}/lib/bridge.cpp)
add_library(bridge OBJECT ${BRIDGE_DIR}/include/bridge.h ${BRIDGE_DIR}/lib/bridge.cpp)

target_link_libraries(
bridge
PRIVATE
${TORCH_LIBRARIES}
# ${LIBTORCH_DIR}/lib/libtorch.so
# ${LIBTORCH_DIR}/lib/libtorch_cpu.so
# ${LIBTORCH_DIR}/lib/libc10.so
# ${LIBTORCH_DIR}/lib/libtorch_global_deps.so
)

target_include_directories(
bridge
PRIVATE
${BRIDGE_DIR}/include
${LIBTORCH_DIR}/include
${LIBTORCH_DIR}/include/torch/csrc/api/include
# ${BRIDGE_DIR}/util
)


set(BRIDGE_OBJECT_FILES $<TARGET_OBJECTS:bridge>)


Expand Down Expand Up @@ -204,13 +172,19 @@ foreach(lib_name IN LISTS LIBTORCH_ALL_LIBS)
list(APPEND LIBTORCH_LIBS_LINKER_ARGS "-l${lib_name_short}")
endforeach()

if(LINUX)
set(LIBTORCH_LINKER_ARGS
"-ltorch"
"-ltorch_cpu"
"-lc10"
)
endif()
cmake_print_variables(LIBTORCH_LIBS_LINKER_ARGS)
# cmake_print_variables(${BRIDGE_OBJECT_FILES})
# cmake_print_variables(BRIDGE_OBJECT_FILES)


set(LIBTORCH_LIBS_LINKER_ARGS
"-ltorch"
# "-ltorch_cpu"
# "-lc10"
# "-ltorch_global_deps"
)
cmake_print_variables(LIBTORCH_LIBS_LINKER_ARGS)


add_executable(TorchBridge ${BRIDGE_DIR}/lib/Bridge.chpl)
add_dependencies(TorchBridge bridge)
Expand All @@ -220,10 +194,10 @@ target_link_options(TorchBridge
${BRIDGE_DIR}/include/bridge.h
${BRIDGE_OBJECT_FILES}
-L ${LIBTORCH_DIR}/lib
# "-ltorch"
# "-ltorch_cpu"
# "-lc10"
# "-ltorch_global_deps"
"-ltorch"
"-ltorch_cpu"
"-lc10"
"-ltorch_global_deps"
${LIBTORCH_LIBS_LINKER_ARGS}
--ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib"
)
Expand Down Expand Up @@ -293,5 +267,33 @@ add_custom_command(

# ./vgg images/frog.jpg

# add_subdirectory(bridge)

add_subdirectory(examples)
add_subdirectory("test")
add_subdirectory(demos)



add_executable(MPSTest
"${PROJECT_ROOT_DIR}/test/tiny/mps.cpp"
)

target_include_directories(MPSTest
PRIVATE
${LIBTORCH_DIR}/include
${LIBTORCH_DIR}/include/torch/csrc/api/include
)

target_link_directories(MPSTest
PRIVATE
${LIBTORCH_DIR}/lib
)

target_link_libraries(MPSTest
PRIVATE
-ltorch
-ltorch_cpu
-lc10
-ltorch_global_deps
)
86 changes: 64 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,79 @@
FROM ubuntu:22.04
# ────────────────────────────────
# 1. Build stage
# ────────────────────────────────
FROM ubuntu:24.04 AS builder


# RUN apt update > /dev/null && apt install -y apt-utils && apt upgrade -y > /dev/null

ENV DEBIAN_FRONTEND=noninteractive

COPY deb /

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update > /dev/null && \
apt upgrade -y > /dev/null && \
apt install -y apt-utils > /dev/null && \
apt install -y python3-pip > /dev/null && \
(apt install -y ./chapel-2.3.0-1.ubuntu22.arm64.deb > /dev/null) || (apt install -y ./chapel-2.3.0-1.ubuntu22.amd64.deb > /dev/null)
# -------- toolchain & helpers
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential g++ cmake ninja-build \
git curl wget ca-certificates unzip \
python3 python3-pip libssl-dev \
apt-utils \
&& ((apt-get install -y --no-install-recommends ./chapel-2.4.0-1.ubuntu24.arm64.deb) || (apt-get install -y --no-install-recommends ./chapel-2.4.0-1.ubuntu24.amd64.deb)) \
&& rm -rf /var/lib/apt/lists/*

# && (apt-get install -y --no-install-recommends ./chapel-2.4.0-1.ubuntu24.arm64.deb) || (apt install -y ./chapel-2.4.0-1.ubuntu24.amd64.deb)

# -------- LibTorch (change CUDA tag for GPU builds)
# ARG TORCH_VERSION=2.2.0 # ← keep in sync with your sources
# ARG TORCH_VARIANT=cpu # cpu | cu118 | cu121 …
# RUN mkdir -p /opt \
# && cd /opt \
# && wget -q --show-progress \
# https://download.pytorch.org/libtorch/${TORCH_VARIANT}/libtorch-cxx11-abi-shared-with-deps-${TORCH_VERSION}%2B${TORCH_VARIANT}.zip \
# && unzip libtorch-cxx11-abi-shared-with-deps-${TORCH_VERSION}+${TORCH_VARIANT}.zip \
# && rm libtorch-cxx11-abi-shared-with-deps-${TORCH_VERSION}+${TORCH_VARIANT}.zip

RUN pip3 install numpy > /dev/null

RUN pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu > /dev/null
RUN mkdir -p /app \
&& cd /app \
&& wget -q --show-progress \
https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip \
&& unzip libtorch-cxx11-abi-shared-with-deps-latest.zip \
&& mkdir -p /app/.cache \
&& mv /app/libtorch-cxx11-abi-shared-with-deps-latest.zip /app/.cache/libtorch_cache.zip


COPY lib /lib
COPY examples /examples
COPY test /test
ENV Torch_DIR=/app/libtorch
ENV CMAKE_PREFIX_PATH=/app/libtorch/libtorch/share/cmake
# lets CMake find TorchConfig.cmake

# Run tests
RUN cd test/correspondence && python3 correspondence.py
RUN cd test/correspondence && python3 correspondence.py --print-compiler-errors

# -------- build your project
WORKDIR /app
COPY . /app

# (uncomment if you have submodules)
# RUN git submodule update --init --recursive

RUN ls

RUN cd /app \
&& mkdir -p build \
&& cd build \
&& cmake -DCMAKE_BUILD_TYPE=Debug .. \
&& make MyExample

# RUN mkdir build \
# && cd build \
# && cmake -DCMAKE_BUILD_TYPE=Debug .. \
# && make TinyLayerTest -j$(nproc)

#RUN cd build && ./TinyLayerTest

# && cmake -DCMAKE_PREFIX_PATH=/opt/libtorch -DCMAKE_BUILD_TYPE=Release .. \

# configure-and-build
# RUN cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Release \
# && cmake --build build --target all -j$(nproc)

# RUN cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Release

# RUN cmake --build build --target all -j$(nproc)

# Build instructions
# force (last resort): docker system prune --all --force
# docker builder prune --all
# docker build --no-cache -t chapel-deb .
# docker build -t chapel-deb .
# docker container run -it chapel-deb bash
37 changes: 37 additions & 0 deletions Dockerfile.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:24.04


# RUN apt update > /dev/null && apt install -y apt-utils && apt upgrade -y > /dev/null


COPY deb /

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update > /dev/null && \
apt upgrade -y > /dev/null && \
apt install -y apt-utils > /dev/null && \
apt install -y python3-pip > /dev/null && \
(apt install -y ./chapel-2.4.0-1.ubuntu25.arm64.deb > /dev/null) || (apt install -y ./chapel-2.4.0-1.ubuntu25.amd64.deb > /dev/null)



RUN pip3 install numpy > /dev/null

RUN pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu > /dev/null


COPY lib /lib
COPY examples /examples
COPY test /test

# Run tests
RUN cd test/correspondence && python3 correspondence.py
RUN cd test/correspondence && python3 correspondence.py --print-compiler-errors


# Build instructions
# force (last resort): docker system prune --all --force
# docker builder prune --all
# docker build --no-cache -t chapel-deb .
# docker build -t chapel-deb .
# docker container run -it chapel-deb bash
Loading
Loading