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

Commit

Permalink
[MXNET-857] Use macro for NVTX specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
KellenSunderland committed Aug 24, 2018
1 parent 18cbea2 commit 60a5e52
Showing 1 changed file with 18 additions and 40 deletions.
58 changes: 18 additions & 40 deletions src/profiler/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ class Profiler {
#define VTUNE_ONLY_CODE(...) /* */ /* This is undefined at the bottom of this file */
#endif

#ifdef MXNET_USE_NVTX
#define NVTX_ONLY_CODE(...) __VA_ARGS__ /* This is undefined at the bottom of this file */
#else
#define NVTX_ONLY_CODE(...) /* */ /* This is undefined at the bottom of this file */
#endif

/**
* _____ __ _ _ _ ____ _ _ _
* | __ \ / _|(_)| |(_) / __ \| | (_) | |
Expand Down Expand Up @@ -772,10 +778,7 @@ struct ProfileTask : public ProfileDuration {
categories_.set(domain_->name());
categories_.append(",task");
VTUNE_ONLY_CODE(vtune_task_.reset(new vtune::VTuneTask(name, domain->dom())));

#if MXNET_USE_NVTX
nvtx_duration_.reset(new nvtx::NVTXDuration(name));
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(nvtx_duration_.reset(new nvtx::NVTXDuration(name)));
}

/*!
Expand All @@ -784,23 +787,16 @@ struct ProfileTask : public ProfileDuration {
void start() override {
start_time_ = ProfileStat::NowInMicrosec();
VTUNE_ONLY_CODE(vtune_task_->start());

#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
nvtx_duration_->start();
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(nvtx_duration_->start());
}

/*!
* \brief Stop the profiling scope
*/
void stop() override {
VTUNE_ONLY_CODE(vtune_task_->stop());
NVTX_ONLY_CODE(nvtx_duration_->stop());
SendStat();

#if MXNET_USE_NVTX
nvtx_duration_->stop();
#endif // MXNET_USE_NVTX
}

ProfileObjectType type() const override { return kTask; }
Expand Down Expand Up @@ -839,10 +835,8 @@ struct ProfileTask : public ProfileDuration {
ProfileDomain *domain_;
/*! \brief VTune task object */
VTUNE_ONLY_CODE(std::unique_ptr<vtune::VTuneTask> vtune_task_);
#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_;
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_);

protected:
/*! \brief Task's start tick */
Expand All @@ -861,9 +855,7 @@ struct ProfileEvent : public ProfileDuration {
: name_(name)
, categories_("event") {
VTUNE_ONLY_CODE(vtune_event_ = vtune::VTuneEvent::registry_.get(name));
#if MXNET_USE_NVTX
nvtx_duration_.reset(new nvtx::NVTXDuration(name));
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(nvtx_duration_.reset(new nvtx::NVTXDuration(name)));
}

/*!
Expand All @@ -872,10 +864,7 @@ struct ProfileEvent : public ProfileDuration {
void start() override {
start_time_ = ProfileStat::NowInMicrosec();
VTUNE_ONLY_CODE(vtune_event_->start());
#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
nvtx_duration_->start();
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(nvtx_duration_->start());
}

/*!
Expand Down Expand Up @@ -924,10 +913,8 @@ struct ProfileEvent : public ProfileDuration {
profile_stat_string categories_;
/*! \brief VTune event object */
VTUNE_ONLY_CODE(vtune::VTuneEvent *vtune_event_);
#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_;
#endif // MXNET_USE_NVTX
/*! \brief NVTX duration object */
NVTX_ONLY_CODE(std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_;);

protected:
/*! \brief Start time of the event */
Expand All @@ -949,11 +936,7 @@ struct ProfileFrame : public ProfileDuration {
CHECK_NOTNULL(domain);
categories_.set(domain_->name());
categories_.append(",frame");

#if MXNET_USE_NVTX
nvtx_duration_.reset(new nvtx::NVTXDuration(name));
#endif // MXNET_USE_NVTX

NVTX_ONLY_CODE(nvtx_duration_.reset(new nvtx::NVTXDuration(name)));
VTUNE_ONLY_CODE(vtune_frame_.reset(new vtune::VTuneFrame(domain->dom())));
}

Expand All @@ -963,10 +946,7 @@ struct ProfileFrame : public ProfileDuration {
void start() override {
start_time_ = ProfileStat::NowInMicrosec();
VTUNE_ONLY_CODE(vtune_frame_->start());
#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
nvtx_duration_->start();
#endif // MXNET_USE_NVTX
NVTX_ONLY_CODE(nvtx_duration_->start());
}

/*!
Expand Down Expand Up @@ -1009,10 +989,8 @@ struct ProfileFrame : public ProfileDuration {
ProfileDomain *domain_;
/*! \brief VTune Frame object */
VTUNE_ONLY_CODE(std::unique_ptr<vtune::VTuneFrame> vtune_frame_);
#if MXNET_USE_NVTX
/*! \brief NVTX duration object */
std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_;
#endif // MXNET_USE_NVTX
/*! \brief NVTX duration object */
NVTX_ONLY_CODE(std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_);

protected:
/*! \brief Frame start time */
Expand Down

0 comments on commit 60a5e52

Please sign in to comment.