Skip to content

Commit 5748998

Browse files
authored
Remove FetchContent from onnx app. (#9005)
1 parent 1a9ac3c commit 5748998

5 files changed

Lines changed: 90 additions & 24 deletions

File tree

apps/onnx/CMakeLists.txt

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,34 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
99
set(CMAKE_CXX_EXTENSIONS NO)
1010
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1111

12-
find_package(Protobuf)
12+
find_package(Protobuf CONFIG)
1313
if (NOT Protobuf_FOUND)
1414
message(WARNING "Could NOT find Protobuf")
1515
return()
1616
endif ()
1717

18+
find_package(ONNX CONFIG)
19+
if (NOT ONNX_FOUND)
20+
message(WARNING "Could NOT find ONNX package config")
21+
return()
22+
endif ()
23+
1824
find_package(Halide REQUIRED)
1925

20-
# Download onnx.proto
21-
include(FetchContent)
22-
FetchContent_Declare(
23-
onnx
24-
GIT_REPOSITORY https://github.com/onnx/onnx.git
25-
GIT_TAG e709452ef2bbc1d113faf678c24e6d3467696e83 # v1.18.0
26-
SOURCE_SUBDIR do-not-load/
27-
)
28-
FetchContent_MakeAvailable(onnx)
26+
find_path(ONNX_INCLUDE_DIR onnx/onnx_pb.h)
27+
if (NOT ONNX_INCLUDE_DIR)
28+
message(WARNING "Could NOT find ONNX headers")
29+
return()
30+
endif ()
31+
set(ONNX_PROTO_FILE "${ONNX_INCLUDE_DIR}/onnx/onnx-ml.proto")
2932

3033
# Add library that converts ONNX models to Halide operators
3134
add_library(oclib STATIC)
3235
add_library(onnx_app::oclib ALIAS oclib)
3336

34-
target_sources(oclib PRIVATE onnx_converter.cc "${onnx_SOURCE_DIR}/onnx/onnx.proto")
35-
protobuf_generate(
36-
TARGET oclib
37-
LANGUAGE cpp
38-
PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/_protoc_out
39-
IMPORT_DIRS ${onnx_SOURCE_DIR}
40-
)
41-
target_include_directories(oclib PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/_protoc_out")
42-
target_link_libraries(oclib PUBLIC Halide::Halide protobuf::libprotobuf-lite)
37+
target_sources(oclib PRIVATE onnx_converter.cc)
38+
target_include_directories(oclib PUBLIC "${ONNX_INCLUDE_DIR}")
39+
target_link_libraries(oclib PUBLIC Halide::Halide ONNX::onnx_proto)
4340
target_compile_definitions(oclib PUBLIC GOOGLE_PROTOBUF_NO_RTTI)
4441

4542
# Add test for the onnx converter library (oclib)
@@ -68,11 +65,11 @@ add_custom_command(
6865
COMMAND
6966
protobuf::protoc
7067
--encode=onnx.ModelProto
71-
"--proto_path=${onnx_SOURCE_DIR}"
72-
"$<SHELL_PATH:${onnx_SOURCE_DIR}/onnx/onnx.proto>"
68+
"--proto_path=${ONNX_INCLUDE_DIR}"
69+
"$<SHELL_PATH:${ONNX_PROTO_FILE}>"
7370
< "$<SHELL_PATH:${CMAKE_CURRENT_SOURCE_DIR}/test_model_proto.txt>"
7471
> test_model.onnx
75-
DEPENDS protobuf::protoc ${onnx_SOURCE_DIR}/onnx/onnx.proto
72+
DEPENDS protobuf::protoc ${ONNX_PROTO_FILE}
7673
COMMENT "Generating test ONNX model from proto content"
7774
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/test_model_proto.txt
7875
VERBATIM
@@ -102,7 +99,7 @@ set_tests_properties(
10299
)
103100

104101
# Python bindings to convert onnx models to Halide model
105-
find_package(Python 3 COMPONENTS Interpreter Development)
102+
find_package(Python 3 COMPONENTS Interpreter Development.Module)
106103
if (NOT Python_FOUND)
107104
message(WARNING "Could NOT find Python")
108105
return()

apps/onnx/onnx_converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define CONVERT_MODEL_H_
33

44
#include "Halide.h"
5-
#include "onnx/onnx.pb.h"
5+
#include "onnx/onnx_pb.h"
66
#include <unordered_map>
77
#include <vector>
88

apps/vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"eigen3",
1313
"libjpeg-turbo",
1414
"libpng",
15+
"onnx",
1516
{
1617
"name": "openblas",
1718
"platform": "(windows & x64 & !uwp & !xbox) | (linux & x64) | (linux & arm64)"
@@ -20,6 +21,8 @@
2021
"name": "opencl",
2122
"platform": "(windows & x64 & !uwp & !xbox) | (linux & x64) | (linux & arm64)"
2223
},
24+
"protobuf",
25+
"pybind11",
2326
"tensorflow-lite"
2427
]
2528
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This instructs vcpkg to do nothing, which causes find_package
2+
# to search the system for Python, rather than the vcpkg trees.
3+
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "python3",
3+
"version": "3.11.8",
4+
"port-version": 4,
5+
"description": "The Python programming language",
6+
"homepage": "https://github.com/python/cpython",
7+
"license": "Python-2.0",
8+
"supports": "!uwp & !mingw",
9+
"dependencies": [
10+
{
11+
"name": "bzip2",
12+
"platform": "!(windows & static)"
13+
},
14+
"expat",
15+
{
16+
"name": "gettext",
17+
"platform": "osx"
18+
},
19+
{
20+
"name": "libffi",
21+
"platform": "!(windows & static)"
22+
},
23+
{
24+
"name": "libiconv",
25+
"platform": "osx"
26+
},
27+
{
28+
"name": "liblzma",
29+
"platform": "!(windows & static)"
30+
},
31+
{
32+
"name": "libuuid",
33+
"platform": "!osx & !windows"
34+
},
35+
{
36+
"name": "openssl",
37+
"platform": "!(windows & static)"
38+
},
39+
{
40+
"name": "python3",
41+
"host": true
42+
},
43+
{
44+
"name": "sqlite3",
45+
"platform": "!(windows & static)"
46+
},
47+
{
48+
"name": "vcpkg-get-python",
49+
"host": true
50+
},
51+
{
52+
"name": "vcpkg-msbuild",
53+
"host": true,
54+
"platform": "windows"
55+
},
56+
"zlib"
57+
],
58+
"features": {
59+
"deprecated-win7-support": {
60+
"description": "Deprecated support for the Windows 7 platform -- may be removed at any time."
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)