Skip to content

Contracts: Tool

Clemens-Alexander Brust edited this page Dec 11, 2015 · 1 revision

Tools in the CN24 framework are programs that use CN24 as a library. For example, all of the programs in the tools folder are considered tools. Generally, if your task or problem requires an operation that cannot be performed using any of the included tools, you will have to write your own. Please consider the following paragraphs when writing a tool using CN24.

Initialization

CN24 has a small amount of global state, specifically for OpenCL, logging and statistics purposes. To initialize CN24, call System::Init:

Conv::System::Init();

Statistics

Using the new StatAggregator feature, components may register their exported statistics. It is the tool's responsibility to register StatSinks and notify StatAggregator that registrations are complete:

// Create a simple ConsoleStatSink
Conv::ConsoleStatSink console_stat_sink;

// Register the sink
Conv:System::stat_aggregator->RegisterSink(&console_stat_sink);

// ...
// Notify StatAggregator
Conv::System::stat_aggregator->Initialize();

Logging

CN24 supports and encapsulates logging to the standard output and standard error streams. You can log to the following output streams:

  • LOGDEBUG for debug messages (log level 3)

  • LOGINFO for user-facing info messages (log level 2)

  • LOGWARN for warning messages (log level 1)

  • LOGERROR for error messages (log level 0)

  • LOGRESULT for testing results

  • LOGTRESULT for training results

It is recommended to insert the LOGEND macro when exiting your program for newline consistency:

LOGINFO << "Hello World!";

// ...

LOGEND;

By default, CN24 only displays messages lower than or equal to the log level specified by either:

  • The first argument to System::Init so you can change the log level in your program, or
  • The CMake cache variable CN24_VERBOSE when building the library.