|
|
@ -11,8 +11,8 @@
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
#include "paddle/fluid/framework/details/op_handle_base.h"
|
|
|
|
#include "paddle/fluid/framework/details/op_handle_base.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
namespace paddle {
|
|
|
|
namespace framework {
|
|
|
|
namespace framework {
|
|
|
@ -122,35 +122,17 @@ void OpHandleBase::RunAndRecordEvent(const std::function<void()> &callback) {
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
if (!events_.empty()) { // Use event
|
|
|
|
if (!events_.empty()) { // Use event
|
|
|
|
std::function<void()> method = callback;
|
|
|
|
std::function<void()> method = callback;
|
|
|
|
|
|
|
|
// NOTE(zcd): device context must be ordered here because RecordEvent
|
|
|
|
|
|
|
|
// will use a mutex to ensure the safe of multi-threads.
|
|
|
|
|
|
|
|
std::map<platform::DeviceContext *, platform::Place> ordered_ctxes;
|
|
|
|
for (auto &p : dev_ctxes_) {
|
|
|
|
for (auto &p : dev_ctxes_) {
|
|
|
|
method = [method, p, this]() {
|
|
|
|
ordered_ctxes.emplace(p.second, p.first);
|
|
|
|
static_cast<platform::CUDADeviceContext *>(p.second)->RecordEvent(
|
|
|
|
|
|
|
|
events_.at(boost::get<platform::CUDAPlace>(p.first).device),
|
|
|
|
|
|
|
|
method);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
method();
|
|
|
|
for (auto &p : ordered_ctxes) {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OpHandleBase::RunAndRecordEventNoMutex(
|
|
|
|
|
|
|
|
const std::function<void()> &callback) {
|
|
|
|
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
if (!events_.empty()) { // Use event
|
|
|
|
|
|
|
|
std::function<void()> method = callback;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto &p : dev_ctxes_) {
|
|
|
|
|
|
|
|
method = [method, p, this]() {
|
|
|
|
method = [method, p, this]() {
|
|
|
|
static_cast<platform::CUDADeviceContext *>(p.second)
|
|
|
|
static_cast<platform::CUDADeviceContext *>(p.first)->RecordEvent(
|
|
|
|
->RecordEventNoMutex(
|
|
|
|
events_.at(boost::get<platform::CUDAPlace>(p.second).device),
|
|
|
|
events_.at(boost::get<platform::CUDAPlace>(p.first).device),
|
|
|
|
method);
|
|
|
|
method);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
method();
|
|
|
|
method();
|
|
|
|