Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7578f04
start writing the tests and header
Dec 17, 2025
9a7888f
attempt to build cmake
Dec 18, 2025
c02a3b9
update cmakelists and conanfile
Dec 30, 2025
bfa82d5
add main file
Dec 30, 2025
d1ee749
update header file
Dec 31, 2025
d7f9c75
planning for tests
Jan 2, 2026
c503977
move cmakefiles and cmakecache
Jan 2, 2026
df53bad
add to gitignore file
Jan 2, 2026
0b32815
remove tests
Jan 2, 2026
489b41c
add to cmakelists, remove build documents from git
Jan 2, 2026
3664c41
fix library linking, fix imports
Jan 5, 2026
ddca157
fix header file problems
Jan 6, 2026
ed09b6f
move to header file
Jan 6, 2026
55c554f
move class definition to header file
Jan 6, 2026
f2379be
fix syntax errors
Jan 7, 2026
a61a9ad
move some small methods to cpp
Jan 7, 2026
5e99066
move most methods to cpp
Jan 8, 2026
42e14ce
fix some of the errors in hpp and cpp files, but still make is not ru…
Jan 8, 2026
e1773a1
moved methods from write_to_tflite_tensor_visitor to cpp
Jan 8, 2026
6d17ea6
add back metadata function that somehow got removed
Jan 8, 2026
4c7f65a
remove alias
Jan 9, 2026
34c5374
add constructor to hpp file and remove alias from main. make is worki…
Jan 9, 2026
aa27c58
move write_to_tflite_tensor_visitor_ definition to cpp
Jan 9, 2026
cf0e95a
remove comments
Jan 9, 2026
df89d23
remove macos 13 as it has been retired
Jan 12, 2026
72fea80
fix formatting with clang-format
Jan 13, 2026
be68410
change executable/library name and remove unnecessary imports
Jan 14, 2026
a7a04c2
move write_to_tflite_tensor_visitor class to cpp
Jan 15, 2026
7efc8d9
fix write to tflite class errors
Jan 15, 2026
8f5a0ca
formatting, removing comments, move service_name to cpp
Jan 15, 2026
28668ee
move make_tensor_view methods to cpp file and rename them - does not …
Jan 16, 2026
3ce48ee
fix errors related to tensor_views_from_tflite_tensor
Jan 16, 2026
2429753
move service_data_type_from_tflite_data_type to cpp file, make MLMode…
Jan 16, 2026
29a8770
remove unnecessary imports, namespace changes
Jan 16, 2026
bd576dc
change executable/library name, fix binary name, change method name/s…
Jan 20, 2026
49e4f9d
put namespace alias back
Jan 20, 2026
14756f0
namespace/variable name changes
Jan 21, 2026
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
29 changes: 29 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 100
Cpp11BracedListStyle: true
DerivePointerAlignment: false
IncludeBlocks: Preserve
IncludeCategories:
- Regex: "<.*>"
Priority: 1
SortPriority: 0
- Regex: '^(<|"(boost|google|grpc)/)'
Priority: 3
SortPriority: 0
- Regex: ".*"
Priority: 1
SortPriority: 0
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentWidth: 4
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
SortIncludes: true
SpaceBeforeAssignmentOperators: true
Standard: Cpp11
UseTab: Never
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: Run linter and build

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
strategy:
matrix:
# TODO(RSDK-10636): run the build on windows-2019, too, when it's is tolerably fast
runs_on: [ubuntu-22.04, ubuntu-22.04-arm, macos-14, macos-13]
runs_on: [ubuntu-22.04, ubuntu-22.04-arm, macos-14]
name: "Lint and build on each platform"
runs-on: ${{ matrix.runs_on }}

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
*.app

CMakeUserPresets.json
build-conan
build-conan/
build/
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ find_package(Threads REQUIRED)
find_package(viam-cpp-sdk REQUIRED)
find_package(tensorflowlite REQUIRED)

add_executable(tflite_cpu
src/tflite_cpu.cpp
)
add_library(tflite_cpu_service src/tflite_cpu.cpp)

target_link_libraries(tflite_cpu
PRIVATE Threads::Threads
PRIVATE viam-cpp-sdk::viamsdk
target_link_libraries(tflite_cpu_service
PUBLIC Threads::Threads
PUBLIC viam-cpp-sdk::viamsdk
PRIVATE tensorflow::tensorflowlite
)

add_executable(tflite_cpu
src/main.cpp
)

target_link_libraries(tflite_cpu PRIVATE tflite_cpu_service)

install(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. What happened to the install target? Was this intentional? If so, why?

TARGETS tflite_cpu
)
)
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def requirements(self):
# NOTE: If you update the `viam-cpp-sdk` dependency here, it
# should also be updated in `bin/setup.{sh,ps1}`.
self.requires("viam-cpp-sdk/0.20.1")
self.requires("boost/[>=1.74.0]")
self.requires("tensorflow-lite/2.15.0")
# NOTE: This should match what the viam-cpp-sdk pulls (indirectly, via grpc/protobuf)
# TODO: Is there a way to express that better than hardcoding it?
Expand Down
64 changes: 64 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdexcept>

#include <viam/sdk/common/instance.hpp>
#include <viam/sdk/module/service.hpp>
#include <viam/sdk/registry/registry.hpp>

#include "tflite_cpu.hpp"

namespace {

int serve(const std::string& socket_path) try {
// Every Viam C++ SDK program must have one and only one Instance object which is created before
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
viam::sdk::Instance inst;

// Create a new model registration for the service.
auto module_registration = std::make_shared<viam::sdk::ModelRegistration>(
// Identify that this resource offers the MLModelService API
viam::sdk::API::get<viam::sdk::MLModelService>(),

// Declare a model triple for this service.
viam::sdk::Model{"viam", "mlmodel-tflite", "tflite_cpu"},

// Define the factory for instances of the resource.
[](viam::sdk::Dependencies deps, viam::sdk::ResourceConfig config) {
return std::make_shared<viam::mlmodel_tflite::MLModelServiceTFLite>(std::move(deps),
std::move(config));
});

// Register the newly created registration with the Registry.
viam::sdk::Registry::get().register_model(module_registration);

// Construct the module service and tell it where to place the socket path.
auto module_service = std::make_shared<viam::sdk::ModuleService>(socket_path);

// Add the server as providing the API and model declared in the
// registration.
module_service->add_model_from_registry(module_registration->api(),
module_registration->model());

// Start the module service.
module_service->serve();

return EXIT_SUCCESS;
} catch (const std::exception& ex) {
std::cout << "ERROR: A std::exception was thrown from `serve`: " << ex.what() << std::endl;
return EXIT_FAILURE;
} catch (...) {
std::cout << "ERROR: An unknown exception was thrown from `serve`" << std::endl;
return EXIT_FAILURE;
}
} // namespace

int main(int argc, char* argv[]) {
const auto usage = std::string("usage: ") + argv[0] + " /path/to/unix/socket";

if (argc < 2) {
std::cout << "ERROR: insufficient arguments\n";
std::cout << usage << "\n";
return EXIT_FAILURE;
}

return serve(argv[1]);
}
Loading