FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge branch 'dev' of https://github.com/cpp-taskflow/cpp-taskflow in… · pmshst/cpp-taskflow@0cd4c3b · GitHub

Commit 0cd4c3b

Browse files
committed
Merge branch 'dev' of https://github.com/cpp-taskflow/cpp-taskflow into dev
2 parents 586d714 + d8ec48e commit 0cd4c3b

5 files changed

Lines changed: 56 additions & 85 deletions

File tree

‎taskflow/core/executor.hpp‎

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ class Executor {
244244

245245
std::unordered_set<std::shared_ptr<ObserverInterface>> _observers;
246246

247-
ObserverInterface* _default_observer;
247+
TFProfObserver* _tfprof;
248248

249249
PerThread& _per_thread() const;
250250

251251
bool _wait_for_task(Worker&, Node*&);
252252

253-
void _instantiate_default_observer();
254-
void _flush_default_observer();
253+
void _instantiate_tfprof();
254+
void _flush_tfprof();
255255
void _observer_prologue(Worker&, Node*);
256256
void _observer_epilogue(Worker&, Node*);
257257
void _spawn(size_t, Domain);
@@ -319,7 +319,7 @@ inline Executor::Executor(size_t N, size_t M) :
319319
_spawn(M, CUDA);
320320

321321
// initiate the observer if requested
322-
_instantiate_default_observer();
322+
_instantiate_tfprof();
323323
}
324324

325325
#else
@@ -344,7 +344,7 @@ inline Executor::Executor(size_t N) :
344344
_spawn(N, HOST);
345345

346346
// instantite the default observer if requested
347-
_instantiate_default_observer();
347+
_instantiate_tfprof();
348348
}
349349
#endif
350350

@@ -376,50 +376,24 @@ inline Executor::~Executor() {
376376
#endif
377377

378378
// flush the default observer
379-
_flush_default_observer();
379+
_flush_tfprof();
380380
}
381381

