Skip to content

Commit

Permalink
More optimizations (LLNL#484)
Browse files Browse the repository at this point in the history
* Remove unused post_end and post_set callbacks

* Use RegionFilter in AnnotationBinding

* Make filter conditional in AnnotationBinding.cpp

* Remove scope flag for snapshots

* Simplify attribute check

* Don't require c++14

* Fix compilation w/ Lassen XL compilers
  • Loading branch information
daboehme authored May 18, 2023
1 parent 64c5fa8 commit 7ffe041
Show file tree
Hide file tree
Showing 37 changed files with 183 additions and 535 deletions.
27 changes: 13 additions & 14 deletions include/caliper/AnnotationBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#include "caliper/common/RuntimeConfig.h"

#include <iostream>
#include <memory>
#include <vector>

namespace cali
namespace cali
{

class Filter;
class RegionFilter;
class Node;

/// \brief Base class for bindings to third-party annotation APIs
Expand All @@ -46,15 +47,15 @@ class Node;
/// class MyBinding : public cali::AnnotationBinding {
/// public:
///
/// const char* service_tag() const {
/// return "mybinding";
/// const char* service_tag() const {
/// return "mybinding";
/// }
///
/// void on_begin(cali::Caliper* c, cali::Channel*, const cali::Attribute& attr, const cali::Variant& value) {
/// std::string str = attr.name();
/// str.append("=");
/// str.append(value.to_string()); // create "<attribute name>=<value>" string
///
///
/// mybegin(str.c_str());
/// }
///
Expand All @@ -69,12 +70,13 @@ class Node;
/// Also see the \a nvprof and \a vtune service implementations for examples of
/// using AnnotationBinding in a %Caliper service.

class AnnotationBinding
class AnnotationBinding
{
ConfigSet m_config;
Filter* m_filter;
Attribute m_marker_attr;

std::unique_ptr<RegionFilter> m_filter;

std::vector<std::string> m_trigger_attr_names;

static const ConfigSet::Entry s_configdata[];
Expand All @@ -88,7 +90,7 @@ class AnnotationBinding
/// These callbacks are internal Caliper mechanisms
/// not meant to be touched by the code of services
/// implementing an AnnotationBinding.
///
///
/// User code should instead use on_mark_attribute(),
/// on_begin(), and on_end().

Expand All @@ -115,13 +117,13 @@ class AnnotationBinding
/// \brief Callback for an annotation begin event
/// \param c Caliper instance
/// \param attr Attribute on which the %Caliper begin event was invoked.
/// \param value The annotation name/value.
/// \param value The annotation name/value.
virtual void on_begin(Caliper* c, Channel* chn, const Attribute& attr, const Variant& value) { }

/// \brief Callback for an annotation end event
/// \param c Caliper instance
/// \param attr Attribute on which the %Caliper end event was invoked.
/// \param value The annotation name/value.
/// \param value The annotation name/value.
virtual void on_end(Caliper* c, Channel* chn, const Attribute& attr, const Variant& value) { }

/// \brief Initialization callback. Invoked after the %Caliper
Expand All @@ -134,10 +136,7 @@ class AnnotationBinding
public:

/// \brief Constructor. Usually invoked through \a make_binding().
AnnotationBinding()
: m_filter(nullptr),
m_marker_attr(Attribute::invalid)
{ }
AnnotationBinding();

virtual ~AnnotationBinding();

Expand Down
19 changes: 3 additions & 16 deletions include/caliper/Caliper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Channel
typedef util::callback<void(Caliper*,Channel*)>
caliper_cbvec;

typedef util::callback<void(Caliper*,Channel*,int,SnapshotView,SnapshotBuilder&)>
typedef util::callback<void(Caliper*,Channel*,SnapshotView,SnapshotBuilder&)>
snapshot_cbvec;
typedef util::callback<void(Caliper*,Channel*,SnapshotView,SnapshotView)>
process_snapshot_cbvec;
Expand All @@ -87,12 +87,8 @@ class Channel
update_cbvec post_begin_evt;
/// \brief Invoked when value is set, \e before it has been put on the blackboard.
update_cbvec pre_set_evt;
/// \brief Invoked when value is set, \e after it has been put on the blackboard.
update_cbvec post_set_evt;
/// \brief Invoked on region end, \e before it has been removed from the blackboard.
update_cbvec pre_end_evt;
/// \brief Invoked on region end, \e after it has been removed from the blackboard.
update_cbvec post_end_evt;

/// \brief Invoked when a new thread context is being created.
caliper_cbvec create_thread_evt;
Expand Down Expand Up @@ -335,14 +331,8 @@ class Caliper : public CaliperMetadataAccessInterface
///
/// This function is signal safe.
///
/// \param channel The %Caliper channel to fetch the context from.
/// \param scopes Defines which blackboard contents (thread, process,
/// channel) are returned. Bitwise combination of cali_context_scope_t
/// flags.
/// \param trigger_info A caller-provided record that is passed to the
/// snapshot callback, and added to the returned snapshot record.
/// \param rec The snapshot record buffer to update.
void pull_context(Channel* channel, int scopes, SnapshotBuilder& rec);
void pull_context(SnapshotBuilder& rec);

/// \brief Trigger and return a snapshot.
///
Expand All @@ -362,13 +352,10 @@ class Caliper : public CaliperMetadataAccessInterface
/// This function is signal safe.
///
/// \param channel The %Caliper channel to fetch the snapshot from.
/// \param scopes Defines which blackboard contents (thread, process,
/// channel) are returned. Bitwise combination of cali_context_scope_t
/// flags.
/// \param trigger_info A caller-provided record that is passed to the
/// snapshot callback, and added to the returned snapshot record.
/// \param rec The snapshot record buffer to update.
void pull_snapshot(Channel* channel, int scopes, SnapshotView trigger_info, SnapshotBuilder& rec);
void pull_snapshot(Channel* channel, SnapshotView trigger_info, SnapshotBuilder& rec);

// --- Flush and I/O API

Expand Down
6 changes: 3 additions & 3 deletions include/caliper/cali.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ cali_attribute_properties(cali_id_t attr_id);
* probably use a dedicated channel to do so.
*
* \param scope Indicates which scopes (process, thread, or task) the
* snapshot should span
* snapshot should span (deprecated, unused)
* \param n Number of event info entries
* \param trigger_info_attr_list Attribute IDs of event info entries
* \param trigger_info_val_list Values of event info entries
Expand All @@ -164,7 +164,7 @@ cali_push_snapshot(int scope, int n,
*
* \param chn_id Channel to take snapshot on
* \param scope Indicates which scopes (process, thread, or task) the
* snapshot should span
* snapshot should span (deprecated, unused)
* \param n Number of event info entries
* \param trigger_info_attr_list Attribute IDs of event info entries
* \param trigger_info_val_list Values of event info entries
Expand All @@ -191,7 +191,7 @@ cali_channel_push_snapshot(cali_id_t chn_id,
*
* \param chn_id Channel to take the snapshot on
* \param scope Indicates which scopes (process, thread, or task) the
* snapshot should span
* snapshot should span (deprecated)
* \param len Length of the provided snapshot buffer.
* \param buf User-provided snapshot storage buffer.
* \return Actual size of the snapshot representation.
Expand Down
15 changes: 0 additions & 15 deletions include/caliper/common/filters/DefaultFilter.h

This file was deleted.

19 changes: 0 additions & 19 deletions include/caliper/common/filters/Filter.h

This file was deleted.

41 changes: 0 additions & 41 deletions include/caliper/common/filters/RegexFilter.h

This file was deleted.

27 changes: 14 additions & 13 deletions src/caliper/Annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Loop::end()
// --- Annotation implementation object

struct Annotation::Impl {
std::atomic<Attribute> m_attr;
std::atomic<cali::Node*> m_attr_node;

std::string m_name;
std::vector<Attribute> m_metadata_keys;
Expand All @@ -130,26 +130,26 @@ struct Annotation::Impl {
std::atomic<int> m_refcount;

Impl(const std::string& name, MetadataListType metadata, int opt)
: m_attr(Attribute::invalid),
: m_attr_node(nullptr),
m_name(name),
m_opt(opt),
m_refcount(1)
{
Caliper c;
Attribute attr = c.get_attribute(name);

if (attr == Attribute::invalid) {
if (!attr) {
for(auto kv : metadata) {
m_metadata_keys.push_back(c.create_attribute(kv.first,kv.second.type(),0));
m_metadata_values.push_back(kv.second);
}
} else {
m_attr.store(attr);
m_attr_node.store(attr.node());
}
}

Impl(const std::string& name, int opt)
: m_attr(Attribute::invalid),
: m_attr_node(nullptr),
m_name(name),
m_opt(opt),
m_refcount(1)
Expand All @@ -176,26 +176,27 @@ struct Annotation::Impl {

void end() {
Caliper c;
Attribute attr = m_attr.load();
Attribute attr = Attribute::make_attribute(m_attr_node.load());

if (attr)
c.end(attr);
}

Attribute get_attribute(Caliper& c, cali_attr_type type) {
Attribute attr = m_attr.load();
cali::Node* attr_node = m_attr_node.load();

if (!attr) {
attr =
if (!attr_node) {
Attribute attr =
c.create_attribute(m_name, type, m_opt,
m_metadata_keys.size(),
m_metadata_keys.data(),
m_metadata_values.data());

m_attr.store(attr);
attr_node = attr.node();
m_attr_node.store(attr_node);
}

return attr;
return Attribute::make_attribute(attr_node);
}

Impl* attach() {
Expand Down Expand Up @@ -263,7 +264,7 @@ Annotation& Annotation::begin()

Annotation& Annotation::begin(int data)
{
Attribute attr = pI->m_attr.load();
Attribute attr = Attribute::make_attribute(pI->m_attr_node.load());

// special case: allow assignment of int values to 'double' or 'uint' attributes
if (attr && attr.type() == CALI_TYPE_DOUBLE)
Expand All @@ -289,7 +290,7 @@ Annotation& Annotation::begin(const Variant& data)

Annotation& Annotation::set(int data)
{
Attribute attr = pI->m_attr.load();
Attribute attr = Attribute::make_attribute(pI->m_attr_node.load());

// special case: allow assignment of int values to 'double' or 'uint' attributes
if (attr && attr.type() == CALI_TYPE_DOUBLE)
Expand Down
Loading

0 comments on commit 7ffe041

Please sign in to comment.