forked from meta-pytorch/torchcodec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
53 lines (42 loc) · 1.49 KB
/
CMakeLists.txt
File metadata and controls
53 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
cmake_minimum_required(VERSION 3.18)
project(TorchCodec)
if(ENABLE_MUSA)
#set(CMAKE_VERBOSE_MAKEFILE on)
find_package(Python COMPONENTS Interpreter REQUIRED)
# 1. Find TORCH_PYTHONPATH
execute_process(
COMMAND
${Python_EXECUTABLE} -c "
import torch
print(torch.utils.cmake_prefix_path)"
OUTPUT_VARIABLE TORCH_PYTHONPATH)
string(REGEX REPLACE "^(.+)\n$" "\\1" TORCH_PYTHONPATH ${TORCH_PYTHONPATH})
message(STATUS "TORCH_PYTHONPATH: " ${TORCH_PYTHONPATH})
list(APPEND CMAKE_PREFIX_PATH ${TORCH_PYTHONPATH})
# 2. Find TORCH_MUSA_PYTHONPATH
execute_process(
COMMAND
${Python_EXECUTABLE} -c "
import os
os.environ[\"TORCH_DEVICE_BACKEND_AUTOLOAD\"] = \"0\"
import torch, torch_musa
print(torch_musa.core.cmake_prefix_path)"
OUTPUT_VARIABLE TORCH_MUSA_PYTHONPATH)
string(REGEX MATCH "^[^\r\n]*" TORCH_MUSA_PYTHONPATH "${TORCH_MUSA_PYTHONPATH}")
message(STATUS "TORCH_MUSA_PYTHONPATH: " ${TORCH_MUSA_PYTHONPATH})
list(APPEND CMAKE_PREFIX_PATH ${TORCH_MUSA_PYTHONPATH})
message(STATUS "CMAKE_PREFIX_PATH: " ${CMAKE_PREFIX_PATH})
execute_process(
COMMAND ${Python_EXECUTABLE} -c "
import torch, os;
print(os.path.join(torch.__path__[0], 'lib', 'libtorch_python.so'))"
OUTPUT_VARIABLE TORCH_PYTHON_LIB
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Using torch_python lib: ${TORCH_PYTHON_LIB}")
endif()
add_subdirectory(src/torchcodec/_core)
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()