382-
// Procedure: _instantiate_default_observer
383-
inline void Executor::_instantiate_default_observer() {
384-
382+
// Procedure: _instantiate_tfprof
383+
inline void Executor::_instantiate_tfprof() {
385384
// TF_OBSERVER_TYPE
386-
auto env = std::getenv("TF_OBSERVER_TYPE");
387-
388-
if(env) {
389-
auto type = static_cast<ObserverType>(std::atoi(env));
390-
391-
switch(type) {
392-
case CHROME_TRACING_OBSERVER:
393-
_default_observer = make_observer<ChromeTracingObserver>().get();
394-
break;
395-
396-
case TASKFLOW_BOARD_OBSERVER:
397-
_default_observer = make_observer<TaskflowBoardObserver>().get();
398-
break;
399-
400-
default:
401-
TF_THROW("unsupported observer type id: ", type);
402-
break;
403-
}
404-
}
405-
else {
406-
_default_observer = nullptr;
407-
}
385+
_tfprof = std::getenv("TF_ENABLE_PROFILER") ?
386+
make_observer<TFProfObserver>().get() : nullptr;
408387
}
409388

410-
// Procedure: _flush_default_observer
411-
inline void Executor::_flush_default_observer() {
412-
if(_default_observer) {
413-
const char* env = std::getenv("TF_OBSERVER_FILE");
414-
if(env) {
415-
char buf[4096];
416-
std::sprintf(buf, "%s_%p.tfb", env, this);
417-
std::ofstream ofs(buf);
418-
_default_observer->dump(ofs);
419-
}
420-
else {
421-
_default_observer->dump(std::cout);
422-
}
389+
// Procedure: _flush_tfprof
390+
inline void Executor::_flush_tfprof() {
391+
392+
if(_tfprof) {
393+
std::ostringstream fpath;
394+
fpath << std::getenv("TF_ENABLE_PROFILER") << _tfprof->_uuid << ".tfp";
395+
std::ofstream ofs(fpath.str());
396+
_tfprof->dump(ofs);
423397
}
424398
}
425399

‎taskflow/core/graph.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../utility/traits.hpp"
77
#include "../utility/passive_vector.hpp"
88
#include "../utility/singleton.hpp"
9+
#include "../utility/uuid.hpp"
910
#include "../nstd/variant.hpp"
1011

1112
#if defined(__CUDA__) || defined(__CUDACC__)

‎taskflow/core/observer.hpp‎

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ class ObserverInterface {
5454
@param task_view a constant wrapper object to the task
5555
*/
5656
virtual void on_exit(unsigned worker_id, TaskView task_view) = 0;
57-
58-
/**
59-
@brief method to dump the observed data
60-
@param ostream the output stream to dump
61-
*/
62-
virtual void dump(std::ostream& ostream) const = 0;
6357
};
6458

6559
// ----------------------------------------------------------------------------
@@ -108,7 +102,7 @@ class ChromeTracingObserver : public ObserverInterface {
108102
@brief dump the timelines in JSON format to an ostream
109103
@param ostream the target std::ostream to dump
110104
*/
111-
inline void dump(std::ostream& ostream) const override final;
105+
inline void dump(std::ostream& ostream) const;
112106

113107
/**
114108
@brief dump the timelines in JSON to a std::string
@@ -259,16 +253,16 @@ inline size_t ChromeTracingObserver::num_tasks() const {
259253
}
260254

261255
// ----------------------------------------------------------------------------
262-
// TaskflowBoardObserver definition
256+
// TFProfObserver definition
263257
// ----------------------------------------------------------------------------
264258

265259
/**
266-
@class: TaskflowBoardObserver
260+
@class: TFProfObserver
267261
268262
@brief observer designed based on taskflow board format
269263
270264
*/
271-
class TaskflowBoardObserver : public ObserverInterface {
265+
class TFProfObserver : public ObserverInterface {
272266

273267
friend class Executor;
274268

@@ -302,12 +296,12 @@ class TaskflowBoardObserver : public ObserverInterface {
302296
};
303297

304298
public:
305-
299+
306300
/**
307301
@brief dump the timelines in JSON format to an ostream
308302
@param ostream the target std::ostream to dump
309303
*/
310-
inline void dump(std::ostream& ostream) const override final;
304+
inline void dump(std::ostream& ostream) const;
311305

312306
/**
313307
@brief dump the timelines in JSON to a std::string
@@ -333,10 +327,12 @@ class TaskflowBoardObserver : public ObserverInterface {
333327
inline void on_exit(unsigned worker_id, TaskView task_view) override final;
334328

335329
Timeline _timeline;
330+
331+
UUID _uuid;
336332
};
337-
333+
338334
// constructor
339-
inline TaskflowBoardObserver::Segment::Segment(
335+
inline TFProfObserver::Segment::Segment(
340336
const std::string& n,
341337
TaskType t,
342338
std::chrono::time_point<std::chrono::steady_clock> b
@@ -345,7 +341,7 @@ inline TaskflowBoardObserver::Segment::Segment(
345341
}
346342

347343
// constructor
348-
inline TaskflowBoardObserver::Segment::Segment(
344+
inline TFProfObserver::Segment::Segment(
349345
const std::string& n,
350346
TaskType t,
351347
std::chrono::time_point<std::chrono::steady_clock> b,
@@ -355,7 +351,7 @@ inline TaskflowBoardObserver::Segment::Segment(
355351
}
356352

357353
// Procedure: set_up
358-
inline void TaskflowBoardObserver::set_up(unsigned num_workers) {
354+
inline void TFProfObserver::set_up(unsigned num_workers) {
359355

360356
_timeline.segments.resize(num_workers);
361357

@@ -367,27 +363,27 @@ inline void TaskflowBoardObserver::set_up(unsigned num_workers) {
367363
}
368364

369365
// Procedure: on_entry
370-
inline void TaskflowBoardObserver::on_entry(unsigned w, TaskView tv) {
366+
inline void TFProfObserver::on_entry(unsigned w, TaskView tv) {
371367
_timeline.segments[w].emplace_back(
372368
tv.name(), tv.type(), std::chrono::steady_clock::now()
373369
);
374370
}
375371

376372
// Procedure: on_exit
377-
inline void TaskflowBoardObserver::on_exit(unsigned w, TaskView) {
373+
inline void TFProfObserver::on_exit(unsigned w, TaskView) {
378374
assert(_timeline.segments[w].size() > 0);
379375
_timeline.segments[w].back().end = std::chrono::steady_clock::now();
380376
}
381377

382378
// Function: clear
383-
inline void TaskflowBoardObserver::clear() {
379+
inline void TFProfObserver::clear() {
384380
for(size_t w=0; w<_timeline.segments.size(); ++w) {
385381
_timeline.segments[w].clear();
386382
}
387383
}
388384

389385
// Procedure: dump
390-
inline void TaskflowBoardObserver::dump(std::ostream& os) const {
386+
inline void TFProfObserver::dump(std::ostream& os) const {
391387

392388
size_t first;
393389

@@ -403,7 +399,7 @@ inline void TaskflowBoardObserver::dump(std::ostream& os) const {
403399
return;
404400
}
405401

406-
os << "{\"group\":\"executor[" << this << "]\",\"data\":[";
402+
os << "{\"executor\":\"" << _uuid << "\",\"data\":[";
407403

408404
for(size_t w=first; w<_timeline.segments.size(); w++) {
409405

@@ -415,15 +411,15 @@ inline void TaskflowBoardObserver::dump(std::ostream& os) const {
415411
os << ',';
416412
}
417413

418-
os << "{\"label\":\"worker " << w << "\",\"data\":[";
414+
os << "{\"worker\":\"worker " << w << "\",\"data\":[";
419415
for(size_t i=0; i<_timeline.segments[w].size(); ++i) {
420416

421417
const auto& s = _timeline.segments[w][i];
422418

423419
if(i) os << ',';
424420

425-
// timeRange
426-
os << "{\"timeRange\":["
421+
// span
422+
os << "{\"span\":["
427423
<< std::chrono::duration_cast<std::chrono::microseconds>(
428424
s.beg - _timeline.origin
429425
).count() << ","
@@ -441,8 +437,8 @@ inline void TaskflowBoardObserver::dump(std::ostream& os) const {
441437
}
442438
os << "\",";
443439

444-
// category "val": "Condition Task",
445-
os << "\"val\":\"" << task_type_to_string(s.type) << "\"";
440+
// category "type": "Condition Task",
441+
os << "\"type\":\"" << task_type_to_string(s.type) << "\"";
446442

447443
os << "}";
448444
}
@@ -453,14 +449,14 @@ inline void TaskflowBoardObserver::dump(std::ostream& os) const {
453449
}
454450

455451
// Function: dump
456-
inline std::string TaskflowBoardObserver::dump() const {
452+
inline std::string TFProfObserver::dump() const {
457453
std::ostringstream oss;
458454
dump(oss);
459455
return oss.str();
460456
}
461457

462458
// Function: num_tasks
463-
inline size_t TaskflowBoardObserver::num_tasks() const {
459+
inline size_t TFProfObserver::num_tasks() const {
464460
return std::accumulate(
465461
_timeline.segments.begin(), _timeline.segments.end(), size_t{0},
466462
[](size_t sum, const auto& exe){
@@ -479,8 +475,8 @@ built-in observer types
479475
480476
*/
481477
enum ObserverType {
482-
CHROME_TRACING_OBSERVER = 1,
483-
TASKFLOW_BOARD_OBSERVER = 2
478+
TFPROF = 1,
479+
CHROME = 2
484480
};
485481

486482
/**
@@ -489,9 +485,9 @@ enum ObserverType {
489485
const char* observer_type_to_string(ObserverType type) {
490486
const char* val;
491487
switch(type) {
492-
case CHROME_TRACING_OBSERVER: val = "ChromeTracingObserver"; break;
493-
case TASKFLOW_BOARD_OBSERVER: val = "TaskflowBoardObserver"; break;
494-
default: val = "undefined"; break;
488+
case TFPROF: val = "TFProf"; break;
489+
case CHROME: val = "Chrome"; break;
490+
default: val = "undefined"; break;
495491
}
496492
return val;
497493
}

‎taskflow/core/task.hpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ const char* task_type_to_string(TaskType type) {
3333
const char* val;
3434

3535
switch(type) {
36-
case PLACEHOLDER_TASK: val = "placeholder"; break;
36+
case PLACEHOLDER_TASK: val = "placeholder"; break;
3737
#ifdef TF_ENABLE_CUDA
38-
case CUDAFLOW_TASK: val = "cudaflow"; break;
38+
case CUDAFLOW_TASK: val = "cudaflow"; break;
3939
#endif
40-
case STATIC_TASK: val = "static task"; break;
41-
case DYNAMIC_TASK: val = "dynamic task"; break;
42-
case CONDITION_TASK: val = "condition task"; break;
43-
case MODULE_TASK: val = "module task"; break;
44-
default: val = "undefined"; break;
40+
case STATIC_TASK: val = "static"; break;
41+
case DYNAMIC_TASK: val = "subflow"; break;
42+
case CONDITION_TASK: val = "condition"; break;
43+
case MODULE_TASK: val = "module"; break;
44+
default: val = "undefined"; break;
4545
}
4646

4747
return val;

‎taskflow/declarations.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Executor;
1919
class WorkerView;
2020
class ObserverInterface;
2121
class ChromeTracingObserver;
22-
class TaskflowBoardObserver;
22+
class TFProfObserver;
2323

2424
// cudaflow
2525
class cudaNode;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL