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

Updated CAPI calls #2012

Merged
merged 5 commits into from
Sep 5, 2023
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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ http_archive(
git_repository(
name = "mediapipe",
remote = "https://github.com/openvinotoolkit/mediapipe",
commit = "c839182d40daae7270a29feba5bedd6330ccc2f8", # Cleanup and switch to tflite object detection (#16)
commit = "ac9ff003cd735f96a2e5501e32b2c941f6d4543d", # Updated CAPI calls (#21)
)

# DEV mediapipe 1 source - adjust local repository path for build
Expand Down
26 changes: 13 additions & 13 deletions src/capi_frontend/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ OVMS_Status* OVMS_ServerReady(OVMS_Server* serverPtr, bool* isReady) {
*isReady = server.isReady();
return nullptr;
}
OVMS_Status* OVMS_StatusGetCode(OVMS_Status* status,
OVMS_Status* OVMS_StatusCode(OVMS_Status* status,
uint32_t* code) {
if (status == nullptr)
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "status"));
Expand All @@ -121,7 +121,7 @@ OVMS_Status* OVMS_StatusGetCode(OVMS_Status* status,
return nullptr;
}

OVMS_Status* OVMS_StatusGetDetails(OVMS_Status* status,
OVMS_Status* OVMS_StatusDetails(OVMS_Status* status,
const char** details) {
if (status == nullptr)
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "status"));
Expand Down Expand Up @@ -181,7 +181,7 @@ void OVMS_ServerDelete(OVMS_Server* server) {
// delete passed in ptr once multi server configuration is done
}

OVMS_Status* OVMS_GetMetadataFieldByPointer(OVMS_Metadata* metadata, const char* pointer, const char** value, size_t* size) {
OVMS_Status* OVMS_MetadataFieldByPointer(OVMS_Metadata* metadata, const char* pointer, const char** value, size_t* size) {
if (metadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "metadata"));
}
Expand Down Expand Up @@ -226,7 +226,7 @@ OVMS_Status* OVMS_SerializeMetadataToString(OVMS_Metadata* metadata, const char*
return nullptr;
}

OVMS_Status* OVMS_GetServerMetadata(OVMS_Server* server, OVMS_Metadata** metadata) {
OVMS_Status* OVMS_ServerMetadata(OVMS_Server* server, OVMS_Metadata** metadata) {
if (server == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "server"));
}
Expand Down Expand Up @@ -612,7 +612,7 @@ OVMS_Status* OVMS_InferenceRequestInputRemoveData(OVMS_InferenceRequest* req, co
return nullptr;
}

OVMS_Status* OVMS_InferenceResponseGetOutput(OVMS_InferenceResponse* res, uint32_t id, const char** name, OVMS_DataType* datatype, const int64_t** shape, size_t* dimCount, const void** data, size_t* bytesize, OVMS_BufferType* bufferType, uint32_t* deviceId) {
OVMS_Status* OVMS_InferenceResponseOutput(OVMS_InferenceResponse* res, uint32_t id, const char** name, OVMS_DataType* datatype, const int64_t** shape, size_t* dimCount, const void** data, size_t* bytesize, OVMS_BufferType* bufferType, uint32_t* deviceId) {
if (res == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "inference response"));
}
Expand Down Expand Up @@ -688,7 +688,7 @@ OVMS_Status* OVMS_InferenceResponseGetOutput(OVMS_InferenceResponse* res, uint32
return nullptr;
}

OVMS_Status* OVMS_InferenceResponseGetOutputCount(OVMS_InferenceResponse* res, uint32_t* count) {
OVMS_Status* OVMS_InferenceResponseOutputCount(OVMS_InferenceResponse* res, uint32_t* count) {
if (res == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "inference response"));
}
Expand All @@ -700,7 +700,7 @@ OVMS_Status* OVMS_InferenceResponseGetOutputCount(OVMS_InferenceResponse* res, u
return nullptr;
}

OVMS_Status* OVMS_InferenceResponseGetParameterCount(OVMS_InferenceResponse* res, uint32_t* count) {
OVMS_Status* OVMS_InferenceResponseParameterCount(OVMS_InferenceResponse* res, uint32_t* count) {
if (res == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "inference response"));
}
Expand All @@ -712,7 +712,7 @@ OVMS_Status* OVMS_InferenceResponseGetParameterCount(OVMS_InferenceResponse* res
return nullptr;
}

OVMS_Status* OVMS_InferenceResponseGetParameter(OVMS_InferenceResponse* res, uint32_t id, OVMS_DataType* datatype, const void** data) {
OVMS_Status* OVMS_InferenceResponseParameter(OVMS_InferenceResponse* res, uint32_t id, OVMS_DataType* datatype, const void** data) {
if (res == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "inference response"));
}
Expand Down Expand Up @@ -959,7 +959,7 @@ OVMS_Status* OVMS_GetServableMetadata(OVMS_Server* serverPtr, const char* servab
return nullptr;
}

OVMS_Status* OVMS_ServableMetadataGetInputCount(OVMS_ServableMetadata* servableMetadata, uint32_t* count) {
OVMS_Status* OVMS_ServableMetadataInputCount(OVMS_ServableMetadata* servableMetadata, uint32_t* count) {
if (servableMetadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "servable metadata"));
}
Expand All @@ -971,7 +971,7 @@ OVMS_Status* OVMS_ServableMetadataGetInputCount(OVMS_ServableMetadata* servableM
return nullptr;
}

OVMS_Status* OVMS_ServableMetadataGetOutputCount(OVMS_ServableMetadata* servableMetadata, uint32_t* count) {
OVMS_Status* OVMS_ServableMetadataOutputCount(OVMS_ServableMetadata* servableMetadata, uint32_t* count) {
if (servableMetadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "servable metadata"));
}
Expand All @@ -982,7 +982,7 @@ OVMS_Status* OVMS_ServableMetadataGetOutputCount(OVMS_ServableMetadata* servable
*count = metadata->getOutputsInfo().size();
return nullptr;
}
OVMS_Status* OVMS_ServableMetadataGetInput(OVMS_ServableMetadata* servableMetadata, uint32_t id, const char** name, OVMS_DataType* datatype, size_t* dimCount, int64_t** shapeMin, int64_t** shapeMax) {
OVMS_Status* OVMS_ServableMetadataInput(OVMS_ServableMetadata* servableMetadata, uint32_t id, const char** name, OVMS_DataType* datatype, size_t* dimCount, int64_t** shapeMin, int64_t** shapeMax) {
if (servableMetadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "servable metadata"));
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ OVMS_Status* OVMS_ServableMetadataGetInput(OVMS_ServableMetadata* servableMetada
return nullptr;
}

OVMS_Status* OVMS_ServableMetadataGetOutput(OVMS_ServableMetadata* servableMetadata, uint32_t id, const char** name, OVMS_DataType* datatype, size_t* dimCount, int64_t** shapeMin, int64_t** shapeMax) {
OVMS_Status* OVMS_ServableMetadataOutput(OVMS_ServableMetadata* servableMetadata, uint32_t id, const char** name, OVMS_DataType* datatype, size_t* dimCount, int64_t** shapeMin, int64_t** shapeMax) {
if (servableMetadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "servable metadata"));
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ OVMS_Status* OVMS_ServableMetadataGetOutput(OVMS_ServableMetadata* servableMetad
return nullptr;
}

OVMS_Status* OVMS_ServableMetadataGetInfo(OVMS_ServableMetadata* servableMetadata, const void** info) {
OVMS_Status* OVMS_ServableMetadataInfo(OVMS_ServableMetadata* servableMetadata, const void** info) {
if (servableMetadata == nullptr) {
return reinterpret_cast<OVMS_Status*>(new Status(StatusCode::NONEXISTENT_PTR, "servable metadata"));
}
Expand Down
8 changes: 4 additions & 4 deletions src/main_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ int main(int argc, char** argv) {
if (res) {
uint32_t code = 0;
const char* details = nullptr;
OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);
std::cout << "Error starting the server. Code:" << code
<< "; details:" << details << std::endl;
OVMS_ServerDelete(srv);
Expand Down Expand Up @@ -327,8 +327,8 @@ int main(int argc, char** argv) {
if (res != nullptr) {
uint32_t code = 0;
const char* details = 0;
OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);
std::cerr << "Error occured during inference. Code:" << code
<< ", details:" << details << std::endl;
OVMS_StatusDelete(res);
Expand Down
18 changes: 9 additions & 9 deletions src/main_capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ int main() {
uint32_t code = 0;
const char* details = 0;

OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);

fprintf(stderr, "error during start: code %d, details: %s\n", code, details);

Expand Down Expand Up @@ -82,8 +82,8 @@ int main() {
uint32_t code = 0;
const char* details = 0;

OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);

fprintf(stderr, "error during inference: code %d, details: %s\n", code, details);

Expand All @@ -98,14 +98,14 @@ int main() {
}

const char* oName = NULL; // not needed
OVMS_DataType oType; // not needed
const int64_t* oShape; // not needed
size_t oDims; // not needed
OVMS_DataType oType; // not needed
const int64_t* oShape; // not needed
size_t oDims; // not needed
const void* oData = NULL;
size_t oNumBytes = 0;
OVMS_BufferType oBuffType; // not needed
uint32_t oDeviceId; // not needed
OVMS_InferenceResponseGetOutput(response, 0, &oName, &oType, &oShape, &oDims, &oData, &oNumBytes, &oBuffType, &oDeviceId);
uint32_t oDeviceId; // not needed
OVMS_InferenceResponseOutput(response, 0, &oName, &oType, &oShape, &oDims, &oData, &oNumBytes, &oBuffType, &oDeviceId);

float expectedOutput[DATA_SIZE];
for (int i = 0; i < NUM_ELEMENTS; i++) {
Expand Down
16 changes: 8 additions & 8 deletions src/main_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ int main(int argc, char** argv) {
OVMS_ServerNew(&srv);

OVMS_Metadata* metadata = 0;
OVMS_GetServerMetadata(srv, &metadata);
OVMS_ServerMetadata(srv, &metadata);
const char* version = 0;
size_t size;
OVMS_GetMetadataFieldByPointer(metadata, "/version", &version, &size);
OVMS_MetadataFieldByPointer(metadata, "/version", &version, &size);
std::cout << "OVMS Version: " << version << std::endl;
OVMS_StringFree(version);

Expand All @@ -105,8 +105,8 @@ int main(int argc, char** argv) {
uint32_t code = 0;
const char* details = nullptr;

OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);
std::cerr << "error during start: code:" << code << "; details:" << details << std::endl;

OVMS_StatusDelete(res);
Expand All @@ -132,8 +132,8 @@ int main(int argc, char** argv) {
if (res != nullptr) {
uint32_t code = 0;
const char* details = 0;
OVMS_StatusGetCode(res, &code);
OVMS_StatusGetDetails(res, &details);
OVMS_StatusCode(res, &code);
OVMS_StatusDetails(res, &details);
std::cout << "Error occured during inference. Code:" << code
<< ", details:" << details << std::endl;
OVMS_StatusDelete(res);
Expand All @@ -145,7 +145,7 @@ int main(int argc, char** argv) {
}
// read output
uint32_t outputCount = 0;
OVMS_InferenceResponseGetOutputCount(response, &outputCount);
OVMS_InferenceResponseOutputCount(response, &outputCount);
const void* voutputData;
size_t bytesize = 0;
uint32_t outputId = outputCount - 1;
Expand All @@ -155,7 +155,7 @@ int main(int argc, char** argv) {
OVMS_BufferType bufferType = (OVMS_BufferType)42;
uint32_t deviceId = 42;
const char* outputName{nullptr};
OVMS_InferenceResponseGetOutput(response, outputId, &outputName, &datatype, &shape, &dimCount, &voutputData, &bytesize, &bufferType, &deviceId);
OVMS_InferenceResponseOutput(response, outputId, &outputName, &datatype, &shape, &dimCount, &voutputData, &bytesize, &bufferType, &deviceId);

std::stringstream ss;
ss << "Got response from OVMS via C-API. "
Expand Down
6 changes: 3 additions & 3 deletions src/mediapipe_calculators/modelapiovmsinferencecalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace {
if (err != nullptr) { \
uint32_t code = 0; \
const char* msg = nullptr; \
OVMS_StatusGetCode(err, &code); \
OVMS_StatusGetDetails(err, &msg); \
OVMS_StatusCode(err, &code); \
OVMS_StatusDetails(err, &msg); \
LOG(INFO) << "Error encountred in OVMSCalculator:" << msg << " code: " << code; \
OVMS_StatusDelete(err); \
RET_CHECK(err == nullptr); \
Expand Down Expand Up @@ -127,7 +127,7 @@ class ModelAPISideFeedCalculator : public CalculatorBase {
// TODO decide which will be easier to migrating later
// using OV tensor by default will be more performant
// but harder to migrate
/*
/*
cc->Outputs().Tag(tag).Set<tensorflow::Tensor>();
*/
LOG(INFO) << "setting output tag:" << tag << " to OVTensor";
Expand Down
10 changes: 5 additions & 5 deletions src/mediapipe_calculators/ovms_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace {
if (err != nullptr) { \
uint32_t code = 0; \
const char* msg = nullptr; \
OVMS_StatusGetCode(err, &code); \
OVMS_StatusGetDetails(err, &msg); \
OVMS_StatusCode(err, &code); \
OVMS_StatusDetails(err, &msg); \
LOG(INFO) << "Error encountred in OVMSCalculator:" << msg << " code: " << code; \
OVMS_StatusDelete(err); \
RET_CHECK(err == nullptr); \
Expand Down Expand Up @@ -254,10 +254,10 @@ class OVMSOVCalculator : public CalculatorBase {
CREATE_GUARD(responseGuard, OVMS_InferenceResponse, response);
// verify GetOutputCount
uint32_t outputCount = 42;
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseGetOutputCount(response, &outputCount));
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseOutputCount(response, &outputCount));
RET_CHECK(outputCount == cc->Outputs().GetTags().size());
uint32_t parameterCount = 42;
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseGetParameterCount(response, &parameterCount));
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseParameterCount(response, &parameterCount));
// TODO handle output filtering. Graph definition could suggest
// that we are not interested in all outputs from OVMS Inference
const void* voutputData;
Expand All @@ -269,7 +269,7 @@ class OVMSOVCalculator : public CalculatorBase {
uint32_t deviceId = 42;
const char* outputName{nullptr};
for (size_t i = 0; i < outputCount; ++i) {
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseGetOutput(response, i, &outputName, &datatype, &shape, &dimCount, &voutputData, &bytesize, &bufferType, &deviceId));
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseOutput(response, i, &outputName, &datatype, &shape, &dimCount, &voutputData, &bytesize, &bufferType, &deviceId));
ov::Tensor* outOvTensor = makeOvTensor(datatype, shape, dimCount, voutputData, bytesize);
cc->Outputs().Tag(outputNameToTag.at(outputName)).Add(outOvTensor, cc->InputTimestamp());
}
Expand Down
Loading