diff --git a/CMakeLists.cmake b/CMakeLists.cmake new file mode 100644 index 000000000..95299c1cd --- /dev/null +++ b/CMakeLists.cmake @@ -0,0 +1,333 @@ +cmake_minimum_required(VERSION 3.20 FATAL_ERROR) +# project(MyProject LANGUAGES CXX) + +include(CMakePrintHelpers) + +# set(CMAKE_VERBOSE_MAKEFILE ON) + +if(UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() + +set(PROJECT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(PROJECT_BINARY_DIR "${CMAKE_BINARY_DIR}") +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") +list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake/chapel") + +project(MyProject LANGUAGES CXX C CHPL) +message(STATUS "Using chpl: ${CMAKE_CHPL_COMPILER}") + + +if(APPLE) + set(CMAKE_C_COMPILER "/usr/bin/clang") + set(CMAKE_CXX_COMPILER "/usr/bin/clang++") +endif() +set(CMAKE_CXX_STANDARD 20) + + +include(LibTorchDL) +download_libtorch( + CACHE_DIR ${PROJECT_CACHE_DIR} + DESTINATION ${LIBTORCH_DIR} +) + +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") + +# file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c "int main(int argc, const char **argv){ return 1; }\n") +# add_executable(ChAI ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c) +# # file(GLOB RESOURCE_FILES *.bmp *.wav moose.dat utf8.txt) +# foreach(RESOURCE_FILE ${CHAI_LIB_FILES}) +# add_custom_command( +# TARGET ChAI +# POST_BUILD +# COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $ +# ) +# endforeach(RESOURCE_FILE) + +# file(COPY ${CHAI_LIB_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + + + + +add_custom_target( + ChAI + ALL + DEPENDS ${PROJECT_SOURCE_DIR}/lib + # SOURCES ${CHAI_LIB_FILES} + # COMMAND ${CMAKE_COMMAND} -E echo "Building ChAI" +) + +foreach(RESOURCE_FILE ${CHAI_LIB_FILES}) + add_custom_command( + TARGET ChAI + POST_BUILD + # OUTPUT $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RESOURCE_FILE} ${PROJECT_BINARY_DIR}/lib + # DEPENDS ${CHAI_LIB_FILES} + ) +endforeach(RESOURCE_FILE) + + + +# foreach(RESOURCE_FILE ${CHAI_LIB_FILES}) +# add_custom_command( +# TARGET ChAI +# POST_BUILD +# COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $ +# ) +# endforeach(RESOURCE_FILE) + + +function(watch) + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS ${ARGV} + ) +endfunction() + + + +# cmake_print_variables(CHAI_LIB_FILES) + +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 +) + + +add_library(bridge_objs STATIC $) +set_target_properties(bridge_objs + PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" +) + + +set(BRIDGE_OBJECT_FILES $) + +# add_custom_command( +# TARGET bridge +# POST_BUILD +# COMMAND ${CMAKE_COMMAND} -E copy_directory +# "${CMAKE_CURRENT_SOURCE_DIR}/style-transfer/models" +# "$/style-transfer/models" +# COMMENT "NOT! Copying ${PROJECT_ROOT_DIR}/examples/vgg/images to $/images" +# ) + + + +file(GLOB LIBTORCH_ALL_LIB_FILES + # "${LIBTORCH_DIR}/lib/*.a" + "${LIBTORCH_DIR}/lib/*.dylib" + "${LIBTORCH_DIR}/lib/*.so") + +set(LIBTORCH_ALL_LIBS "") +foreach(lib_path IN LISTS LIBTORCH_ALL_LIB_FILES) + get_filename_component(lib_name "${lib_path}" NAME_WE) + list(APPEND LIBTORCH_ALL_LIBS "${lib_name}") +endforeach() + + +set(REQUIRED_LIBS + "libtorch" + "libtorch_cpu" + "libc10" +) + +set(DISALLOWED_LIBS + "libtorch_python" +) + +set(LIBTORCH_LIBS_LINKER_ARGS "") # Will hold the list of "-l..." flags. +foreach(lib_name IN LISTS LIBTORCH_ALL_LIBS) + if(lib_name IN_LIST DISALLOWED_LIBS) + if(lib_name IN_LIST REQUIRED_LIBS) + message(FATAL_ERROR "Required lib ${lib_name} is disallowed.") + else() + message(STATUS "Skipping disallowed lib: ${lib_name}") + continue() + endif() + endif() + string(REGEX REPLACE "^lib" "" lib_name_short "${lib_name}") + list(APPEND LIBTORCH_LIBS_LINKER_ARGS "-l${lib_name_short}") +endforeach() + +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) + +set(CHAI_LINKER_ARGS + -M ${PROJECT_ROOT_DIR}/lib + ${BRIDGE_DIR}/include/bridge.h + ${BRIDGE_OBJECT_FILES} + -L ${LIBTORCH_DIR}/lib + ${LIBTORCH_LIBS_LINKER_ARGS} + --ccflags "-I${BRIDGE_DIR}/include -L${PROJECT_ROOT_DIR}/build" + --ldflags "-L${PROJECT_ROOT_DIR}/build -Wl,-rpath,${LIBTORCH_DIR}/lib" +) + + +add_executable(TorchBridge ${PROJECT_ROOT_DIR}/lib/Bridge.chpl) +add_dependencies(TorchBridge bridge) +add_dependencies(TorchBridge ChAI) +add_dependencies(TorchBridge bridge_objs) +target_link_options(TorchBridge + PRIVATE + -M ${PROJECT_ROOT_DIR}/lib + ${BRIDGE_DIR}/include/bridge.h + ${BRIDGE_OBJECT_FILES} + -L ${LIBTORCH_DIR}/lib + "-ltorch" + "-ltorch_cpu" + "-lc10" + "-ltorch_global_deps" + ${LIBTORCH_LIBS_LINKER_ARGS} + --ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib" + ${CHAI_LINKER_ARGS} +) + + + + +add_executable(TinyLayerTest + ${PROJECT_ROOT_DIR}/test/tiny/layer_test.chpl + ${CHAI_LIB_FILES} + ) +add_dependencies(TinyLayerTest bridge) +add_dependencies(TinyLayerTest ChAI) +target_link_options(TinyLayerTest + PRIVATE + --main-module layer_test.chpl + -M ${PROJECT_ROOT_DIR}/lib + ${CHAI_LINKER_ARGS} +) + + +add_executable(TinyBridgeSystemTest + ${PROJECT_ROOT_DIR}/test/tiny/bridge_system_test.chpl + ${CHAI_LIB_FILES} + ) +add_dependencies(TinyBridgeSystemTest bridge) +add_dependencies(TinyBridgeSystemTest ChAI) +add_dependencies(TinyBridgeSystemTest bridge_objs) +add_dependencies(TinyBridgeSystemTest TorchBridge) +target_link_options(TinyBridgeSystemTest + PRIVATE + --main-module bridge_system_test.chpl + -M ${PROJECT_ROOT_DIR}/lib + ${CHAI_LINKER_ARGS} +) + + +# chpl test/tiny/layer_test.chpl -M lib bridge/include/bridge.h build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,libtorch/lib" + +# chpl --fast -o vgg test.chpl -M ../../lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/include/bridge.h /Users/iainmoncrief/Documents/Github/ChAI/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L /Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,/Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib" + +# chpl -o vgg test.chpl $(../../embed_libtorch.sh .) +# chpl --fast -o vgg test.chpl $(../../embed_libtorch.sh .) + + + + + + + + +add_executable(vgg + "${PROJECT_ROOT_DIR}/examples/vgg/test.chpl" + ${PROJECT_ROOT_DIR}/examples/vgg/VGG.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(vgg bridge) +add_dependencies(vgg ChAI) +target_link_options(vgg + PRIVATE + # -M ${PROJECT_ROOT_DIR}/examples/vgg + -svggExampleDir="${PROJECT_ROOT_DIR}/examples/vgg" + ${CHAI_LINKER_ARGS} +) + +add_custom_command( + TARGET vgg + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${PROJECT_ROOT_DIR}/examples/vgg/images" + "$/images" + COMMENT "Copying ${PROJECT_ROOT_DIR}/examples/vgg/images to $/images" +) + +# ./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 +) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 326c21030..d8f32e788 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,12 +210,13 @@ set(CHAI_LINKER_ARGS ) -add_executable(TorchBridge ${BRIDGE_DIR}/lib/Bridge.chpl) +add_executable(TorchBridge ${PROJECT_ROOT_DIR}/lib/Bridge.chpl) add_dependencies(TorchBridge bridge) add_dependencies(TorchBridge ChAI) add_dependencies(TorchBridge bridge_objs) target_link_options(TorchBridge PRIVATE + -M ${PROJECT_ROOT_DIR}/lib ${BRIDGE_DIR}/include/bridge.h ${BRIDGE_OBJECT_FILES} -L ${LIBTORCH_DIR}/lib @@ -225,41 +226,91 @@ target_link_options(TorchBridge "-ltorch_global_deps" ${LIBTORCH_LIBS_LINKER_ARGS} --ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib" + ${CHAI_LINKER_ARGS} ) +function(chai_add_executable TARGET MAIN_CHPL) + # (1) Create the executable with the .chpl file + CHAI libs + add_executable(${TARGET} + ${MAIN_CHPL} + ${CHAI_LIB_FILES} + ) + # (2) Add the standard ChAI/bridge-related dependencies + add_dependencies(${TARGET} + bridge + ChAI + bridge_objs + ) + # (3) Extract just the filename (e.g. "my_test.chpl") for --main-module + get_filename_component(_main_base ${MAIN_CHPL} NAME) -add_executable(TinyLayerTest - ${PROJECT_ROOT_DIR}/test/tiny/layer_test.chpl - ${CHAI_LIB_FILES} - ) -add_dependencies(TinyLayerTest bridge) -add_dependencies(TinyLayerTest ChAI) -target_link_options(TinyLayerTest - PRIVATE - --main-module layer_test.chpl - -M ${PROJECT_ROOT_DIR}/lib + # (4) Build a list of all "-M " flags: + # First, always include ${PROJECT_ROOT_DIR}/lib. + set(_module_dirs "${PROJECT_ROOT_DIR}/lib") + # Then, if the caller passed any extra dirs (ARGN), append them. + if(ARGN) + list(APPEND _module_dirs ${ARGN}) + endif() + + # Now turn each entry in _module_dirs into a "-M " pair. + set(_m_flags "") + foreach(_d IN LISTS _module_dirs) + list(APPEND _m_flags "-M" "${_d}") + endforeach() + + # (5) Finally, attach --main-module, all -M flags, and any CHAI_LINKER_ARGS. + target_link_options(${TARGET} + PRIVATE + --main-module ${_main_base} + ${_m_flags} ${CHAI_LINKER_ARGS} + ) +endfunction() + + +# add_executable(TinyLayerTest +# ${PROJECT_ROOT_DIR}/test/tiny/layer_test.chpl +# ${CHAI_LIB_FILES} +# ) +# add_dependencies(TinyLayerTest bridge) +# add_dependencies(TinyLayerTest ChAI) +# target_link_options(TinyLayerTest +# PRIVATE +# --main-module layer_test.chpl +# -M ${PROJECT_ROOT_DIR}/lib +# ${CHAI_LINKER_ARGS} +# ) + +chai_add_executable(TinyLayerTest + ${PROJECT_ROOT_DIR}/test/tiny/layer_test.chpl + ${PROJECT_ROOT_DIR}/lib ) -add_executable(TinyBridgeSystemTest +# add_executable(TinyBridgeSystemTest +# ${PROJECT_ROOT_DIR}/test/tiny/bridge_system_test.chpl +# ${CHAI_LIB_FILES} +# ) +# add_dependencies(TinyBridgeSystemTest bridge) +# add_dependencies(TinyBridgeSystemTest ChAI) +# add_dependencies(TinyBridgeSystemTest bridge_objs) +# add_dependencies(TinyBridgeSystemTest TorchBridge) +# target_link_options(TinyBridgeSystemTest +# PRIVATE +# --main-module bridge_system_test.chpl +# -M ${PROJECT_ROOT_DIR}/lib +# ${CHAI_LINKER_ARGS} +# ) + +chai_add_executable(TinyBridgeSystemTest ${PROJECT_ROOT_DIR}/test/tiny/bridge_system_test.chpl - ${CHAI_LIB_FILES} - ) -add_dependencies(TinyBridgeSystemTest bridge) -add_dependencies(TinyBridgeSystemTest ChAI) -add_dependencies(TinyBridgeSystemTest bridge_objs) -add_dependencies(TinyBridgeSystemTest TorchBridge) -target_link_options(TinyBridgeSystemTest - PRIVATE - --main-module bridge_system_test.chpl - -M ${PROJECT_ROOT_DIR}/lib - ${CHAI_LINKER_ARGS} + ${PROJECT_ROOT_DIR}/lib ) + # chpl test/tiny/layer_test.chpl -M lib bridge/include/bridge.h build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,libtorch/lib" # chpl --fast -o vgg test.chpl -M ../../lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/include/bridge.h /Users/iainmoncrief/Documents/Github/ChAI/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L /Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,/Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib" diff --git a/bridge/.DS_Store b/bridge/.DS_Store index 47d43d092..1fc778476 100644 Binary files a/bridge/.DS_Store and b/bridge/.DS_Store differ diff --git a/bridge/CMakeLists.txt b/bridge/CMakeLists.txt deleted file mode 100644 index 19071eaff..000000000 --- a/bridge/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ - - - -# READD THESE LATER (START) - -# find_package(OpenCV 4 REQUIRED) - -# find_library(ACCELERATE Accelerate REQUIRED) -# find_library(METAL Metal REQUIRED) -# find_library(FOUNDATION Foundation REQUIRED) - - - -# add_library(BridgeUtil INTERFACE) - -# Tell consumers where to find the headers -# target_include_directories(BridgeUtil -# INTERFACE # usage requirement -# ${CMAKE_CURRENT_SOURCE_DIR}/util -# ) - - -# READD END - -# (optional) expose compile options / definitions -# target_compile_features(myheaders INTERFACE cxx_std_20) -# target_compile_definitions(myheaders INTERFACE MYLIB_USE_SOMETHING=1) - -# (optional) make an alias so callers can use myproject::myheaders -# add_library(BridgeUtil::myheaders ALIAS myheaders) diff --git a/bridge/Fix.txt b/bridge/Fix.txt deleted file mode 100644 index 608e10be6..000000000 --- a/bridge/Fix.txt +++ /dev/null @@ -1,4 +0,0 @@ - -https://github.com/pytorch/pytorch/issues/20030 - -install_name_tool -add_rpath /opt/homebrew/opt/libomp/lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/lib/libtorch_cpu.dylib \ No newline at end of file diff --git a/bridge/Makefile b/bridge/Makefile deleted file mode 100644 index 079b6701e..000000000 --- a/bridge/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -CXX = /usr/bin/clang++ -PWD = $(shell pwd) -LIBTORCH = $(PWD)/libtorch - -all: bridge.o Bridge - -bridge.o: lib/bridge.cpp include/bridge.h - $(CXX) -c lib/bridge.cpp -I include -o bridge.o -I $(LIBTORCH)/include/torch/csrc/api/include -I $(LIBTORCH)/include --std=c++17 - -# g++ -c lib/bridge.cpp -I include -o bridge.o -I /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/include/torch/csrc/api/include -I /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/include --std=c++17 - -Bridge: bridge.o lib/Bridge.chpl - chpl lib/Bridge.chpl include/bridge.h bridge.o -L $(LIBTORCH)/lib -ltorch -ltorch_cpu -lc10 --ldflags "-Wl,-rpath,$(LIBTORCH)/lib" - -clean: - rm -f bridge.o - rm -f Bridge - - - diff --git a/bridge/_CMakeLists.txt b/bridge/_CMakeLists.txt deleted file mode 100644 index ebe1f4ef3..000000000 --- a/bridge/_CMakeLists.txt +++ /dev/null @@ -1,223 +0,0 @@ -cmake_minimum_required(VERSION 3.31 FATAL_ERROR) -# project(MyProject LANGUAGES CXX) - -include(CMakePrintHelpers) - -# set(CMAKE_VERBOSE_MAKEFILE ON) - -if(UNIX AND NOT APPLE) - set(LINUX TRUE) -endif() - -set(CMAKE_C_COMPILER "clang") -set(CMAKE_CXX_COMPILER "clang++") -set(CMAKE_CXX_STANDARD 17) - - -set(PROJECT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set(PROJECT_BINARY_DIR "${CMAKE_BINARY_DIR}") - - -# For ExternalProject_Add -include(FetchContent) -include(ExternalProject) - -# ------------------------------------------------------------------------------ -# 1) External project: build PyTorch (libtorch) from source as STATIC -# ------------------------------------------------------------------------------ - -# Where to place PyTorch after installation -# set(PYTORCH_INSTALL_DIR "${PROJECT_BINARY_DIR}/pytorch-install") -# set(PYTORCH_BUILD_DIR "${PROJECT_BINARY_DIR}/pytorch-prefix/src/pytorch-build") - -# set(PYTORCH_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/pytorch-install-prefix") -# file(MAKE_DIRECTORY "${PYTORCH_INSTALL_PREFIX}") - -# ExternalProject_Add can fetch from Git, a local path, or a release tarball. -# Here, for simplicity, we'll fetch from Git. In practice, you might want -# a fixed commit or a release tarball for reproducible builds. - -# 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 -# -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR} - -# INSTALL_DIR ${PYTORCH_INSTALL_DIR} # Where to install - -# # LOG_DOWNLOAD ON -# # LOG_UPDATE ON -# # LOG_PATCH ON -# # LOG_CONFIGURE ON -# # LOG_BUILD ON -# # LOG_INSTALL ON - -# ) - -set(PYTORCH_INSTALL_DIR "${PROJECT_ROOT_DIR}/libtorch") -# file(GLOB_RECURSE PYTORCH_INCLUDES "${PYTORCH_INSTALL_DIR}/include" "*.h") -# file(GLOB_RECURSE PYTORCH_LIBS "${PYTORCH_INSTALL_DIR}/lib" "*.a") - - -# set(PYTORCH_LIBS_LINKER_ARGS "-L/Users/jade/Development/libtorch/libtorch/lib") # Will hold the list of "-l..." flags. -# foreach(lib_path IN LISTS PYTORCH_LIBS) -# # Get just the filename without the directory or extension -# get_filename_component(lib_name "${lib_path}" NAME_WE) -# # If it starts with "lib", strip that off -# string(REGEX REPLACE "^lib" "" lib_name "${lib_name}") -# # Now prepend "-l" to the actual library name -# list(APPEND MY_LIBS "-l${lib_name}") -# endforeach() - - -find_package(chpl REQUIRED HINTS ${PROJECT_ROOT_DIR}/cmake/chapel) -list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake") -list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake/chapel") - -project(MyProject LANGUAGES CXX C CHPL) - -# ------------------------------------------------------------------------------ -# 2) Create an INTERFACE library to wrap the installed static libs -# ------------------------------------------------------------------------------ - -# We'll create a dummy target that depends on 'pytorch' so that -# building your own code will first build/install PyTorch. - -# add_library(torch_interface INTERFACE) - -# # Ensure that our 'torch_interface' target isn't used until PyTorch is built -# # add_dependencies(torch_interface pytorch) - -# # Include directories for PyTorch -# target_include_directories(torch_interface INTERFACE -# "${PYTORCH_INSTALL_DIR}/include" -# "${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include" -# # "${PYTORCH_BUILD_DIR}/aten/src/include" -# ) - -# # Link the relevant static libraries. For a minimal CPU-only build, -# # you'll likely need at least these (names can vary by version). -# # The exact set can differ depending on which components got built. - -# target_link_libraries(torch_interface INTERFACE -# "${PYTORCH_INSTALL_DIR}/lib/libtorch.a" -# "${PYTORCH_INSTALL_DIR}/lib/libtorch_cpu.a" -# "${PYTORCH_INSTALL_DIR}/lib/libc10.a" - -# # ${PYTORCH_LIBS} - -# # System libraries often needed: -# pthread -# dl -# rt -# ) - - - -add_executable(CHPLTest lib/CHPLTest.chpl) - - -add_library(torchbridge OBJECT "${PROJECT_ROOT_DIR}/lib/bridge.cpp" "${PROJECT_ROOT_DIR}/include/bridge.h") -# add_dependencies(torchbridge torch_interface) - -target_include_directories(torchbridge PRIVATE - "${PYTORCH_INSTALL_DIR}/include" - "${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include" - "${PROJECT_ROOT_DIR}/include" -# # "${PYTORCH_BUILD_DIR}/aten/src/include" -) -# target_link_directories(torchbridge PUBLIC -# "${PYTORCH_INSTALL_DIR}/lib" -# ) -# target_link_libraries(torchbridge -# PRIVATE -# # torch_interface -# # ${PYTORCH_LIBS} - -# pthread -# dl -# rt -# ) - - - - - -add_executable(Bridge lib/Bridge.chpl include/bridge.h) -# add_dependencies(TorchBridge torchbridge) -add_dependencies(Bridge torchbridge) - -target_link_options(Bridge - PRIVATE - "${PROJECT_ROOT_DIR}/include/bridge.h" - "-L${PROJECT_BINARY_DIR}" - # "-ltorchbridge" - # -L. - "-ltorchbridge" - # "-I${PROJECT_BINARY_DIR}" - "-L${PYTORCH_INSTALL_DIR}/lib" - # "-I${PYTORCH_INSTALL_DIR}/include" - # "-I${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include" - "-ltorch" - "-ltorch_cpu" - # "-lcpuinfo" - "-lc10" - # "-lsleef" - # "-lclog" - # "-lprotoc" - # ${PYTORCH_LIBS_LINKER_ARGS} - # "-lpthread" - # "-ldl" - ) - - - -# ------------------------------------------------------------------------------ -# 3) Build your own executable that uses torch_interface -# ------------------------------------------------------------------------------ - -# add_executable(my_app src/main.cpp) - -# # Link your app against our interface library -# target_link_libraries(my_app PRIVATE torch_interface) - diff --git a/bridge/cmake/chapel/CMakeCHPLCompiler.cmake.in b/bridge/cmake/chapel/CMakeCHPLCompiler.cmake.in deleted file mode 100644 index cc000ad9e..000000000 --- a/bridge/cmake/chapel/CMakeCHPLCompiler.cmake.in +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023-2025 Hewlett Packard Enterprise Development LP -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set(CMAKE_CHPL_COMPILER "@CMAKE_CHPL_COMPILER@") -set(CMAKE_CHPL_COMPILER_LOADED 1) -set(CMAKE_CHPL_SOURCE_FILE_EXTENSIONS "@CMAKE_CHPL_SOURCE_FILE_EXTENSIONS@") -set(CMAKE_CHPL_OUTPUT_EXTENSION "@CMAKE_CHPL_OUTPUT_EXTENSION@") -set(CMAKE_CHPL_COMPILER_ENV_VAR "@CMAKE_CHPL_COMPILER_ENV_VAR@") diff --git a/bridge/cmake/chapel/CMakeCHPLInformation.cmake b/bridge/cmake/chapel/CMakeCHPLInformation.cmake deleted file mode 100644 index 2448ff1f5..000000000 --- a/bridge/cmake/chapel/CMakeCHPLInformation.cmake +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2023-2025 Hewlett Packard Enterprise Development LP -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# TODO: this is a hack, how do we tell cmake that we can't compile to object files? -set(CMAKE_CHPL_COMPILE_OBJECT "test -f || ln -s ") -set(CMAKE_CHPL_LINK_EXECUTABLE " -o ") -# doesn't work on link step - -# TODO: support --library directly to build Chapel shared libs for interoperability - -set(CMAKE_CHPL_SOURCE_FILE_EXTENSIONS chpl) - -set(CMAKE_CHPL_OUTPUT_EXTENSION ".chpl") - - -set(CMAKE_CHPL_FLAGS_RELEASE "--fast") -set(CMAKE_CHPL_FLAGS_DEBUG "-g") diff --git a/bridge/cmake/chapel/CMakeDetermineCHPLCompiler.cmake b/bridge/cmake/chapel/CMakeDetermineCHPLCompiler.cmake deleted file mode 100644 index 85e59b346..000000000 --- a/bridge/cmake/chapel/CMakeDetermineCHPLCompiler.cmake +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2023-2025 Hewlett Packard Enterprise Development LP -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# if there is an env CHPL_HOME, use it to find printchplenv -if (DEFINED ENV{CHPL_HOME}) - set(CHPL_HOME $ENV{CHPL_HOME}) - - execute_process( - COMMAND ${CHPL_HOME}/util/printchplenv --value --only CHPL_HOST_BIN_SUBDIR - OUTPUT_VARIABLE CHPL_HOST_BIN_SUBDIR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - set(CHPL_HOME_BIN_PATH ${CHPL_HOME}/bin/${CHPL_HOST_BIN_SUBDIR}) - # TODO: what if its a prefix install? -else() - set(CHPL_HOME "") - set(CHPL_HOME_BIN_PATH "") -endif() - -find_program( - CMAKE_CHPL_COMPILER - NAMES "chpl" - HINTS ${CHPL_HOME} ${CHPL_HOME_BIN_PATH} - DOC "chpl compiler" -) -# TODO: how to find chpl with just CHPL_HOME? - -set(CMAKE_CHPL_COMPILER_ENV_VAR "") - -configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeCHPLCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeCHPLCompiler.cmake) diff --git a/bridge/cmake/chapel/CMakeTestCHPLCompiler.cmake b/bridge/cmake/chapel/CMakeTestCHPLCompiler.cmake deleted file mode 100644 index 20cd8a372..000000000 --- a/bridge/cmake/chapel/CMakeTestCHPLCompiler.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2023-2025 Hewlett Packard Enterprise Development LP -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# For now do nothing -set(CMAKE_CHPL_COMPILER_WORKS 1 CACHE INTERNAL "") diff --git a/bridge/cmake/chapel/README.md b/bridge/cmake/chapel/README.md deleted file mode 100644 index bb3cff024..000000000 --- a/bridge/cmake/chapel/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# chpl CMake Support - -This directory contains the necessary files to support building Chapel programs using CMake. - -Take the following steps to use Chapel with CMake: - -1. Copy the files in this directory to your project's source directory. You may want to copy the files to a subdirectory like `cmake`, or you can just copy them to the root of your project. -2. Add `find_package(chpl REQUIRED HINTS .)` to your `CMakeLists.txt` file. - -Here is an example `CMakeLists.txt` file for a minimal Hello World program: - -```cmake -find_package(chpl REQUIRED HINTS .) -project(hello LANGUAGES CHPL) - -add_executable(hello hello.chpl) -``` diff --git a/bridge/cmake/chapel/chpl-config.cmake b/bridge/cmake/chapel/chpl-config.cmake deleted file mode 100644 index 145770e2a..000000000 --- a/bridge/cmake/chapel/chpl-config.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2023-2025 Hewlett Packard Enterprise Development LP -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") diff --git a/bridge/include/bridge.h.pch b/bridge/include/bridge.h.pch deleted file mode 100644 index 338831a66..000000000 Binary files a/bridge/include/bridge.h.pch and /dev/null differ diff --git a/bridge/jade.sh b/bridge/jade.sh deleted file mode 100644 index 9e5f5f8a4..000000000 --- a/bridge/jade.sh +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/bridge/lib/CHPLTest.chpl b/bridge/lib/CHPLTest.chpl deleted file mode 100644 index 759705ec1..000000000 --- a/bridge/lib/CHPLTest.chpl +++ /dev/null @@ -1 +0,0 @@ -writeln("Hello, world!"); diff --git a/bridge/lib/bridge.cpp b/bridge/lib/bridge.cpp index 9d46f5ca1..b40fbeed5 100644 --- a/bridge/lib/bridge.cpp +++ b/bridge/lib/bridge.cpp @@ -94,7 +94,8 @@ void store_tensor(at::Tensor &input, float32_t* dest) { std::memcpy(dest,data,bytes_size); } -bridge_tensor_t torch_to_bridge(at::Tensor &tensor) { +bridge_tensor_t torch_to_bridge(at::Tensor tensor_) { + at::Tensor tensor = tensor_.contiguous().to(torch::kCPU,torch::kFloat32,false,false); bridge_tensor_t result; result.created_by_c = true; result.was_freed = false; @@ -170,7 +171,9 @@ extern "C" bridge_tensor_t load_tensor_from_file(const uint8_t* file_path) { std::string fp(reinterpret_cast(file_path)); std::vector f = get_the_bytes(fp); torch::IValue x = torch::pickle_load(f); - torch::Tensor t = x.toTensor(); + at::Tensor t = x.toTensor(); + std::cout << "Tensor loaded from file: " << t.sizes() << std::endl; + std::cout.flush(); return torch_to_bridge(t); } diff --git a/bridge/run.sh b/bridge/run.sh deleted file mode 100644 index 3abffc955..000000000 --- a/bridge/run.sh +++ /dev/null @@ -1,3 +0,0 @@ - -cmake -S . -B build -cmake --build build diff --git a/demos/video/chapel-webcam/lib/Makefile.smol b/demos/video/chapel-webcam/lib/Makefile.smol deleted file mode 100644 index 3d06055c4..000000000 --- a/demos/video/chapel-webcam/lib/Makefile.smol +++ /dev/null @@ -1,17 +0,0 @@ -CHPL_RUNTIME_LIB = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/lib - -CHPL_RUNTIME_INCL = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/runtime/include - -CHPL_THIRD_PARTY = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/third-party - -CHPL_HOME = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec - -CHPL_CFLAGS = -Ilib -Wno-unused -Wno-uninitialized -Wno-pointer-sign -Wno-incompatible-pointer-types -Wno-tautological-compare -I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal -I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/packages -I../../../lib -I$(CHPL_RUNTIME_INCL)/localeModels/flat -I$(CHPL_RUNTIME_INCL)/localeModels -I$(CHPL_RUNTIME_INCL)/comm/none -I$(CHPL_RUNTIME_INCL)/comm -I$(CHPL_RUNTIME_INCL)/tasks/qthreads -I$(CHPL_RUNTIME_INCL)/. -I$(CHPL_RUNTIME_INCL)/./qio -I$(CHPL_RUNTIME_INCL)/./atomics/cstdlib -I$(CHPL_RUNTIME_INCL)/./mem/jemalloc -I$(CHPL_THIRD_PARTY)/utf8-decoder -I$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable -I$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/include -I. -I/opt/homebrew/Cellar/gmp/6.3.0/include -I/opt/homebrew/Cellar/hwloc/2.12.0/include -I/opt/homebrew/Cellar/jemalloc/5.3.0/include -I/opt/homebrew/include - -CHPL_LDFLAGS = -Llib -lsmol -ltorch -ltorch_cpu -lc10 -ltorch_global_deps -lbridge_objs -L$(CHPL_RUNTIME_LIB)/darwin/llvm/arm64/cpu-native/loc-flat/comm-none/tasks-qthreads/tmr-generic/unwind-none/mem-jemalloc/atomics-cstdlib/hwloc-system/re2-bundled/fs-none/lib_pic-none/san-none -lchpl -L$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -Wl,-rpath,$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -lqthread -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -L$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lre2 -Wl,-rpath,$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lm -lpthread -L/opt/homebrew/Cellar/gmp/6.3.0/lib -lgmp -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -Wl,-rpath,/opt/homebrew/Cellar/hwloc/2.12.0/lib -lhwloc -L/opt/homebrew/Cellar/jemalloc/5.3.0/lib -Wl,-rpath,/opt/homebrew/Cellar/jemalloc/5.3.0/lib -ljemalloc -L/opt/homebrew/lib - -CHPL_COMPILER = /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang - -CHPL_LINKER = /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang++ - -CHPL_LINKERSHARED = /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang++ -shared diff --git a/demos/video/chapel-webcam/lib/smol.cmake b/demos/video/chapel-webcam/lib/smol.cmake deleted file mode 100644 index 46fa60b50..000000000 --- a/demos/video/chapel-webcam/lib/smol.cmake +++ /dev/null @@ -1,15 +0,0 @@ -set(CHPL_RUNTIME_LIB /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/lib) - -set(CHPL_RUNTIME_INCL /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/runtime/include) - -set(CHPL_THIRD_PARTY /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/third-party) - -set(CHPL_HOME /opt/homebrew/Cellar/chapel/2.4.0_1/libexec) - -set(smol_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR} /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/packages ../../../lib ${CHPL_RUNTIME_INCL}/localeModels/flat ${CHPL_RUNTIME_INCL}/localeModels ${CHPL_RUNTIME_INCL}/comm/none ${CHPL_RUNTIME_INCL}/comm ${CHPL_RUNTIME_INCL}/tasks/qthreads ${CHPL_RUNTIME_INCL}/. ${CHPL_RUNTIME_INCL}/./qio ${CHPL_RUNTIME_INCL}/./atomics/cstdlib ${CHPL_RUNTIME_INCL}/./mem/jemalloc ${CHPL_THIRD_PARTY}/utf8-decoder ${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable ${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/include . /opt/homebrew/Cellar/gmp/6.3.0/include /opt/homebrew/Cellar/hwloc/2.12.0/include /opt/homebrew/Cellar/jemalloc/5.3.0/include /opt/homebrew/include) - -set(smol_LINK_LIBS -L${CMAKE_CURRENT_LIST_DIR} -lsmol -ltorch -ltorch_cpu -lc10 -ltorch_global_deps -lbridge_objs -L${CHPL_RUNTIME_LIB}/darwin/llvm/arm64/cpu-native/loc-flat/comm-none/tasks-qthreads/tmr-generic/unwind-none/mem-jemalloc/atomics-cstdlib/hwloc-system/re2-bundled/fs-none/lib_pic-none/san-none -lchpl -L${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -Wl,-rpath,${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -lqthread -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -L${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/lib -lre2 -Wl,-rpath,${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/lib -lm -lpthread -L/opt/homebrew/Cellar/gmp/6.3.0/lib -lgmp -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -Wl,-rpath,/opt/homebrew/Cellar/hwloc/2.12.0/lib -lhwloc -L/opt/homebrew/Cellar/jemalloc/5.3.0/lib -Wl,-rpath,/opt/homebrew/Cellar/jemalloc/5.3.0/lib -ljemalloc -L/opt/homebrew/lib -lsmol) - -set(CHPL_COMPILER /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang) -set(CHPL_LINKER /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang++) -set(CHPL_LINKERSHARED /opt/homebrew/Cellar/llvm@19/19.1.7/bin/clang++ -shared) diff --git a/demos/video/chapel-webcam/lib/smol.h b/demos/video/chapel-webcam/lib/smol.h deleted file mode 100644 index c212905c0..000000000 --- a/demos/video/chapel-webcam/lib/smol.h +++ /dev/null @@ -1,40 +0,0 @@ -#include "stdchpl.h" -#include "wctype.h" -#include "ctype.h" -#include "ImageHelper/stb_image_helper.h" -#include "bridge.h" -void chpl__init_Autograd(int64_t _ln, - int32_t _fn); -void chpl__init_Bridge(int64_t _ln, - int32_t _fn); -void chpl__init_DynamicTensor(int64_t _ln, - int32_t _fn); -void chpl__init_Layer(int64_t _ln, - int32_t _fn); -void chpl__init_NDArray(int64_t _ln, - int32_t _fn); -void chpl__init_Network(int64_t _ln, - int32_t _fn); -void chpl__init_Remote(int64_t _ln, - int32_t _fn); -void chpl__init_Standard(int64_t _ln, - int32_t _fn); -void chpl__init_StaticTensor(int64_t _ln, - int32_t _fn); -void chpl__init_SubModDistribution(int64_t _ln, - int32_t _fn); -void chpl__init_Types(int64_t _ln, - int32_t _fn); -void chpl__init_Utilities(int64_t _ln, - int32_t _fn); -void chpl__init_ndarrayRandom(int64_t _ln, - int32_t _fn); -void chpl__init_smol(int64_t _ln, - int32_t _fn); -int64_t getScaledFrameWidth(int64_t width); -int64_t getScaledFrameHeight(int64_t height); -void globalLoadModel(void); -chpl_external_array getNewFrame(chpl_external_array * frame, - int64_t height, - int64_t width, - int64_t channels); diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt deleted file mode 100644 index 4590c7216..000000000 --- a/dependencies/CMakeLists.txt +++ /dev/null @@ -1,89 +0,0 @@ -cmake_minimum_required(VERSION 3.18) -project(MyProject LANGUAGES CXX) - -# For ExternalProject_Add -include(FetchContent) -include(ExternalProject) - -# ------------------------------------------------------------------------------ -# 1) External project: build PyTorch (libtorch) from source as STATIC -# ------------------------------------------------------------------------------ - -# Where to place PyTorch after installation -set(PYTORCH_INSTALL_DIR "${CMAKE_BINARY_DIR}/pytorch-install") - -# ExternalProject_Add can fetch from Git, a local path, or a release tarball. -# Here, for simplicity, we'll fetch from Git. In practice, you might want -# a fixed commit or a release tarball for reproducible builds. - -ExternalProject_Add( - pytorch - GIT_REPOSITORY https://github.com/pytorch/pytorch.git - GIT_TAG v2.0.1 # Example: specify a particular release - UPDATE_COMMAND "" # Don’t auto-run 'git pull' - PATCH_COMMAND "" # No custom patch step - - # 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 - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR} - - INSTALL_DIR ${PYTORCH_INSTALL_DIR} # Where to install -) - -# ------------------------------------------------------------------------------ -# 2) Create an INTERFACE library to wrap the installed static libs -# ------------------------------------------------------------------------------ - -# We'll create a dummy target that depends on 'pytorch' so that -# building your own code will first build/install PyTorch. - -add_library(torch_interface INTERFACE) - -# Ensure that our 'torch_interface' target isn't used until PyTorch is built -add_dependencies(torch_interface pytorch) - -# Include directories for PyTorch -target_include_directories(torch_interface INTERFACE - "${PYTORCH_INSTALL_DIR}/include" - "${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include" -) - -# Link the relevant static libraries. For a minimal CPU-only build, -# you'll likely need at least these (names can vary by version). -# The exact set can differ depending on which components got built. - -target_link_libraries(torch_interface INTERFACE - "${PYTORCH_INSTALL_DIR}/lib/libtorch.a" - "${PYTORCH_INSTALL_DIR}/lib/libtorch_cpu.a" - "${PYTORCH_INSTALL_DIR}/lib/libc10.a" - - # System libraries often needed: - pthread - dl - rt -) - -# ------------------------------------------------------------------------------ -# 3) Build your own executable that uses torch_interface -# ------------------------------------------------------------------------------ - -# add_executable(my_app src/main.cpp) - -# # Link your app against our interface library -# target_link_libraries(my_app PRIVATE torch_interface) - diff --git a/dependencies/run.sh b/dependencies/run.sh deleted file mode 100644 index 3abffc955..000000000 --- a/dependencies/run.sh +++ /dev/null @@ -1,3 +0,0 @@ - -cmake -S . -B build -cmake --build build diff --git a/embed_libtorch.sh b/embed_libtorch.sh deleted file mode 100755 index c3d46fdc6..000000000 --- a/embed_libtorch.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env sh - -# -# This script prints the flags required by the Chapel compiler to embed Python -# code in a Chapel program. It is intended to be used by consumers of the -# 'Python' module. See https://chapel-lang.org/docs/modules/packages/Python.html -# - -# get the chpl home directory -# chpl_home=$(cd $(dirname $0) ; cd ..; cd ..; pwd) -# chpl_python=$("$chpl_home/util/config/find-python.sh") - -cd "$(dirname "$0")" - -mkdir -p build -cd build -cmake .. > /dev/null -make -j4 > /dev/null -cd .. - -SOURCE_DIR=$(pwd) -BRIDGE_LIB=$SOURCE_DIR/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -LIBTORCH_DIR=$SOURCE_DIR/libtorch - - -echo "-M $SOURCE_DIR/lib $SOURCE_DIR/bridge/include/bridge.h $BRIDGE_LIB -I $SOURCE_DIR/bridge/include -L $LIBTORCH_DIR/lib --ldflags -Wl,-rpath,$SOURCE_DIR/libtorch/lib" - -# PYTHON_INCLUDE_DIR=$($chpl_python -c "import sysconfig; print(sysconfig.get_paths()['include'])") -# PYTHON_LIB_DIR=$($chpl_python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -# PYTHON_LDVERSION=$($chpl_python -c "import sysconfig; print(sysconfig.get_config_var('LDVERSION'))") - -# DISABLE_WARNINGS="" -# # some older python's don't use `#ifndef` when they should -# # so we disable redefinition warnings for clean testing -# DISABLE_WARNINGS="$DISABLE_WARNINGS --ccflags -Wno-macro-redefined" - -# echo "--ccflags -isystem$PYTHON_INCLUDE_DIR -L$PYTHON_LIB_DIR --ldflags -Wl,-rpath,$PYTHON_LIB_DIR -lpython$PYTHON_LDVERSION $DISABLE_WARNINGS" \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 277b468c9..5f1bb557d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,7 +2,4 @@ add_subdirectory(my_example) -add_subdirectory(torch_model_loading) - - -add_subdirectory(split_loop) \ No newline at end of file +add_subdirectory(torch-tensor-loading) diff --git a/examples/split_loop/CMakeLists.txt b/examples/split_loop/CMakeLists.txt deleted file mode 100644 index 0cca4d929..000000000 --- a/examples/split_loop/CMakeLists.txt +++ /dev/null @@ -1,86 +0,0 @@ -find_package(OpenCV 4 REQUIRED) - -find_library(ACCELERATE Accelerate REQUIRED) -find_library(METAL Metal REQUIRED) -find_library(FOUNDATION Foundation REQUIRED) - - - -add_library(bridge_cv OBJECT ${BRIDGE_DIR}/include/bridge.h ${BRIDGE_DIR}/lib/bridge.cpp) - -target_link_directories(bridge_cv PRIVATE ${LIBTORCH_DIR}/lib) - -target_link_libraries( - bridge_cv - PRIVATE - -ltorch - -ltorch_cpu - -lc10 - -ltorch_global_deps - ${OpenCV_LIBS} - # ${TORCH_LIBRARIES} - ${ACCELERATE} - ${METAL} - ${FOUNDATION} -) - -target_include_directories( - bridge_cv - PRIVATE - ${BRIDGE_DIR}/include - ${LIBTORCH_DIR}/include - ${LIBTORCH_DIR}/include/torch/csrc/api/include - # ${BRIDGE_DIR}/util -) - -# if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") -# target_compile_options(bridge_cv PRIVATE -Ofast -flto -ffast-math) -# target_link_options(bridge_cv PRIVATE -flto) -# endif() - - -set(BRIDGE_CV_OBJECT_FILES $) - - -set(CHAI_CV_LINKER_ARGS - -M ${PROJECT_ROOT_DIR}/lib - ${BRIDGE_DIR}/include/bridge.h - ${BRIDGE_CV_OBJECT_FILES} - -L ${LIBTORCH_DIR}/lib - ${LIBTORCH_LIBS_LINKER_ARGS} - --ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib" -) - - - - - - - - -add_executable(SplitLoop - ${CMAKE_CURRENT_SOURCE_DIR}/split_loop.chpl - ${CHAI_LIB_FILES} -) - -add_dependencies(SplitLoop bridge_cv) -# add_dependencies(SplitLoop ChAI) -target_link_options(SplitLoop - PRIVATE - ${CHAI_CV_LINKER_ARGS} -) - -cmake_print_variables(CHAI_CV_LINKER_ARGS) -cmake_print_variables(OpenCV_LIBS) -cmake_print_variables(ACCELERATE) -cmake_print_variables(METAL) -cmake_print_variables(FOUNDATION) - -set_target_properties(SplitLoop PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} -) - -# if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") -# target_compile_options(SplitLoop PRIVATE -Ofast -flto -ffast-math) -# target_link_options(SplitLoop PRIVATE -flto) -# endif() \ No newline at end of file diff --git a/examples/split_loop/split_loop.chpl b/examples/split_loop/split_loop.chpl deleted file mode 100644 index 9c633b35a..000000000 --- a/examples/split_loop/split_loop.chpl +++ /dev/null @@ -1,27 +0,0 @@ -use Tensor; -use CTypes; - -proc main(args: [] string) { - writeln("Hello, world!"); - - // cobegin { - // for i in 0..<100 { - // begin Bridge.splitLoop(i,100); - // } - // } - var n: int(64) = 0; - var nr = c_ptrTo(n); - cobegin { - begin Bridge.splitLoopFiller(1000000,nr); - - for i in 0..<10 { - writeln("Hello from ", nr.deref()); - } - - } - - - Bridge.showWebcam(); - - writeln("Done!"); -} \ No newline at end of file diff --git a/examples/torch-tensor-loading/CMakeLists.txt b/examples/torch-tensor-loading/CMakeLists.txt new file mode 100644 index 000000000..9f91097c2 --- /dev/null +++ b/examples/torch-tensor-loading/CMakeLists.txt @@ -0,0 +1,34 @@ + + + + + +# add_executable(TorchLoad +# ${CMAKE_CURRENT_SOURCE_DIR}/torch_load.chpl +# ${CHAI_LIB_FILES} +# ) +# add_dependencies(TorchLoad bridge) +# add_dependencies(TorchLoad ChAI) +# add_dependencies(TorchLoad bridge_objs) +# target_link_options(TorchLoad +# PRIVATE +# --main-module torch_load.chpl +# -M ${PROJECT_ROOT_DIR}/lib +# ${CHAI_LINKER_ARGS} +# ) + +chai_add_executable(TorchLoad + ${CMAKE_CURRENT_SOURCE_DIR}/torch_load.chpl + ${PROJECT_ROOT_DIR}/lib +) + +add_custom_command(TARGET TorchLoad POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/tensors" + "${CMAKE_BINARY_DIR}/examples/TorchLoad/tensors" + COMMENT "Copying tensor folder" +) + +set_target_properties(TorchLoad PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) diff --git a/examples/torch_model_loading/mktensor.ipynb b/examples/torch-tensor-loading/mktensor.ipynb similarity index 85% rename from examples/torch_model_loading/mktensor.ipynb rename to examples/torch-tensor-loading/mktensor.ipynb index 000f02119..13ebe726b 100644 --- a/examples/torch_model_loading/mktensor.ipynb +++ b/examples/torch-tensor-loading/mktensor.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "873dd3b8", "metadata": {}, "outputs": [], @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "a07c23ff", "metadata": {}, "outputs": [], @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "131adc46", "metadata": {}, "outputs": [ @@ -57,39 +57,49 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 11, "id": "d4aed442", "metadata": {}, "outputs": [], "source": [ - "x = torch.arange(0,num_elt)\n", - "x = x.reshape(f1,f2).to(torch.float32)" + "x = torch.arange(0,(500 ** 2)*3)\n", + "x = x.reshape(3,500,500).to(torch.float32)" ] }, { "cell_type": "code", - "execution_count": 6, - "id": "481d4709", + "execution_count": 12, + "id": "c45c09fc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "torch.Size([3, 500, 500])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "torch.save(x, 'models/my_tensor.pt')" + "x.shape" ] }, { "cell_type": "code", - "execution_count": 7, - "id": "1a17ec15", + "execution_count": 13, + "id": "481d4709", "metadata": {}, "outputs": [], "source": [ - "m = {'a': x, 'b': x + 1}\n", - "torch.save(m, 'models/my_tensor_dict.pt')" + "torch.save(x, 'models/input.pt')" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "id": "841d4dfe", "metadata": {}, "outputs": [], @@ -112,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "id": "ca34dafc", "metadata": {}, "outputs": [ @@ -122,7 +132,7 @@ "True" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } diff --git a/examples/torch-tensor-loading/tensors/input.pt b/examples/torch-tensor-loading/tensors/input.pt new file mode 100644 index 000000000..57acf9652 Binary files /dev/null and b/examples/torch-tensor-loading/tensors/input.pt differ diff --git a/examples/torch-tensor-loading/torch_load.chpl b/examples/torch-tensor-loading/torch_load.chpl new file mode 100644 index 000000000..1de2c30e7 --- /dev/null +++ b/examples/torch-tensor-loading/torch_load.chpl @@ -0,0 +1,23 @@ +use Tensor; + + +proc main(args: [] string) { + + var image = ndarray.loadPyTorchTensor(3,args[1],real(32)); + writeln("Image shape: ", image.shape); + + image = image.resize(224,224); + writeln("Resized image: ", image.shape); + image = image.imageNetNormalize(); + writeln("Normed-Resized image: ", image.shape); + + var batchedImage = ndarray.loadPyTorchTensor(3,args[1],real(32)).unsqueeze(0); + writeln("Batched image: ", batchedImage.shape); + + writeln("Batched image resized: ", batchedImage.shape); + + image = batchedImage.squeeze(3).imageNetNormalize(); + writeln("Squeezed image: ", image.shape); + + image.saveImage("test.jpg"); +} \ No newline at end of file diff --git a/examples/torch_model_loading/CMakeLists.txt b/examples/torch_model_loading/CMakeLists.txt deleted file mode 100644 index b8cd059cd..000000000 --- a/examples/torch_model_loading/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - - - - - -add_executable(TorchLoad - ${CMAKE_CURRENT_SOURCE_DIR}/torch_load.chpl - ${CHAI_LIB_FILES} -) -add_dependencies(TorchLoad bridge) -add_dependencies(TorchLoad ChAI) -target_link_options(TorchLoad - PRIVATE - ${CHAI_LINKER_ARGS} -) - -add_custom_command(TARGET TorchLoad POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CMAKE_CURRENT_SOURCE_DIR}/models" - "$/models" - COMMENT "Copying model folder" -) \ No newline at end of file diff --git a/examples/torch_model_loading/models/my_tensor.pt b/examples/torch_model_loading/models/my_tensor.pt deleted file mode 100644 index 768a801f4..000000000 Binary files a/examples/torch_model_loading/models/my_tensor.pt and /dev/null differ diff --git a/examples/torch_model_loading/models/my_tensor_dict.pt b/examples/torch_model_loading/models/my_tensor_dict.pt deleted file mode 100644 index 054c9fb55..000000000 Binary files a/examples/torch_model_loading/models/my_tensor_dict.pt and /dev/null differ diff --git a/examples/torch_model_loading/torch_load.chpl b/examples/torch_model_loading/torch_load.chpl deleted file mode 100644 index 93c3a4063..000000000 --- a/examples/torch_model_loading/torch_load.chpl +++ /dev/null @@ -1,25 +0,0 @@ -use Tensor; - - -proc main(args: [] string) { - // const a = ndarray.loadPyTorchTensorDictWithKey(2,"models/my_tensor_dict.pt","a"); - // const b = ndarray.loadPyTorchTensorDictWithKey(2,"models/my_tensor_dict.pt","b"); - // writeln("a sum: ", a.sum()); - // writeln("b sum: ", b.sum()); - - var image = ndarray.loadFrom(args[1],3,real(32)); - - image = image.resize(224,224).imageNetNormalize(); - writeln("Resized image: ", image.shape); - - var batchedImage = ndarray.loadFrom(args[1],3,real(32)).unsqueeze(0); - writeln("Batched image: ", batchedImage.shape); - - // batchedImage = batchedImage.resize(224,224); - writeln("Batched image resized: ", batchedImage.shape); - - image = batchedImage.squeeze(3).imageNetNormalize(); - writeln("Squeezed image: ", image.shape); - - image.saveImage("test.jpg"); -} \ No newline at end of file diff --git a/learning/IterTest.chpl b/learning/IterTest.chpl deleted file mode 100644 index 9a1c70d0c..000000000 --- a/learning/IterTest.chpl +++ /dev/null @@ -1,19 +0,0 @@ -use Utilities.Standard; - -const D = {0..<5,0..<5}; - -// for idx in D { -// var i = 0; -// var blk = 1; -// for param j in 0.., B: float<2>) -> float<2>; -mat_mul A B = A @ B; - -kernel mat_mul(in A: float<2>, in B: float<2>, out C: float<2>) { - C = A @ B; -} - -kernel mat_mul_delta(in A: float<2>, in B: float<2>, out C: float<2>) -> float<2>; -mat_mul_delta A B = ∂(A @ B) / ∂A; - diff --git a/to_run.sh b/to_run.sh deleted file mode 100644 index b7964bdab..000000000 --- a/to_run.sh +++ /dev/null @@ -1,9 +0,0 @@ -git clone --recursive https://github.com/pytorch/pytorch -cd pytorch -pip install cmake ninja -pip install -r requirements.txt -pip install pkg-config libuv -MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py build --cmake-only - - -python3 setup.py develop