C++ demo memory release problem
For bugs or installation issues, please provide the following information. The more information you provide, the more likely people will be able to help you.
Environment info
Operating System: windows
Compiler:VS2015
MXNet version:0.9.5
Steps to reproduce
or if you are running standard examples, please provide the commands you have run that lead to the error.
- run image-classification-predict.cc 2.MXPredFree(pred_hnd) don't release memory in GPU or CPU mode
same problem, exe can't exit normally and cpu gpu memory didn't release.
Operating System: Windows 7 x64 Compiler: VS2015 MXNET version: 0.10.0 and 0.11.0
@lx75249
@piiswrong This is the raw API demo.. not the demo in c++ package.
@lx75249 MXNotifyShutdown() can't resolve it yet
I create a std::thread to run the demo, the memory release a big part, but left a small part before exit exe but thread end. I try the release function MXNotifyShutdown(), MXPredFree(pred_hnd) both, absolutely didn't work. I believe it was a bug. code as follow:
int f() {
std::string test_file = "G:/标识牌-9~17.jpg";
//test_file = std::string(argv[1]);
// Models path for your model, you have to modify it
std::string json_file = "VGG_VOC0712Plus_SSD_512x_16w.json";
std::string param_file = "VGG_VOC0712Plus_SSD_512x_16w.params";
std::string synset_file = "model/Inception/synset.txt";
std::string nd_file = "model/Inception/mean_224.nd";
BufferFile json_data(json_file);
BufferFile param_data(param_file);
//system("pause");
// Parameters
int dev_type = 2; // 1: cpu, 2: gpu
int dev_id = 0; // arbitrary.
mx_uint num_input_nodes = 1; // 1 for feedforward
const char* input_key[1] = { "data" };
const char** input_keys = input_key;
// Image size and channels
int width = 512;
int height = 512;
int channels = 3;
const mx_uint input_shape_indptr[2] = { 0, 4 };
const mx_uint input_shape_data[4] = { 1,
static_cast<mx_uint>(channels),
static_cast<mx_uint>(height),
static_cast<mx_uint>(width) };
PredictorHandle pred_hnd = 0;
if (json_data.GetLength() == 0 ||
param_data.GetLength() == 0) {
return -1;
}
// Create Predictor
MXPredCreate((const char*)json_data.GetBuffer(),
(const char*)param_data.GetBuffer(),
static_cast<size_t>(param_data.GetLength()),
dev_type,
dev_id,
num_input_nodes,
input_keys,
input_shape_indptr,
input_shape_data,
&pred_hnd);
assert(pred_hnd);
int image_size = width * height * channels;
// Read Mean Data
const mx_float* nd_data = NULL;
NDListHandle nd_hnd = 0;
BufferFile nd_buf(nd_file);
if (nd_buf.GetLength() > 0) {
mx_uint nd_index = 0;
mx_uint nd_len;
const mx_uint* nd_shape = 0;
const char* nd_key = 0;
mx_uint nd_ndim = 0;
MXNDListCreate((const char*)nd_buf.GetBuffer(),
nd_buf.GetLength(),
&nd_hnd, &nd_len);
MXNDListGet(nd_hnd, nd_index, &nd_key, &nd_data, &nd_shape, &nd_ndim);
}
// Read Image Data
std::vector<mx_float> image_data = std::vector<mx_float>(image_size);
GetImageFile(test_file, image_data.data(),
channels, cv::Size(width, height), nd_data);
// Set Input Image
MXPredSetInput(pred_hnd, "data", image_data.data(), image_size);
// Do Predict Forward
MXPredForward(pred_hnd);
mx_uint output_index = 0;
mx_uint *shape = 0;
mx_uint shape_len;
// Get Output Result
MXPredGetOutputShape(pred_hnd, output_index, &shape, &shape_len);
size_t size = 1;
for (mx_uint i = 0; i < shape_len; ++i) size *= shape[i];
std::vector<float> data(size);
MXPredGetOutput(pred_hnd, output_index, &(data[0]), size);
// Release NDList
if (nd_hnd)
MXNDListFree(nd_hnd);
// Release Predictor
MXPredFree(pred_hnd);
MXNotifyShutdown();
// Synset path for your model, you have to modify it
std::vector<std::string> synset = LoadSynset(synset_file);
// Print Output Data
//PrintOutputResult(data, synset);
return 0;
}
#include
int main(int argc, char* argv[]) { std::thread t1(f); t1.detach(); //f(); }
Win10 is ok.
what interface you call?@kimivital
I run the example file(image-classification-predict.cc) with other model.
I run it on win10, memory leak in GPU or CPU mode.
@apache/mxnet-committers: This issue has been inactive for the past 90 days. It has no label and needs triage.
For general "how-to" questions, our user forum (and Chinese version) is a good place to get help.
@junxigauss is this still an issue on mxnet v1.2?
I' got the same issue on Arch Linux in master branch, but calling MXNotifyShutdown resolve it.
I solve it, by modify nnvm cpu gpu memory manager coder.
@junxigauss - It would be very helpful for all users if you can do a PR for the code change? Or, Can you please provide more details on the fix you made?
@junxigauss Can you elaborate what have you done to solve it?
@mxnet-label-bot add [Pending Requester Info]
@junxigauss Requesting an explanation on the solution, it would help all users , if they run across a similar issue.
@junxigauss : Would you be able to share the solution? As mentioned above, this could be very useful for others as well.
@leleamol : Would this still be an issue?
This issue is not related to C++ Front End API. Removing the C++ Label.