Skip to content

Commit aa80010

Browse files
authored
Build spot and loop-report without MPI (LLNL#394)
* Move create_filename() into utils * Add serial SpotController * Re-add loop-report * Simplify CustomOutputController default flush * Fixes and cleanup * Fix warnings * Test loop-report and spot always * Fix loop-report output option
1 parent 0073bb6 commit aa80010

22 files changed

+618
-379
lines changed

include/caliper/ChannelController.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class ChannelController
4040

4141
protected:
4242

43-
/// \brief Return the underlying %Caliper channel object.
44-
Channel* channel();
45-
4643
/// \brief Provide access to the underlying config map.
4744
///
4845
/// Note that configuration modifications are only effective before
@@ -62,6 +59,9 @@ class ChannelController
6259

6360
public:
6461

62+
/// \brief Return the underlying %Caliper channel object.
63+
Channel* channel();
64+
6565
/// \brief Create and activate the %Caliper channel,
6666
/// or reactivate a stopped %Caliper channel.
6767
void start();

include/caliper/CollectiveOutputChannel.h

+7-16
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#ifndef CALI_COLLECTIVE_CHANNEL_CONTROLLER_H
1010
#define CALI_COLLECTIVE_CHANNEL_CONTROLLER_H
1111

12-
#include "ChannelController.h"
13-
1412
#include <mpi.h>
1513

1614
#include <memory>
1715

1816
namespace cali
1917
{
2018

19+
class ChannelController;
2120
class OutputStream;
2221

2322
/// \class CollectiveOutputChannel
@@ -30,12 +29,15 @@ class OutputStream;
3029
/// communicator and/or C++ I/O stream.
3130
///
3231
/// \sa make_collective_output_channel()
33-
class CollectiveOutputChannel : public cali::ChannelController
32+
class CollectiveOutputChannel
3433
{
3534
public:
3635

37-
/// \brief Create channel controller with given name, flags, and config.
38-
CollectiveOutputChannel(const char* name, int flags, const config_map_t& cfg);
36+
/// \brief Start the underlying channel
37+
virtual void start() = 0;
38+
39+
/// \brief Stop/pause the underlying channel
40+
virtual void stop() = 0;
3941

4042
/// \brief Try to create a CollectiveOutputChannel based on the
4143
/// configuration in \a from.
@@ -78,17 +80,6 @@ class CollectiveOutputChannel : public cali::ChannelController
7880
/// \param comm MPI communicator
7981
virtual void collective_flush(MPI_Comm comm);
8082

81-
/// \brief Aggregate and flush data.
82-
///
83-
/// The default behavior aggregates data across all ranks in the
84-
/// \c MPI_COMM_WORLD communicator and writes it to stdout. This is a
85-
/// collective operation on \c MPI_COMM_WORLD.
86-
///
87-
/// If MPI was never initialized, the calling process will aggregate and
88-
/// write its local data. If MPI was initialized but has been finalized,
89-
/// the function does nothing.
90-
virtual void flush() override;
91-
9283
virtual ~CollectiveOutputChannel();
9384
};
9485

src/caliper/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(CALIPER_RUNTIME_SOURCES
55
Caliper.cpp
66
ChannelController.cpp
77
ConfigManager.cpp
8+
CustomOutputController.cpp
89
MemoryPool.cpp
910
MetadataTree.cpp
1011
RegionProfile.cpp
@@ -30,6 +31,7 @@ list(APPEND CALIPER_SERIAL_OBJS
3031
caliper/setup_serial.cpp)
3132

3233
if (CALIPER_HAVE_MPI)
34+
target_include_directories(caliper-runtime PRIVATE ${MPI_CXX_INCLUDE_PATH})
3335
list(APPEND CALIPER_ALL_OBJS
3436
caliper/machine_mpi.cpp
3537
caliper/setup_mpi.cpp)
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2021, Lawrence Livermore National Security, LLC.
2+
// See top-level LICENSE file for details.
3+
4+
#include "CustomOutputController.h"
5+
6+
#include "caliper/Caliper.h"
7+
8+
#include "caliper/common/Log.h"
9+
#include "caliper/common/OutputStream.h"
10+
11+
using namespace cali;
12+
using namespace cali::internal;
13+
14+
CustomOutputController::FlushFn CustomOutputController::s_flush_fn { nullptr };
15+
16+
void
17+
CustomOutputController::set_flush_fn(FlushFn flush_fn)
18+
{
19+
s_flush_fn = flush_fn;
20+
}
21+
22+
//
23+
// --- CustomOutputController::Comm
24+
//
25+
26+
CustomOutputController::Comm::~Comm()
27+
{
28+
}
29+
30+
int CustomOutputController::Comm::rank() const
31+
{
32+
return 0;
33+
}
34+
35+
int CustomOutputController::Comm::bcast_int(int val) const
36+
{
37+
return val;
38+
}
39+
40+
std::string CustomOutputController::Comm::bcast_str(const std::string& val) const
41+
{
42+
return val;
43+
}
44+
45+
void CustomOutputController::Comm::cross_aggregate(CaliperMetadataDB& db, Aggregator& agg) const
46+
{
47+
// no-op
48+
}
49+
50+
void CustomOutputController::flush()
51+
{
52+
auto chn = channel();
53+
54+
if (!chn)
55+
return;
56+
57+
if (s_flush_fn) {
58+
(*s_flush_fn)(this);
59+
} else {
60+
Log(2).stream() << chn->name()
61+
<< ": CustomOutputController::flush(): using serial flush"
62+
<< std::endl;
63+
64+
Comm comm;
65+
OutputStream stream;
66+
67+
collective_flush(stream, comm);
68+
}
69+
}
70+
71+
CustomOutputController::CustomOutputController(const char* name, int flags, const config_map_t& initial_cfg)
72+
: ChannelController(name, flags, initial_cfg)
73+
{ }

src/caliper/CustomOutputController.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2021, Lawrence Livermore National Security, LLC.
2+
// See top-level LICENSE file for details.
3+
4+
#pragma once
5+
6+
#ifndef CALI_CUSTOM_OUTPUT_CONTROLLER_H
7+
#define CALI_CUSTOM_OUTPUT_CONTROLLER_H
8+
9+
#include "caliper/ChannelController.h"
10+
11+
#include <string>
12+
13+
namespace cali
14+
{
15+
16+
class Aggregator;
17+
class CaliperMetadataDB;
18+
class OutputStream;
19+
20+
namespace internal
21+
{
22+
23+
/// \brief Base class for a channel controller implementing a custom communication
24+
/// scheme.
25+
///
26+
/// Lets us switch communication between serial, MPI, and potentially other
27+
/// communication protocols.
28+
class CustomOutputController : public cali::ChannelController
29+
{
30+
typedef void (*FlushFn)(CustomOutputController*);
31+
static FlushFn s_flush_fn;
32+
33+
public:
34+
35+
/// \brief Set the flush function for MPI (or other) communication
36+
/// protocols.
37+
///
38+
/// This callback lets us specify alternate flush implementations, in
39+
/// particular for MPI. The MPI build sets this in mpi_setup.cpp.
40+
static void set_flush_fn(FlushFn);
41+
42+
/// \brief Base class for the communication protocol. Implements serial
43+
/// (no-op) communication.
44+
class Comm {
45+
public:
46+
47+
virtual ~Comm();
48+
49+
virtual int rank() const;
50+
51+
virtual int bcast_int(int val) const;
52+
virtual std::string bcast_str(const std::string& str) const;
53+
54+
virtual void cross_aggregate(CaliperMetadataDB& db, Aggregator& agg) const;
55+
};
56+
57+
/// \brief Override to implement custom collective flush operation using
58+
/// \a comm and \a stream.
59+
virtual void collective_flush(OutputStream& stream, Comm& comm) = 0;
60+
61+
/// \brief Perform default flush (no user-provided comm or stream)
62+
///
63+
/// Invokes s_flush_fn() if set, which in turn invokes the collective_flush()
64+
/// method overriden by derived classes. The s_flush_fn() specifies the
65+
/// communication protocol, e.g. MPI. The default implementation is serial.
66+
virtual void flush() override;
67+
68+
CustomOutputController(const char* name, int flags, const config_map_t& initial_config);
69+
};
70+
71+
} // namespace internal
72+
73+
} // namespace cali
74+
75+
#endif

src/caliper/controllers/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ set(CALIPER_CONTROLLERS_SOURCES
44
controllers/CudaActivityReportController.cpp
55
controllers/HatchetRegionProfileController.cpp
66
controllers/HatchetSampleProfileController.cpp
7+
controllers/LoopReportController.cpp
78
controllers/OpenMPReportController.cpp
89
controllers/RuntimeReportController.cpp
10+
controllers/SpotController.cpp
911
controllers/controllers.cpp
1012
controllers/util.cpp)
1113

0 commit comments

Comments
 (0)