Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

C++ demo memory release problem #7973

Closed
junxigauss opened this issue Sep 21, 2017 · 25 comments
Closed

C++ demo memory release problem #7973

junxigauss opened this issue Sep 21, 2017 · 25 comments

Comments

@junxigauss
Copy link

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.

  1. run image-classification-predict.cc
    2.MXPredFree(pred_hnd) don't release memory in GPU or CPU mode
@kimivital
Copy link

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

@piiswrong
Copy link
Contributor

@lx75249

@conopt
Copy link
Contributor

conopt commented Sep 21, 2017

@piiswrong This is the raw API demo.. not the demo in c++ package.

@junxigauss
Copy link
Author

@lx75249 MXNotifyShutdown() can't resolve it yet

@junxigauss
Copy link
Author

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();
}

@kimivital
Copy link

Win10 is ok.

@junxigauss
Copy link
Author

what interface you call?@kimivital

@kimivital
Copy link

I run the example file(image-classification-predict.cc) with other model.

@junxigauss
Copy link
Author

I run it on win10, memory leak in GPU or CPU mode.

@szha
Copy link
Member

szha commented Dec 26, 2017

@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.

@sojiadeshina
Copy link
Contributor

@junxigauss is this still an issue on mxnet v1.2?

@Kolkir
Copy link

Kolkir commented Aug 5, 2018

I' got the same issue on Arch Linux in master branch, but calling MXNotifyShutdown resolve it.

@junxigauss
Copy link
Author

I solve it, by modify nnvm cpu gpu memory manager coder.

@sandeep-krishnamurthy
Copy link
Contributor

@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?

@zhreshold
Copy link
Member

@junxigauss Can you elaborate what have you done to solve it?

@leleamol
Copy link
Contributor

leleamol commented Nov 9, 2018

@mxnet-label-bot add [Pending Requester Info]

@vrakesh
Copy link
Contributor

vrakesh commented Nov 26, 2018

@junxigauss Requesting an explanation on the solution, it would help all users , if they run across a similar issue.

@vdantu
Copy link
Contributor

vdantu commented Dec 15, 2018

@junxigauss : Would you be able to share the solution? As mentioned above, this could be very useful for others as well.

@vdantu
Copy link
Contributor

vdantu commented Dec 15, 2018

@leleamol : Would this still be an issue?

@leleamol
Copy link
Contributor

leleamol commented Jan 4, 2019

This issue is not related to C++ Front End API. Removing the C++ Label.

@leleamol
Copy link
Contributor

leleamol commented Jan 4, 2019

@mxnet-label-bot remove [C++]

@marcoabreu marcoabreu removed the C++ Related to C++ label Jan 4, 2019
@leleamol
Copy link
Contributor

leleamol commented Jan 4, 2019

@mxnet-label-bot add [C API]

@ThomasDelteil
Copy link
Contributor

@leleamol is it still an issue?

@leleamol
Copy link
Contributor

leleamol commented May 8, 2019

This doesn't seem to an issue anymore. I would recommend closing this issue.
@lanking520

@lanking520
Copy link
Member

@junxigauss Please feel free to reopen this issue if problem persist. Close it for now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests