@@ -29,17 +29,13 @@ namespace cudf {
29
29
30
30
context::context (init_flags flags) : _program_cache{nullptr }
31
31
{
32
- if (has_flag (flags, init_flags::INIT_JIT_CACHE)) {
33
- _program_cache = std::make_unique<jit::program_cache>();
34
- }
35
-
36
- if (has_flag (flags, init_flags::LOAD_NVCOMP)) { io::detail::nvcomp::load_nvcomp_library (); }
37
-
38
32
auto dump_codegen_flag = getenv_or (" LIBCUDF_JIT_DUMP_CODEGEN" , std::string{" OFF" });
39
33
_dump_codegen = (dump_codegen_flag == " ON" || dump_codegen_flag == " 1" );
40
34
41
35
auto use_jit_flag = getenv_or (" LIBCUDF_JIT_ENABLED" , std::string{" OFF" });
42
36
_use_jit = (use_jit_flag == " ON" || use_jit_flag == " 1" );
37
+
38
+ initialize_components (flags);
43
39
}
44
40
45
41
jit::program_cache& context::program_cache ()
@@ -50,6 +46,20 @@ jit::program_cache& context::program_cache()
50
46
51
47
bool context::dump_codegen () const { return _dump_codegen; }
52
48
49
+ void context::initialize_components (init_flags flags)
50
+ {
51
+ // Only initialize components that haven't been initialized yet
52
+ auto const new_flags = flags & ~_initialized_flags;
53
+
54
+ if (has_flag (new_flags, init_flags::INIT_JIT_CACHE)) {
55
+ _program_cache = std::make_unique<jit::program_cache>();
56
+ }
57
+
58
+ if (has_flag (new_flags, init_flags::LOAD_NVCOMP)) { io::detail::nvcomp::load_nvcomp_library (); }
59
+
60
+ _initialized_flags = _initialized_flags | new_flags;
61
+ }
62
+
53
63
bool context::use_jit () const { return _use_jit; }
54
64
55
65
std::unique_ptr<context>& get_context_ptr_ref ()
@@ -71,15 +81,15 @@ namespace CUDF_EXPORT cudf {
71
81
72
82
void initialize (init_flags flags)
73
83
{
74
- CUDF_EXPECTS (
75
- get_context_ptr_ref () == nullptr , " context is already initialized" , std::runtime_error);
76
- get_context_ptr_ref () = std::make_unique<context>(flags);
84
+ auto & ctx = get_context_ptr_ref ();
85
+ if (ctx == nullptr ) {
86
+ // First initialization - create the context
87
+ ctx = std::make_unique<context>(flags);
88
+ } else {
89
+ // Context already exists - initialize additional components
90
+ ctx->initialize_components (flags);
91
+ }
77
92
}
78
93
79
- void deinitialize ()
80
- {
81
- CUDF_EXPECTS (
82
- get_context_ptr_ref () != nullptr , " context has already been deinitialized" , std::runtime_error);
83
- get_context_ptr_ref ().reset ();
84
- }
94
+ void deinitialize () { get_context_ptr_ref ().reset (); }
85
95
} // namespace CUDF_EXPORT cudf
0 commit comments