diff --git a/model_zoo/official/cv/alexnet/ascend310_infer/src/main.cc b/model_zoo/official/cv/alexnet/ascend310_infer/src/main.cc index c0f66ce0c31..78ec674b974 100644 --- a/model_zoo/official/cv/alexnet/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/alexnet/ascend310_infer/src/main.cc @@ -120,7 +120,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } } else { auto input0_files = GetAllInputData(FLAGS_input0_path); @@ -155,9 +159,13 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i][j], outputs); + int rst = WriteResult(input0_files[i][j], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; } } + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/cv/alexnet/ascend310_infer/src/utils.cc b/model_zoo/official/cv/alexnet/ascend310_infer/src/utils.cc index d71f388b83d..2c11078eaaa 100644 --- a/model_zoo/official/cv/alexnet/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/alexnet/ascend310_infer/src/utils.cc @@ -22,7 +22,6 @@ using mindspore::MSTensor; using mindspore::DataType; - std::vector> GetAllInputData(std::string dir_name) { std::vector> ret; @@ -102,6 +101,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -112,7 +113,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE *outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/centerface/ascend310_infer/src/main.cc b/model_zoo/official/cv/centerface/ascend310_infer/src/main.cc index c170f4329d2..0abfd75936e 100644 --- a/model_zoo/official/cv/centerface/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/centerface/ascend310_infer/src/main.cc @@ -180,7 +180,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/cv/centerface/ascend310_infer/src/utils.cc b/model_zoo/official/cv/centerface/ascend310_infer/src/utils.cc index b509c57f823..c5ea5a4a461 100644 --- a/model_zoo/official/cv/centerface/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/centerface/ascend310_infer/src/utils.cc @@ -46,6 +46,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -56,7 +58,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/main.cc b/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/main.cc index be39426ed73..dc5e34bad5b 100644 --- a/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/main.cc @@ -107,7 +107,11 @@ int main(int argc, char **argv) { startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTime_ms, endTime_ms)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int infer_cnt = 0; diff --git a/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/utils.cc b/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/utils.cc index d231193e799..344fc329fb1 100644 --- a/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/cnn_direction_model/ascend310_infer/src/utils.cc @@ -63,6 +63,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -73,7 +75,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/cnnctc/ascend310_infer/src/main.cc b/model_zoo/official/cv/cnnctc/ascend310_infer/src/main.cc index 4345f3c6939..c6192c81b91 100644 --- a/model_zoo/official/cv/cnnctc/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/cnnctc/ascend310_infer/src/main.cc @@ -111,7 +111,6 @@ int main(int argc, char **argv) { std::cout << "ERROR: Build failed." << std::endl; return 1; } - auto all_files = GetAllFiles(FLAGS_dataset_path); std::map costTime_map; size_t size = all_files.size(); @@ -149,16 +148,13 @@ int main(int argc, char **argv) { int n = NewWidth; netOutput++; while (n < FLAGS_image_width) { - *netOutput = temp; - netOutput++; - n++; + *netOutput = temp; netOutput++; n++; } } } - std::vector model_inputs = model.GetInputs(); inputs.emplace_back(model_inputs[0].Name(), model_inputs[0].DataType(), model_inputs[0].Shape(), - img.Data().get(), img.DataSize()); + img.Data().get(), img.DataSize()); gettimeofday(&start, nullptr); ret = model.Predict(inputs, &outputs); gettimeofday(&end, nullptr); @@ -169,11 +165,14 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; - for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { double diff = 0.0; diff = iter->second - iter->first; diff --git a/model_zoo/official/cv/cnnctc/ascend310_infer/src/utils.cc b/model_zoo/official/cv/cnnctc/ascend310_infer/src/utils.cc index cc5e872a937..b91483aa87d 100644 --- a/model_zoo/official/cv/cnnctc/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/cnnctc/ascend310_infer/src/utils.cc @@ -46,6 +46,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -56,7 +58,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/crnn/ascend310_infer/src/main.cc b/model_zoo/official/cv/crnn/ascend310_infer/src/main.cc index 28cf63c95b4..293825c0119 100644 --- a/model_zoo/official/cv/crnn/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/crnn/ascend310_infer/src/main.cc @@ -136,7 +136,11 @@ int main(int argc, char **argv) { startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTime_ms, endTime_ms)); - WriteResult(allFiles[i], outputs); + int rst = WriteResult(allFiles[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int infer_cnt = 0; diff --git a/model_zoo/official/cv/crnn/ascend310_infer/src/utils.cc b/model_zoo/official/cv/crnn/ascend310_infer/src/utils.cc index b509c57f823..2083c4625c6 100644 --- a/model_zoo/official/cv/crnn/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/crnn/ascend310_infer/src/utils.cc @@ -46,6 +46,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -56,10 +58,21 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; - } + } return 0; } diff --git a/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc b/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc index 4396f2fdc17..6abcbc581ea 100644 --- a/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/ctpn/ascend310_infer/src/main.cc @@ -138,7 +138,11 @@ int main(int argc, char **argv) { startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTime_ms, endTime_ms)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int infer_cnt = 0; diff --git a/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc b/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc index 4557e1c3455..626924cc050 100644 --- a/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/ctpn/ascend310_infer/src/utils.cc @@ -46,6 +46,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput = outputs[i].Data(); @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE *outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/deeplabv3/ascend310_infer/src/main.cc b/model_zoo/official/cv/deeplabv3/ascend310_infer/src/main.cc index 41b434eb78f..5c47938ee02 100644 --- a/model_zoo/official/cv/deeplabv3/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/deeplabv3/ascend310_infer/src/main.cc @@ -195,7 +195,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/cv/deeplabv3/ascend310_infer/src/utils.cc b/model_zoo/official/cv/deeplabv3/ascend310_infer/src/utils.cc index 40762c41edc..d80fd5347bb 100644 --- a/model_zoo/official/cv/deeplabv3/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/deeplabv3/ascend310_infer/src/utils.cc @@ -64,6 +64,8 @@ std::vector GetImagesById(const std::string &idFile, const std::str int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -74,7 +76,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc b/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc index 7a38c2bd663..14ca0ac60d2 100644 --- a/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/deeptext/ascend310_infer/src/main.cc @@ -130,7 +130,11 @@ int main(int argc, char **argv) { startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTime_ms, endTime_ms)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int infer_cnt = 0; diff --git a/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc b/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc index 4557e1c3455..626924cc050 100644 --- a/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/deeptext/ascend310_infer/src/utils.cc @@ -46,6 +46,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput = outputs[i].Data(); @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE *outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/densenet/ascend310_infer/src/main.cc b/model_zoo/official/cv/densenet/ascend310_infer/src/main.cc index 484f1a26f03..2734d5c07bf 100644 --- a/model_zoo/official/cv/densenet/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/densenet/ascend310_infer/src/main.cc @@ -139,7 +139,11 @@ int main(int argc, char **argv) { startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTime_ms, endTime_ms)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int infer_cnt = 0; diff --git a/model_zoo/official/cv/densenet/ascend310_infer/src/utils.cc b/model_zoo/official/cv/densenet/ascend310_infer/src/utils.cc index d231193e799..344fc329fb1 100644 --- a/model_zoo/official/cv/densenet/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/densenet/ascend310_infer/src/utils.cc @@ -63,6 +63,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -73,7 +75,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/cv/dpn/ascend310_infer/src/main.cc b/model_zoo/official/cv/dpn/ascend310_infer/src/main.cc index d92a9b0cc57..31fea6c4346 100644 --- a/model_zoo/official/cv/dpn/ascend310_infer/src/main.cc +++ b/model_zoo/official/cv/dpn/ascend310_infer/src/main.cc @@ -120,7 +120,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } } else { auto input0_files = GetAllInputData(FLAGS_input0_path); @@ -155,9 +159,13 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i][j], outputs); + int rst = WriteResult(input0_files[i][j], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; } } + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/cv/dpn/ascend310_infer/src/utils.cc b/model_zoo/official/cv/dpn/ascend310_infer/src/utils.cc index d71f388b83d..2c11078eaaa 100644 --- a/model_zoo/official/cv/dpn/ascend310_infer/src/utils.cc +++ b/model_zoo/official/cv/dpn/ascend310_infer/src/utils.cc @@ -22,7 +22,6 @@ using mindspore::MSTensor; using mindspore::DataType; - std::vector> GetAllInputData(std::string dir_name) { std::vector> ret; @@ -102,6 +101,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -112,7 +113,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE *outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/gnn/bgcf/ascend310_infer/src/main.cc b/model_zoo/official/gnn/bgcf/ascend310_infer/src/main.cc index 94296af69cf..4313966029c 100644 --- a/model_zoo/official/gnn/bgcf/ascend310_infer/src/main.cc +++ b/model_zoo/official/gnn/bgcf/ascend310_infer/src/main.cc @@ -136,7 +136,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/gnn/bgcf/ascend310_infer/src/utils.cc b/model_zoo/official/gnn/bgcf/ascend310_infer/src/utils.cc index c947e4d5f45..e9b90b78b5a 100644 --- a/model_zoo/official/gnn/bgcf/ascend310_infer/src/utils.cc +++ b/model_zoo/official/gnn/bgcf/ascend310_infer/src/utils.cc @@ -45,6 +45,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/nlp/bert/ascend310_infer/src/main.cc b/model_zoo/official/nlp/bert/ascend310_infer/src/main.cc index 2fe114ddaa4..595379e0b86 100644 --- a/model_zoo/official/nlp/bert/ascend310_infer/src/main.cc +++ b/model_zoo/official/nlp/bert/ascend310_infer/src/main.cc @@ -124,7 +124,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/nlp/bert/ascend310_infer/src/utils.cc b/model_zoo/official/nlp/bert/ascend310_infer/src/utils.cc index c947e4d5f45..e9b90b78b5a 100644 --- a/model_zoo/official/nlp/bert/ascend310_infer/src/utils.cc +++ b/model_zoo/official/nlp/bert/ascend310_infer/src/utils.cc @@ -45,6 +45,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/official/recommend/deepfm/ascend310_infer/src/main.cc b/model_zoo/official/recommend/deepfm/ascend310_infer/src/main.cc index 3879ed4d9b9..2475cbb1a8c 100644 --- a/model_zoo/official/recommend/deepfm/ascend310_infer/src/main.cc +++ b/model_zoo/official/recommend/deepfm/ascend310_infer/src/main.cc @@ -116,7 +116,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/official/recommend/deepfm/ascend310_infer/src/utils.cc b/model_zoo/official/recommend/deepfm/ascend310_infer/src/utils.cc index c947e4d5f45..e9b90b78b5a 100644 --- a/model_zoo/official/recommend/deepfm/ascend310_infer/src/utils.cc +++ b/model_zoo/official/recommend/deepfm/ascend310_infer/src/utils.cc @@ -45,6 +45,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/research/cv/advanced_east/ascend310_infer/src/main.cc b/model_zoo/research/cv/advanced_east/ascend310_infer/src/main.cc index cd9767a77e3..13509612bef 100644 --- a/model_zoo/research/cv/advanced_east/ascend310_infer/src/main.cc +++ b/model_zoo/research/cv/advanced_east/ascend310_infer/src/main.cc @@ -120,7 +120,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(all_files[i], outputs); + int rst = WriteResult(all_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/research/cv/advanced_east/ascend310_infer/src/utils.cc b/model_zoo/research/cv/advanced_east/ascend310_infer/src/utils.cc index 27dfa015021..a0bb08abf00 100644 --- a/model_zoo/research/cv/advanced_east/ascend310_infer/src/utils.cc +++ b/model_zoo/research/cv/advanced_east/ascend310_infer/src/utils.cc @@ -22,7 +22,6 @@ using mindspore::MSTensor; using mindspore::DataType; - std::vector> GetAllInputData(std::string dir_name) { std::vector> ret; @@ -102,6 +101,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -112,7 +113,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName = fileName + '_' + std::to_string(i) + ".bin"; std::string outFileName = homePath + "/" + fileName; FILE *outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; } diff --git a/model_zoo/research/recommend/autodis/ascend310_infer/src/main.cc b/model_zoo/research/recommend/autodis/ascend310_infer/src/main.cc index ca105f8aab1..9cc207f3247 100644 --- a/model_zoo/research/recommend/autodis/ascend310_infer/src/main.cc +++ b/model_zoo/research/recommend/autodis/ascend310_infer/src/main.cc @@ -118,7 +118,11 @@ int main(int argc, char **argv) { startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; costTime_map.insert(std::pair(startTimeMs, endTimeMs)); - WriteResult(input0_files[i], outputs); + int rst = WriteResult(input0_files[i], outputs); + if (rst != 0) { + std::cout << "write result failed." << std::endl; + return rst; + } } double average = 0.0; int inferCount = 0; diff --git a/model_zoo/research/recommend/autodis/ascend310_infer/src/utils.cc b/model_zoo/research/recommend/autodis/ascend310_infer/src/utils.cc index c947e4d5f45..e9b90b78b5a 100644 --- a/model_zoo/research/recommend/autodis/ascend310_infer/src/utils.cc +++ b/model_zoo/research/recommend/autodis/ascend310_infer/src/utils.cc @@ -45,6 +45,8 @@ std::vector GetAllFiles(std::string_view dirName) { int WriteResult(const std::string& imageFile, const std::vector &outputs) { std::string homePath = "./result_Files"; + int INVALID_POINTER = -1; + int ERROR = -2; for (size_t i = 0; i < outputs.size(); ++i) { size_t outputSize; std::shared_ptr netOutput; @@ -55,7 +57,18 @@ int WriteResult(const std::string& imageFile, const std::vector &outpu fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); std::string outFileName = homePath + "/" + fileName; FILE * outputFile = fopen(outFileName.c_str(), "wb"); - fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); + if (outputFile == nullptr) { + std::cout << "open result file " << outFileName << " failed" << std::endl; + return INVALID_POINTER; + } + size_t size = fwrite(netOutput.get(), sizeof(char), outputSize, outputFile); + if (size != outputSize) { + fclose(outputFile); + outputFile = nullptr; + std::cout << "write result file " << outFileName << " failed, write size[" << size << + "] is smaller than output size[" << outputSize << "], maybe the disk is full." << std::endl; + return ERROR; + } fclose(outputFile); outputFile = nullptr; }