Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the compiler gym service backends to the new API #277

Merged
merged 40 commits into from
May 27, 2021

Conversation

ChrisCummins
Copy link
Contributor

Issue #254.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 17, 2021
Copy link
Contributor

@hughleat hughleat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although I still think that not making the user know anything about what RPC mechanism you are using would be better, including allowing a simpler API for them.

}
std::vector<ActionSpace> getActionSpaces() const final override {
ActionSpace space;
space.set_name("default");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shame these are protobufs, then they could just be params to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that this class is never instantiated by the user. They pass it into CompilerGymService<T> which handles lifetime management:
https://github.com/facebookresearch/CompilerGym/blob/development/compiler_gym/service/runtime/CompilerGymServiceImpl.h#L64

scope="module",
params=[example.EXAMPLE_CC_SERVICE_BINARY, example.EXAMPLE_PY_SERVICE_BINARY],
)
def bin(request) -> Path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pytest.fixture decorator declares a fixture, which means that any test function can then take bin as an argument and it will run and return the fixture value

@ChrisCummins
Copy link
Contributor Author

ChrisCummins commented May 18, 2021

Thanks for the review @hughleat!

The CI is complaining of a problem that I've never seen before. An undefined reference to the destructor of google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField() and google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField() in getSpaces():

bazel-out/k8-fastbuild/bin/examples/_objs/RandomSearch/RandomSearch.pic.o:RandomSearch.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'

Will investigate and fix before merging.

@ChrisCummins
Copy link
Contributor Author

I have been blocked on this issue for a couple of days now and cannot seem to figure it out. I have been unable to reproduce this locally on any build environment, including the docker environment used for building the linux wheels. The problem affects all targets that use the new C++ CompilerGymService implementation, and produces the same link-time error:

ERROR: /home/runner/work/CompilerGym/CompilerGym/compiler_gym/envs/llvm/service/BUILD:53:10: Linking compiler_gym/envs/llvm/service/compiler_gym-llvm-service-prelinked failed: (Exit 1): clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/1570/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/compiler_gym-llvm-service-prelinked-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/1570/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/compiler_gym-llvm-service-prelinked-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/_objs/compiler_gym-llvm-service-prelinked/RunService.pic.o:RunService.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/_objs/compiler_gym-llvm-service-prelinked/RunService.pic.o:RunService.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/_objs/compiler_gym-llvm-service-prelinked/RunService.pic.o:RunService.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/compiler_gym/envs/llvm/service/_objs/compiler_gym-llvm-service-prelinked/RunService.pic.o:RunService.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: /home/runner/work/CompilerGym/CompilerGym/examples/example_compiler_gym_service/service_cc/BUILD:7:10: Linking examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc failed: (Exit 1): clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/2646/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/2646/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/compiler_gym-example-service-cc-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/_objs/compiler_gym-example-service-cc/ExampleService.pic.o:ExampleService.cc:function compiler_gym::runtime::CompilerGymService<(anonymous namespace)::ExampleCompilationSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/_objs/compiler_gym-example-service-cc/ExampleService.pic.o:ExampleService.cc:function compiler_gym::runtime::CompilerGymService<(anonymous namespace)::ExampleCompilationSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/_objs/compiler_gym-example-service-cc/ExampleService.pic.o:ExampleService.cc:function compiler_gym::runtime::CompilerGymService<(anonymous namespace)::ExampleCompilationSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/example_compiler_gym_service/service_cc/_objs/compiler_gym-example-service-cc/ExampleService.pic.o:ExampleService.cc:function compiler_gym::runtime::CompilerGymService<(anonymous namespace)::ExampleCompilationSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: /home/runner/work/CompilerGym/CompilerGym/examples/BUILD:120:10: Linking examples/RandomSearch failed: (Exit 1): clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/2798/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/examples/RandomSearch-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox clang failed: error executing command 
  (cd /home/runner/.cache/bazel/_bazel_runner/db3e34f1e14ee53d927a48b4c425fcaa/sandbox/linux-sandbox/2798/execroot/CompilerGym && \
  exec env - \
    LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.9.5/x64/lib \
    PATH=/home/runner/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/opt/hostedtoolcache/Python/3.9.5/x64/bin:/opt/hostedtoolcache/Python/3.9.5/x64:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/runner/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
    *** \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/examples/RandomSearch-2.params)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/examples/_objs/RandomSearch/RandomSearch.pic.o:RandomSearch.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/_objs/RandomSearch/RandomSearch.pic.o:RandomSearch.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/_objs/RandomSearch/RandomSearch.pic.o:RandomSearch.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ActionSpace>::~RepeatedPtrField()'
bazel-out/k8-fastbuild/bin/examples/_objs/RandomSearch/RandomSearch.pic.o:RandomSearch.cc:function compiler_gym::runtime::CompilerGymService<compiler_gym::llvm_service::LlvmSession>::GetSpaces(grpc::ServerContext*, compiler_gym::GetSpacesRequest const*, compiler_gym::GetSpacesReply*): error: undefined reference to 'google::protobuf::RepeatedPtrField<compiler_gym::ObservationSpace>::~RepeatedPtrField()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Supporting the Fork() operator is optional for CompilationSessions, so
provide a fallback implementation that creates a new environment and
replays the action sequence by hand.
Encourage re-use of code within rules, and allow the test target to be
overriden from the command line.
process.poll() may return 0.
Use SIGTERM rather than SIGKILL to terminate backend services, and
then check that the process ended with returncode zero.
This adds a SIGTERM handler which enables the gRPC server to be
shutdown gracefully. This enables an address sanitized build to run
the end-of-process leak check.
@ChrisCummins ChrisCummins force-pushed the runtime-port branch 2 times, most recently from 39916c6 to 4187b9d Compare May 27, 2021 14:18
@ChrisCummins
Copy link
Contributor Author

Fixed the destructor linker error by rewriting the code using for loops rather than direct vector assignment. There's still a few bits to fix up in the CI configs then I'll merge.

@codecov-commenter
Copy link

Codecov Report

Merging #277 (f858b34) into development (2ce4af9) will decrease coverage by 0.22%.
The diff coverage is 52.94%.

❗ Current head f858b34 differs from pull request most recent head 4187b9d. Consider uploading reports for the commit 4187b9d to get more accurate results
Impacted file tree graph

@@               Coverage Diff               @@
##           development     #277      +/-   ##
===============================================
- Coverage        82.07%   81.84%   -0.23%     
===============================================
  Files               87       87              
  Lines             4731     4765      +34     
===============================================
+ Hits              3883     3900      +17     
- Misses             848      865      +17     
Impacted Files Coverage Δ
...ice/runtime/create_and_run_compiler_gym_service.py 42.37% <28.57%> (-3.97%) ⬇️
compiler_gym/service/connection.py 74.02% <63.63%> (+0.02%) ⬆️
compiler_gym/envs/compiler_env.py 85.90% <73.68%> (-0.52%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ce4af9...4187b9d. Read the comment docs.

@ChrisCummins
Copy link
Contributor Author

All test signals green. Merging!

@ChrisCummins ChrisCummins merged commit 9ab1b04 into facebookresearch:development May 27, 2021
@ChrisCummins ChrisCummins deleted the runtime-port branch May 27, 2021 16:52
This was referenced Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants