Caffe2 - C++ API
A deep learning, cross platform ML framework
run_plan_mpi.cc
1 
17 #include <mpi.h>
18 
19 #include "c10/util/Flags.h"
20 #include "caffe2/core/init.h"
21 #include "caffe2/core/logging.h"
22 #include "caffe2/core/operator.h"
23 #include "caffe2/proto/caffe2_pb.h"
24 #include "caffe2/utils/proto_utils.h"
25 
26 C10_DEFINE_string(plan, "", "The given path to the plan protobuffer.");
27 
28 int main(int argc, char** argv) {
29  c10::SetUsageMessage("Runs a caffe2 plan that has MPI operators in it.");
30  int mpi_ret;
31  MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &mpi_ret);
32  if (mpi_ret != MPI_THREAD_MULTIPLE &&
33  mpi_ret != MPI_THREAD_SERIALIZED) {
34  std::cerr << "Caffe2 MPI requires the underlying MPI to support the "
35  "MPI_THREAD_SERIALIZED or MPI_THREAD_MULTIPLE mode.\n";
36  return 1;
37  }
38  caffe2::GlobalInit(&argc, &argv);
39  LOG(INFO) << "Loading plan: " << FLAGS_plan;
40  caffe2::PlanDef plan_def;
41  CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_plan, &plan_def));
42  std::unique_ptr<caffe2::Workspace> workspace(new caffe2::Workspace());
43  workspace->RunPlan(plan_def);
44 
45  // This is to allow us to use memory leak checks.
46  caffe2::ShutdownProtobufLibrary();
47  MPI_Finalize();
48  return 0;
49 }
C10_API void SetUsageMessage(const std::string &str)
Sets the usage message when a commandline tool is called with "--help".
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:44