Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions src/viam/sdk/services/private/discovery_client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <viam/sdk/services/private/discovery_client.hpp>

#include <viam/api/service/discovery/v1/discovery.grpc.pb.h>
#include <viam/api/service/discovery/v1/discovery.pb.h>

Expand All @@ -8,6 +6,7 @@
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/services/discovery.hpp>
#include <viam/sdk/services/private/discovery_client.hpp>

namespace viam {
namespace sdk {
Expand Down
3 changes: 1 addition & 2 deletions src/viam/sdk/services/private/discovery_server.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <viam/sdk/services/private/discovery_client.hpp>

#include <viam/sdk/common/private/repeated_ptr_convert.hpp>
#include <viam/sdk/common/private/service_helper.hpp>
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/services/private/discovery_client.hpp>
#include <viam/sdk/services/private/discovery_server.hpp>

namespace viam {
Expand Down
6 changes: 2 additions & 4 deletions src/viam/sdk/services/private/generic_client.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <viam/sdk/services/private/generic_client.hpp>

#include <utility>

#include <viam/api/common/v1/common.pb.h>
#include <viam/api/service/generic/v1/generic.grpc.pb.h>

#include <utility>
#include <viam/sdk/common/client_helper.hpp>
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/config/resource.hpp>
#include <viam/sdk/robot/client.hpp>
#include <viam/sdk/services/private/generic_client.hpp>

namespace viam {
namespace sdk {
Expand Down
3 changes: 1 addition & 2 deletions src/viam/sdk/services/private/generic_server.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <viam/sdk/services/private/generic_server.hpp>

#include <viam/sdk/common/private/service_helper.hpp>
#include <viam/sdk/rpc/server.hpp>
#include <viam/sdk/services/generic.hpp>
#include <viam/sdk/services/private/generic_server.hpp>

namespace viam {
namespace sdk {
Expand Down
7 changes: 2 additions & 5 deletions src/viam/sdk/services/private/mlmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <viam/sdk/services/private/mlmodel.hpp>

#include <boost/variant/get.hpp>
#include <memory>
#include <stack>
#include <stdexcept>
#include <type_traits>
#include <utility>

#include <boost/variant/get.hpp>

#include <viam/sdk/common/exception.hpp>
#include <viam/sdk/services/private/mlmodel.hpp>

namespace viam {
namespace sdk {
Expand Down
6 changes: 2 additions & 4 deletions src/viam/sdk/services/private/mlmodel_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <viam/sdk/services/private/mlmodel_client.hpp>

#include <grpcpp/channel.h>

#include <viam/sdk/common/client_helper.hpp>
#include <viam/sdk/services/private/mlmodel.hpp>

#include <viam/sdk/common/exception.hpp>
#include <viam/sdk/services/private/mlmodel.hpp>
#include <viam/sdk/services/private/mlmodel_client.hpp>

// As of proto version 27 (full version number 5.27) Arena::CreateMessage is deprecated in favor of
// Arena::Create. We use this macro to accomodate earlier supported versions of proto where
Expand Down
51 changes: 37 additions & 14 deletions src/viam/sdk/services/private/mlmodel_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <viam/sdk/services/private/mlmodel_server.hpp>

#include <viam/sdk/common/private/service_helper.hpp>
#include <viam/sdk/rpc/server.hpp>
#include <viam/sdk/services/mlmodel.hpp>
#include <viam/sdk/services/private/mlmodel.hpp>
#include <viam/sdk/services/private/mlmodel_server.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

It looks like maybe your editor got a little aggressive in its formatting opinions, here and in other files. Can you put back the header ordering? It actually is intentional the way it is, with the associated header coming first in its own group (helps ensure the header is standalone).

Copy link
Member Author

Choose a reason for hiding this comment

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

undid the bad linting

Copy link
Member

Choose a reason for hiding this comment

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

This one should go back up as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


namespace viam {
namespace sdk {
Expand All @@ -38,17 +37,13 @@ ::grpc::Status MLModelServiceServer::Infer(

const auto md = mlms->metadata({});
MLModelService::named_tensor_views inputs;
for (const auto& input : md.inputs) {
const auto where = request->input_tensors().tensors().find(input.name);
if (where == request->input_tensors().tensors().end()) {
// Ignore any inputs for which we don't have metadata, since
// we can't validate the type info.
//
// TODO: Should this be an error? For now we just don't decode
// those tensors.
continue;
}
auto tensor = mlmodel::make_sdk_tensor_from_api_tensor(where->second);

// Check if there's only one input tensor and metadata only expects one, too
if (request->input_tensors().tensors().size() == 1 && md.inputs.size() == 1) {
// Special case: just one tensor, add it without name check
const MLModelService::tensor_info input = md.inputs[0];
const auto& tensor_pair = *request->input_tensors().tensors().begin();
auto tensor = mlmodel::make_sdk_tensor_from_api_tensor(tensor_pair.second);
const auto tensor_type = MLModelService::tensor_info::tensor_views_to_data_type(tensor);
if (tensor_type != input.data_type) {
std::ostringstream message;
Expand All @@ -58,7 +53,35 @@ ::grpc::Status MLModelServiceServer::Infer(
<< static_cast<ut>(tensor_type);
return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str());
}
inputs.emplace(std::move(input.name), std::move(tensor));
inputs.emplace(tensor_pair.first, std::move(tensor));
} else {
// Normal case: multiple tensors, do metadata checks
for (const auto& input : md.inputs) {
const auto where = request->input_tensors().tensors().find(input.name);
if (where == request->input_tensors().tensors().end()) {
// Ignore any inputs for which we don't have metadata, since
Copy link
Member

Choose a reason for hiding this comment

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

Comment is stale.

// we can't validate the type info.
// if the input vector of the expected name is not found, return an error
std::ostringstream message;
message << "Expected tensor input `" << input.name
<< "` was not found; if you believe you have this tensor under a "
"different name, rename it to the expected tensor name";
return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str());
}
auto tensor = mlmodel::make_sdk_tensor_from_api_tensor(where->second);
const auto tensor_type =
MLModelService::tensor_info::tensor_views_to_data_type(tensor);
if (tensor_type != input.data_type) {
std::ostringstream message;
using ut = std::underlying_type<MLModelService::tensor_info::data_types>::type;
message << "Tensor input `" << input.name
<< "` was the wrong type; expected type "
<< static_cast<ut>(input.data_type) << " but got type "
<< static_cast<ut>(tensor_type);
return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str());
}
inputs.emplace(std::move(input.name), std::move(tensor));
}
}

const auto outputs = mlms->infer(inputs, helper.getExtra());
Expand Down
7 changes: 2 additions & 5 deletions src/viam/sdk/services/private/motion_client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <viam/sdk/services/private/motion_client.hpp>

#include <math.h>

#include <grpcpp/support/status.h>

#include <math.h>
#include <viam/api/service/motion/v1/motion.grpc.pb.h>
#include <viam/api/service/motion/v1/motion.pb.h>

Expand All @@ -12,6 +8,7 @@
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/services/motion.hpp>
#include <viam/sdk/services/private/motion_client.hpp>

namespace viam {
namespace sdk {
Expand Down
3 changes: 1 addition & 2 deletions src/viam/sdk/services/private/motion_server.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <memory>

#include <grpcpp/support/status.h>

#include <memory>
#include <viam/sdk/common/exception.hpp>
#include <viam/sdk/common/pose.hpp>
#include <viam/sdk/common/private/repeated_ptr_convert.hpp>
Expand Down
7 changes: 2 additions & 5 deletions src/viam/sdk/services/private/navigation_client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <viam/sdk/services/private/navigation_client.hpp>

#include <math.h>

#include <grpcpp/support/status.h>

#include <math.h>
#include <viam/api/service/navigation/v1/navigation.grpc.pb.h>
#include <viam/api/service/navigation/v1/navigation.pb.h>

Expand All @@ -12,6 +8,7 @@
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/services/navigation.hpp>
#include <viam/sdk/services/private/navigation_client.hpp>

namespace viam {
namespace sdk {
Expand Down
3 changes: 1 addition & 2 deletions src/viam/sdk/services/private/navigation_server.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <memory>

#include <grpcpp/support/status.h>

#include <memory>
#include <viam/sdk/common/pose.hpp>
#include <viam/sdk/common/private/repeated_ptr_convert.hpp>
#include <viam/sdk/common/private/service_helper.hpp>
Expand Down