Skip to content

Commit 17fdb7c

Browse files
committed
Made the LogLevel variable thread local
1 parent 2552213 commit 17fdb7c

File tree

14 files changed

+65
-29
lines changed

14 files changed

+65
-29
lines changed

src/htm/engine/Input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void Input::uninitialize() {
330330

331331
namespace htm {
332332
std::ostream &operator<<(std::ostream &f, const Input &d) {
333-
f << "Input: " << d.getRegion()->getName() << "." << d.getName() << " " << d.getData();
333+
f << "Input: " << d.getRegion()->getName() << "." << d.getName() << " " << d.getData();
334334
return f;
335335
}
336336
}

src/htm/engine/Link.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <htm/ntypes/BasicType.hpp>
2828
#include <htm/utils/Log.hpp>
2929

30-
// By calling NTA_LOG_LEVEL = LogLevel::LogLevel_Verbose
30+
// By calling Network::setLogLevel(LogLevel_Verbose)
3131
// you can enable the NTA_DEBUG macros below.
3232

3333
namespace htm {
@@ -187,7 +187,7 @@ void Link::compute() {
187187
const Array &src = propagationDelay_ ? propagationDelayBuffer_.front() : src_->getData();
188188
Array &dest = dest_->getData();
189189

190-
NTA_DEBUG << "Link::compute: " << getMoniker() << "; copying to dest input"
190+
NTA_DEBUG << "compute Link: copying " << getMoniker()
191191
<< "; delay=" << propagationDelay_ << "; size=" << src.getCount()
192192
<< " type=" << BasicType::getName(src.getType())
193193
<< " --> " << BasicType::getName(dest.getType()) << std::endl;

src/htm/engine/Network.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ namespace htm {
4040

4141
class RegisteredRegionImpl;
4242

43+
thread_local LogLevel NTA_LOG_LEVEL;
44+
45+
4346
Network::Network() {
4447
commonInit();
4548
}
4649

4750
// move constructor
48-
Network::Network(Network && n) {
51+
Network::Network(Network &&n) noexcept {
4952
regions_ = std::move(n.regions_);
5053
minEnabledPhase_ = n.minEnabledPhase_;
5154
maxEnabledPhase_ = n.maxEnabledPhase_;
5255
phaseInfo_ = std::move(n.phaseInfo_);
5356
callbacks_ = n.callbacks_;
5457
iteration_ = n.iteration_;
55-
}
58+
}
5659

5760
Network::Network(const std::string& filename) {
5861
commonInit();

src/htm/engine/Network.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Link;
6767
/**
6868
* Cannot copy or assign a Network object. But can be moved.
6969
*/
70-
Network(Network&&); // move is allowed
70+
Network(Network &&) noexcept; // move is allowed
7171
Network(const Network&) = delete;
7272
void operator=(const Network&) = delete;
7373

@@ -378,8 +378,10 @@ class Link;
378378
/**
379379
* Set one of the debug levels: LogLevel_None = 0, LogLevel_Minimal, LogLevel_Normal, LogLevel_Verbose
380380
*/
381-
static void setLogLevel(LogLevel level) {
381+
static LogLevel setLogLevel(LogLevel level) {
382+
LogLevel prev = NTA_LOG_LEVEL;
382383
NTA_LOG_LEVEL = level;
384+
return prev;
383385
}
384386

385387

src/htm/engine/Output.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void Output::removeLink(const std::shared_ptr<Link>& link) {
118118

119119
namespace htm {
120120
std::ostream &operator<<(std::ostream &f, const Output &d) {
121-
f << "Output:" << d.getRegion()->getName() << "." << d.getName() << " " << d.getData();
121+
f << "Output: " << d.getRegion()->getName() << "." << d.getName() << " " << d.getData();
122122
return f;
123123
}
124124
}

src/htm/regions/SPRegion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void SPRegion::compute() {
158158
// Call SpatialPooler compute
159159
sp_->compute(inputBuffer.getSDR(), args_.learningMode, outputBuffer.getSDR());
160160

161-
161+
// trace facility
162162
NTA_DEBUG << "compute " << *getOutput("bottomUpOut") << "\n";
163163

164164
}

src/htm/regions/ScalarSensor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ void ScalarSensor::compute()
102102
{
103103
SDR &output = getOutput("encoded")->getData().getSDR();
104104
encoder_->encode((Real64)sensedValue_, output);
105+
106+
// trace facility
107+
NTA_DEBUG << "compute " << getOutput("encoded") << std::endl;
105108
}
106109

107110
ScalarSensor::~ScalarSensor() {}

src/htm/regions/TMRegion.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void TMRegion::compute() {
210210
Array &externalPredictiveInputsWinners = getInput("externalPredictiveInputsWinners")->getData();
211211
SDR& externalPredictiveInputsWinnerCells = (args_.externalPredictiveInputs) ? (externalPredictiveInputsWinners.getSDR()) : nullSDR;
212212

213+
// Trace facility
213214
NTA_DEBUG << "compute " << *in << std::endl;
214215

215216
// Perform Bottom up compute()
@@ -231,34 +232,32 @@ void TMRegion::compute() {
231232
//
232233
std::shared_ptr<Output> out;
233234
out = getOutput("bottomUpOut");
234-
//set
235-
NTA_LOG_LEVEL = htm::LogLevel::LogLevel_Verbose;
236-
NTA_CHECK(NTA_LOG_LEVEL == LogLevel::LogLevel_Verbose) << "setting Verbose failed, man";
237-
//to output the NTA_DEBUG statements below
235+
//call Network::setLogLevel(LogLevel::LogLevel_Verbose);
236+
// to output the NTA_DEBUG statements below
238237
SDR& sdr = out->getData().getSDR();
239238
tm_->getActiveCells(sdr); //active cells
240239
if (args_.orColumnOutputs) { //output as columns
241240
sdr = tm_->cellsToColumns(sdr);
242241
}
243-
NTA_DEBUG << "bottomUpOut " << *out << std::endl;
242+
NTA_DEBUG << "compute "<< *out << std::endl;
244243

245244
out = getOutput("activeCells");
246245
tm_->getActiveCells(out->getData().getSDR());
247-
NTA_DEBUG << "active " << *out << std::endl;
246+
NTA_DEBUG << "compute "<< *out << std::endl;
248247

249248
out = getOutput("predictedActiveCells");
250249
tm_->activateDendrites();
251250
tm_->getWinnerCells(out->getData().getSDR());
252-
NTA_DEBUG << "winners " << *out << std::endl;
251+
NTA_DEBUG << "compute "<< *out << std::endl;
253252

254253
out = getOutput("anomaly");
255254
Real32* buffer = reinterpret_cast<Real32*>(out->getData().getBuffer());
256255
buffer[0] = tm_->anomaly; //only the first field is valid
257-
NTA_DEBUG << "anomaly " << *out << std::endl;
256+
NTA_DEBUG << "compute "<< *out << std::endl;
258257

259258
out = getOutput("predictiveCells");
260259
out->getData().getSDR() = tm_->getPredictiveCells();
261-
NTA_DEBUG << "predictive " << *out << std::endl;
260+
NTA_DEBUG << "compute " << *out << std::endl;
262261
}
263262

264263

src/htm/regions/TMRegion.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TMRegion : public RegionImpl, Serializable {
182182
Size iter;
183183
} args_;
184184

185-
bool isConnected_(std::string name) const;
185+
186186

187187
computeCallbackFunc computeCallback_;
188188
std::unique_ptr<TemporalMemory> tm_;

src/htm/regions/TestNode.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ void TestNode::compute() {
172172
Array &inputArray = bottomUpIn_->getData();
173173
Real64* inputBuffer = (Real64*)inputArray.getBuffer();
174174
size_t count = inputArray.getCount();
175+
176+
// trace facility
177+
NTA_DEBUG << "compute " << bottomUpIn_ << std::endl;
178+
175179

176180
// See TestNode.hpp for description of the computation
177181

@@ -198,6 +202,10 @@ void TestNode::compute() {
198202
}
199203
}
200204

205+
// trace facility
206+
NTA_DEBUG << "compute " << bottomUpOut_ << "\n";
207+
208+
201209
iter_++;
202210
}
203211

0 commit comments

Comments
 (0)