Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] add onnx proto & meson setting #2891

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ option('enable-profile', type: 'boolean', value: false)
option('enable-trace', type: 'boolean', value: false)
option('enable-debug', type: 'boolean', value: false)
option('enable-tflite-interpreter', type: 'boolean', value: true)
option('enable-onnx-interpreter', type: 'boolean', value: false)
option('enable-memory-swap', type: 'boolean', value: false)
option('memory-swap-path', type: 'string', value: '')
option('test-timeout', type: 'integer', value: 60)
Expand Down
21 changes: 21 additions & 0 deletions nntrainer/compiler/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ compiler_headers = [
'compiler_fwd.h'
]

if get_option('enable-onnx-interpreter')
protobuf_dep = dependency('protobuf', required: true)
nntrainer_base_deps += protobuf_dep

protoc = find_program('protoc', required: true)
onnx_proto = custom_target('onnx_proto',
input: 'onnx.proto',
output: ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
command: [
protoc,
'--cpp_out=' + meson.build_root() + '/nntrainer/compiler',
'-I=' + meson.current_source_dir(),
meson.current_source_dir() + '/onnx.proto'
])

nntrainer_inc_abs += meson.current_build_dir()
nntrainer_inc += include_directories('.')
onnx_proto_dep = declare_dependency(sources : onnx_proto)
nntrainer_base_deps += onnx_proto_dep
endif
Copy link
Member

@myungjoo myungjoo Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a script to generate onnx.pb.cc around here.

Hints:

# Protobuf compiler
pb_comp = find_program('protoc', required: get_option('protobuf-support'))

https://github.com/nnstreamer/nnstreamer/blob/ff5c1fd34230e4d72eee0711118fedef64f3b8a1/meson.build#L156-L159

if protobuf_support_is_available
  pb_gen = generator(pb_comp,
      output: ['@BASENAME@.pb.h', '@BASENAME@.pb.cc'],
      arguments : [
        '--proto_path=@CURRENT_SOURCE_DIR@/include',
        '--cpp_out=@BUILD_DIR@',
        '@INPUT@'
      ]
  )
  pb_gen_src = pb_gen.process('./include/nnstreamer.proto')
endif

https://github.com/nnstreamer/nnstreamer/blob/ff5c1fd34230e4d72eee0711118fedef64f3b8a1/ext/nnstreamer/meson.build#L8-L18

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@myungjoo I haven't finished editing yet, but I accidentally pushed while working out of habit.
I'll refer to the code you provided, make the necessary changes, and push again. Thanks a lot!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protobuf_dep = dependency('protobuf', required: true)
nntrainer_base_deps += protobuf_dep

protoc = find_program('protoc', required: true)  
pb_gen = generator(
      protoc,
      output: ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
      arguments: ['--cpp_out=@BUILD_DIR@', '-I=@CURRENT_SOURCE_DIR@', '@INPUT@'],
    )
pb_gen_src = pb_gen.process('onnx.proto')
// + shared_library setting using pb_gen_src

@myungjoo I referred to the given code and tried to use the generator as shown above, and I think this method is more appropriate for this purpose. However, since the same meson script uses custom_target instead of generator for FlatBuffer and TFLite, I uploaded the code using custom_target to unify the code within the same script. How about updating all parts to use generator instead of custom_target at a later time(when I have some spare time)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. As long as you now have .proto file to generate .pb.cc/h automatically, it's all good.


if get_option('enable-tflite-interpreter')
if not tflite_dep.found()
error('Tensorflow2-Lite dependency not found')
Expand Down
Loading