-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move mutable globals into a central structure
This is a stab at an alternative to #7717, per discussion there. It doesn't necessarily have all the mutable globals moved here, but at least the ones we discussed. Better? Worse? What do you think?
- Loading branch information
1 parent
649a224
commit e194a43
Showing
11 changed files
with
179 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "CompilerGlobals.h" | ||
|
||
#include "Util.h" | ||
|
||
namespace Halide { | ||
namespace Internal { | ||
|
||
namespace { | ||
|
||
Globals the_real_globals; | ||
|
||
size_t compute_stack_size() { | ||
std::string stack_size = get_env_variable("HL_COMPILER_STACK_SIZE"); | ||
if (stack_size.empty()) { | ||
return default_compiler_stack_size; | ||
} else { | ||
return std::stoi(stack_size); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
Globals &globals() { | ||
return the_real_globals; | ||
} | ||
|
||
Globals::Globals() { | ||
reset(); | ||
} | ||
|
||
void Globals::reset() { | ||
random_float_counter = 0; | ||
random_uint_counter = 0; | ||
random_variable_counter = 0; | ||
for (int i = 0; i < num_unique_name_counters; i++) { | ||
unique_name_counters[i] = 0; | ||
} | ||
tick_stack.clear(); | ||
compiler_stack_size = compute_stack_size(); | ||
} | ||
|
||
} // namespace Internal | ||
} // namespace Halide |
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,62 @@ | ||
#ifndef HALIDE_COMPILER_GLOBALS_H | ||
#define HALIDE_COMPILER_GLOBALS_H | ||
|
||
/** \file | ||
* Contains a struct that defines all of the Compiler's global state. | ||
*/ | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <string> | ||
|
||
#include "Util.h" | ||
|
||
namespace Halide { | ||
namespace Internal { | ||
|
||
/** This struct is designed to contain all of the *mutable* global data | ||
* used by the Halide compiler. (Global data that is declared const must | ||
* not go here.) */ | ||
struct Globals { | ||
struct TickStackEntry { | ||
std::chrono::time_point<std::chrono::high_resolution_clock> time; | ||
std::string file; | ||
int line; | ||
}; | ||
|
||
// A counter to use in random_float() calls. | ||
std::atomic<int> random_float_counter; | ||
|
||
// A counter to use in random_uint() and random_int() calls. | ||
std::atomic<int> random_uint_counter; | ||
|
||
// A counter to use in tagging random variables. | ||
// Note that this will be reset by Internal::reset_random_counters(). | ||
std::atomic<int> random_variable_counter; | ||
|
||
// Counters used for the unique_name() utilities. | ||
std::atomic<int> unique_name_counters[num_unique_name_counters]; | ||
|
||
// The stack for tic/toc utilities | ||
std::vector<TickStackEntry> tick_stack; | ||
|
||
// The amount of stack space to use for the compiler, in bytes. | ||
size_t compiler_stack_size; | ||
|
||
Globals(); | ||
|
||
void reset(); | ||
|
||
private: | ||
Globals(const Globals ©) = delete; | ||
Globals &operator=(const Globals &) = delete; | ||
Globals(Globals &&) = delete; | ||
Globals &operator=(Globals &&) = delete; | ||
}; | ||
|
||
Globals &globals(); | ||
|
||
} // namespace Internal | ||
} // namespace Halide | ||
|
||
#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
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
Oops, something went wrong.