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

Patch to onnxruntime-1.16.2 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 cgo_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package onnxruntime
// Changes here should be mirrored in contrib/cgo_static.go and cuda/cgo_static.go.

/*
#cgo CXXFLAGS: --std=c++11
#cgo CXXFLAGS: --std=c++17
#cgo !windows CPPFLAGS: -I/usr/local/include
#cgo !windows LDFLAGS: -L/usr/local/lib -lonnxruntime -lstdc++
*/
Expand Down
45 changes: 31 additions & 14 deletions core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,57 @@ ORTEnv ORTEnv_New(int logging_level,char* log_env) {
ORTSession* ORTSession_New(ORTEnv ort_env,char* model_location, ORTSessionOptions session_options){
auto session = new Ort::Session(*ort_env, model_location, *session_options);
Ort::AllocatorWithDefaultOptions allocator;
size_t num_input_nodes = (*session).GetInputCount();

size_t num_input_nodes = session->GetInputCount();
char **input_node_names = NULL;
std::vector<Ort::AllocatedStringPtr> inputNodeNameAllocatedStrings;
input_node_names = (char**)realloc(input_node_names, num_input_nodes*sizeof(*input_node_names));

// iterate over all input nodes
for (int i = 0; i < num_input_nodes; i++) {
char* input_name = (*session).GetInputName(i, allocator);
auto shapes = (*session).GetInputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
input_node_names[i] = input_name;
printf("Input %d : name=%s shape=", i, input_name);
auto input_name = session->GetInputNameAllocated(i, allocator);
auto shapes = session->GetInputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
inputNodeNameAllocatedStrings.push_back(std::move(input_name));
input_node_names[i] = inputNodeNameAllocatedStrings.back().get();
int length = strlen(input_node_names[i]);
char* varDest = (char*)malloc((length+1) * sizeof(char));
memcpy(varDest,input_node_names[i], length+1);
input_node_names[i] = varDest;
printf("Input : %d, Name : %s, Shape : [", i, input_node_names[i]);
for (size_t i = 0; i < shapes.size(); ++i) {
printf("%ld", shapes[i]);
if (i < shapes.size() - 1)
if (i < shapes.size() - 1){
printf(",");
}else{
printf("]\n");
}
}
printf("\n");
}

size_t num_output_nodes = (*session).GetOutputCount();
size_t num_output_nodes = session->GetOutputCount();
char **output_node_names = NULL;
std::vector<Ort::AllocatedStringPtr> outputNodeNameAllocatedStrings;
output_node_names = (char**)realloc(output_node_names, num_output_nodes*sizeof(*output_node_names));

// iterate over all output nodes
for (int i = 0; i < num_output_nodes; i++) {
char* output_name = (*session).GetOutputName(i, allocator);
auto shapes = (*session).GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
output_node_names[i] = output_name;
printf("Output %d : name=%s shape=", i, output_name);
auto output_name = session->GetOutputNameAllocated(i, allocator);
auto shapes = session->GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
outputNodeNameAllocatedStrings.push_back(std::move(output_name));
output_node_names[i] = outputNodeNameAllocatedStrings.back().get();
int length = strlen(output_node_names[i]);
char* varDest = (char*)malloc((length+1) * sizeof(char));
memcpy(varDest,output_node_names[i], length+1);
output_node_names[i] = varDest;
printf("Output : %d, Name : %s, Shape : [", i, output_node_names[i]);
for (size_t i = 0; i < shapes.size(); ++i) {
printf("%ld", shapes[i]);
if (i < shapes.size() - 1)
if (i < shapes.size() - 1){
printf(",");
} else{
printf("]\n");
}
}
printf("\n");
}

auto res = new ORTSession{session, input_node_names,num_input_nodes, output_node_names, num_output_nodes};
Expand Down
8 changes: 4 additions & 4 deletions dockerfile/Dockerfile_ubuntu_arm64_example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM ubuntu:20.04
FROM ubuntu:22.04
LABEL maintainer="Ivan Suteja <[email protected]>"

ARG GO_VERSION=1.14.15
ARG ONNXRUNTIME_VERSION=1.11.1
ARG ONNX_VERSION=1.12.0
ARG GO_VERSION=1.21.4
ARG ONNXRUNTIME_VERSION=1.16.2
ARG ONNX_VERSION=1.15.0

# DEFINE ALL ENV
ENV GOROOT=/usr/local/go
Expand Down