-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
#include <unordered_set> | ||
|
||
namespace omnn::rt { | ||
|
||
template <typename ValueT> | ||
class OptimizationLoopDetect { | ||
static thread_local std::unordered_set<ValueT> LoopDetectionStack; | ||
bool isLoop; | ||
const ValueT* value; | ||
|
||
public: | ||
OptimizationLoopDetect(const ValueT& value) { | ||
auto emplaced = LoopDetectionStack.emplace(value); | ||
this->value = &*emplaced.first; | ||
isLoop = !emplaced.second; | ||
} | ||
|
||
~OptimizationLoopDetect() { | ||
if (!isLoop) | ||
LoopDetectionStack.erase(*value); | ||
} | ||
|
||
auto isLoopDetected() const { return isLoop; } | ||
}; | ||
|
||
template <typename ValueT> | ||
thread_local std::unordered_set<ValueT> OptimizationLoopDetect<ValueT>::LoopDetectionStack; | ||
|
||
} | ||
|
||
#if !defined(NDEBUG) && !defined(NOOMDEBUG) | ||
#define ANTILOOP(Type) \ | ||
::omnn::rt::OptimizationLoopDetect<Type> antilooper(*this); \ | ||
if (antilooper.isLoopDetected()) { \ | ||
std::cout << "Loop of optimizating detected in " << *this << std::endl; \ | ||
return; \ | ||
} | ||
#else | ||
#define ANTILOOP(Type) \ | ||
::omnn::rt::OptimizationLoopDetect<Type> antilooper(*this); \ | ||
if (antilooper.isLoopDetected()) { \ | ||
return; \ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters