Skip to content

Commit

Permalink
[llvm] Make sure that BenchmarkFactory::close() is called.
Browse files Browse the repository at this point in the history
This adds an explicit call to BenchmarkFactory::close() on the global
singleton, since otherwise it may not be called.

Fixes facebookresearch#582.
Issue facebookresearch#591.
  • Loading branch information
ChrisCummins committed Mar 6, 2022
1 parent 6183b7f commit 1b6187d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler_gym/envs/llvm/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cc_binary(
name = "compiler_gym-llvm-service-prelinked",
srcs = ["RunService.cc"],
deps = [
":BenchmarkFactory",
":LlvmSession",
"//compiler_gym/service/runtime:cc_runtime",
],
Expand Down
1 change: 1 addition & 0 deletions compiler_gym/envs/llvm/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cg_cc_binary(
"RunService.cc"
DEPS
::LlvmSession
::BenchmarkFactory
compiler_gym::service::runtime::cc_runtime
)

Expand Down
11 changes: 11 additions & 0 deletions compiler_gym/envs/llvm/service/RunService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#include "compiler_gym/envs/llvm/service/BenchmarkFactory.h"
#include "compiler_gym/envs/llvm/service/LlvmSession.h"
#include "compiler_gym/service/runtime/Runtime.h"
#include "llvm/InitializePasses.h"
Expand Down Expand Up @@ -61,5 +62,15 @@ int main(int argc, char** argv) {
initLlvm();
const auto ret = createAndRunCompilerGymService<LlvmSession>(argc, argv, usage);

// NOTE(github.com/facebookresearch/CompilerGym/issues/582): We need to make
// sure that BenchmarkFactory::close() is called on the global singleton
// instance, so that the temporary scratch directories are tidied up.
//
// TODO(github.com/facebookresearch/CompilerGym/issues/591): Once the runtime
// has been refactored to support intra-session mutable state, this singleton
// can be replaced by a member variable that is closed on
// CompilerGymServiceContext::shutdown().
BenchmarkFactory::getSingleton(FLAGS_working_dir).close();

return ret;
}

0 comments on commit 1b6187d

Please sign in to comment.