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

Basic PR on Cost Model #35774

Merged
merged 14 commits into from
Sep 18, 2021
Merged

Conversation

zhhsplendid
Copy link
Member

@zhhsplendid zhhsplendid commented Sep 15, 2021

PR types

New features

PR changes

APIs

Describe

Add basic Cost Model, it uses executor to run program and profile it to get op time.

This is an early basic version, we will add more functions in the future.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

EnableProfiler(profiler_state);
executor.Run(main_program, &scope, /*block_id = */ 0);

std::vector<std::vector<Event>>* time_events =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best idea is using unique_ptr or shared_ptr rather than raw pointer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to me, change done.

}
++event_index;
}
if (start_profiler_idx != 0 && stop_profiler_idx != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start_profiler_idx != 0? Why can not main_thread_events[0].name() == "_start_profiler_", I think it is possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a little background, profiler would have some initialize events which aren't "start_profiler", but to support the start_profiler_idx == 0 case, I changed the related code. I compare it with -1;

ProgramDesc program = CreateTestProgram();
ProgramDesc empty_program;
CostData cost_data =
cost_model.ProfileMeasure(program, empty_program, "cpu", {"time"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find "gpu" version test, should add it for coverage CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see it on python test ^_^

}
int count = 0;
while (count <= 1000) {
++count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this useless loop necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary to occupy test time

++event_index;
}
if (start_profiler_idx != -1 && stop_profiler_idx != -1) {
double cpu_time_ms = main_thread_events[start_profiler_idx].CpuElapsedMs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add PADDLE_ENFORCE_GE(start_profiler_idx, 0) and PADDLE_ENFORCE_GT(stop_profiler_idx, start_profiler_idx) here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not good now, because we are not sure about profiler

// here.
}

double CostData::GetOpTimeMs(int op_id) const { return op_time_ms_.at(op_id); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to use size_t replace int because the global_block.OpSize() return size_t.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little background, we would also support graph in the future, then there will be int node id. We are not sure whether there is negative graph id

Copy link
Contributor

@thisjiang thisjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhhsplendid zhhsplendid changed the title Experimental PR on Cost Model Basic PR on Cost Model Sep 18, 2021
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhhsplendid zhhsplendid merged commit 5ba9fe6 into PaddlePaddle:develop Sep 18, 2021
zhhsplendid added a commit to zhhsplendid/Paddle that referenced this pull request Sep 22, 2021
Add basic Cost Model, it uses executor to run program and profile it to get op time.

This is an early basic version, we will add more functions in the future.
lanxianghit pushed a commit that referenced this pull request Sep 24, 2021
Add basic Cost Model, it uses executor to run program and profile it to get op time.

This is an early basic version, we will add more functions in the future.
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 29, 2021
Add basic Cost Model, it uses executor to run program and profile it to get op time.

This is an early basic version, we will add more functions in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants