diff --git a/.gitignore b/.gitignore index f7d2a58..44373a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vscode/ -*.out \ No newline at end of file +*.out +*.a +*.o +*.so \ No newline at end of file diff --git a/README.md b/README.md index 92ba09e..68d7c8b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This repository contains the source code to compile an image upscale dynamic lib Make sure Tensorflow c is installed on your machine then link to that library when compiling (similar to below). ```console -gcc -I /usr/local/include/ -L /usr/local/lib/ -Wall -fPIC -C src/entry_functions.c -ltensorflow -o entry_functions.o +gcc -I /usr/local/include/ -L /usr/local/lib/ -Wall -fPIC -c src/entry_functions.c -ltensorflow -o entry_functions.o gcc -shared -o image-upscale.so entry_functions.o ``` diff --git a/src/entry_functions.c b/src/entry_functions.c index 5372196..2bf429d 100644 --- a/src/entry_functions.c +++ b/src/entry_functions.c @@ -6,7 +6,7 @@ Model* model = NULL; ModelInfo* modelInfo = NULL; -void initialize(const char* errorMsg){ +void initialize(char* errorMsg){ // create model model = newModel(); // get NoiseCancel model info (currently only supported model) @@ -15,27 +15,27 @@ void initialize(const char* errorMsg){ if(check.code) { freeModel(model); // free memory from model - errorMsg = TF_Message(check.status); + strcpy(errorMsg, TF_Message(check.status)); return; } check = findModelNodes(model, modelInfo); if(check.code) { freeModel(model); // free memory from model - errorMsg = TF_Message(check.status); + strcpy(errorMsg, TF_Message(check.status)); return; } } // on success call freeOutputData to avoid memory leak, returns null and errorMsg if errors -OutputData* runModel(const char* errorMsg, DataInfo dataInfo){ +OutputData* runModel(char* errorMsg, DataInfo dataInfo){ // create input and output tensor on heap TF_Tensor** inputTensor=(TF_Tensor**)malloc(sizeof(TF_Tensor*) * modelInfo->numInputNodes); - TF_Tensor* outputTensor = (TF_Tensor*)malloc(sizeof(TF_Tensor*)); + TF_Tensor* outputTensor=malloc(sizeof(TF_Tensor*)); // create tensors for all the static data required for models for(unsigned int i=0; i < modelInfo->numStaticInputData; ++i){ TFInfo check = dataInfoToTensor(&inputTensor, &modelInfo->staticInputData[i], model->status, i); if(check.code){ - errorMsg = TF_Message(check.status); + strcpy(errorMsg, TF_Message(check.status)); freeTensor(inputTensor, modelInfo->numInputNodes); free(outputTensor); return NULL; @@ -44,7 +44,7 @@ OutputData* runModel(const char* errorMsg, DataInfo dataInfo){ // create tensors from the passed in data TFInfo check = dataInfoToTensor(&inputTensor, &dataInfo, model->status, modelInfo->numStaticInputData); if(check.code){ - errorMsg = TF_Message(check.status); + strcpy(errorMsg, TF_Message(check.status)); freeTensor(inputTensor, modelInfo->numInputNodes); free(outputTensor); return NULL; @@ -52,7 +52,7 @@ OutputData* runModel(const char* errorMsg, DataInfo dataInfo){ // run model on the tensors check = run(model, modelInfo, inputTensor, &outputTensor); if(check.code){ - errorMsg = TF_Message(check.status); + strcpy(errorMsg, TF_Message(check.status)); freeTensor(inputTensor, modelInfo->numInputNodes); freeTensor(&outputTensor, 1); return NULL; @@ -77,4 +77,4 @@ void freeOutputData(OutputData *outputData){ void cleanup(){ freeModel(model); -} \ No newline at end of file +} diff --git a/src/entry_functions.h b/src/entry_functions.h index 3b20574..38ce69f 100644 --- a/src/entry_functions.h +++ b/src/entry_functions.h @@ -1,7 +1,7 @@ #include "models.c" #include "macros.c" -EXPORTED OutputData* runModel(const char* errorMsg, DataInfo dataInfo); -EXPORTED void initialize(const char* errorMsg); +EXPORTED OutputData* runModel(char* errorMsg, DataInfo dataInfo); +EXPORTED void initialize(char* errorMsg); EXPORTED void freeOutputData(OutputData *outputData); EXPORTED void cleanup(); \ No newline at end of file diff --git a/src/type_defines.c b/src/type_defines.c index 0251023..ccc096b 100644 --- a/src/type_defines.c +++ b/src/type_defines.c @@ -70,7 +70,7 @@ typedef struct OutputData{ // output tensor here for free call TF_Tensor* outputTensor; // number of dimensions - unsigned numOfDimensions; + unsigned int numOfDimensions; // shape of the data int64_t* dimension; }OutputData; \ No newline at end of file diff --git a/src/utility.c b/src/utility.c index cf96f0a..75ba49d 100644 --- a/src/utility.c +++ b/src/utility.c @@ -38,7 +38,15 @@ TFInfo dataInfoToTensor(TF_Tensor*** inputTensor, DataInfo* dataInfo, TF_Status* &NoOpDeallocator, 0); if(inputTensor[0][index] == NULL){ - return newTFInfo(status, TF_ABORTED, "Input tensor could not be created"); + char buffer[256]; + sprintf(buffer, "Input tensor could not be created. numDims: %i, dataSize: %i, dims:[%i,%i,%i,%i]", + (int)dataInfo->numberOfDimensions, + (int)dataInfo->dataSize, + (int)dataInfo->dimensions[0], + (int)dataInfo->dimensions[1], + (int)dataInfo->dimensions[2], + (int)dataInfo->dimensions[3]); + return newTFInfo(status, TF_ABORTED, buffer); } return newTFInfo(status, TF_OK, ""); }