-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[service] Add a CompilationSession abstract base class.
The CompilationSession class encapsulates an incremental compilation session. This is the first in a series of patches that separates the RPC server from the compilation session. Issue #254.
- Loading branch information
1 parent
3a6f8a3
commit f6b63e1
Showing
3 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// | ||
// 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/service/CompilationSession.h" | ||
|
||
using grpc::Status; | ||
using grpc::StatusCode; | ||
|
||
namespace compiler_gym { | ||
|
||
std::string CompilationSession::getCompilerVersion() const { return ""; } | ||
|
||
Status CompilationSession::init(CompilationSession& other) { | ||
return Status(StatusCode::UNIMPLEMENTED, "CompilationSession::init() not implemented"); | ||
} | ||
|
||
Status CompilationSession::endOfStep(bool& endOfEpisode, | ||
std::optional<ActionSpace>& newActionSpace) { | ||
return Status::OK; | ||
} | ||
|
||
CompilationSession::CompilationSession(const boost::filesystem::path& workingDirectory) | ||
: workingDirectory_(workingDirectory) {} | ||
|
||
} // namespace compiler_gym |
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,71 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
#pragma once | ||
|
||
#include <grpcpp/grpcpp.h> | ||
|
||
#include <vector> | ||
|
||
#include "boost/filesystem.hpp" | ||
#include "compiler_gym/service/proto/compiler_gym_service.pb.h" | ||
|
||
namespace compiler_gym { | ||
|
||
// Base class for encapsulating an incremental compilation session. | ||
// | ||
// To add support for a new compiler, suclass from this base and provide | ||
// implementations of the abstract methods. | ||
class CompilationSession { | ||
public: | ||
// Get the compiler version. | ||
virtual std::string getCompilerVersion() const; | ||
|
||
// A list of action spaces describing the capabilities of the compiler. | ||
virtual std::vector<ActionSpace> getActionSpaces() const = 0; | ||
|
||
// A list of feature vectors that this compiler provides. | ||
virtual std::vector<ObservationSpace> getObservationSpaces() const = 0; | ||
|
||
// Start a CompilationSession. This will be called after construction and | ||
// before applyAction() or computeObservation(). This will only be called | ||
// once. | ||
[[nodiscard]] virtual grpc::Status init(const ActionSpace& actionSpace, | ||
const Benchmark& benchmark) = 0; | ||
|
||
// Initialize the state from another CompilerSession. This will be called | ||
// after construction and before applyAction() or computeObservation(). This | ||
// will only be called once. | ||
[[nodiscard]] virtual grpc::Status init(CompilationSession& other); | ||
|
||
// Apply an action. | ||
[[nodiscard]] virtual grpc::Status applyAction(const Action& action, bool& endOfEpisode, | ||
std::optional<ActionSpace>& newActionSpace, | ||
bool& actionHadNoEffect) = 0; | ||
|
||
// compute an observation | ||
[[nodiscard]] virtual grpc::Status computeObservation(const ObservationSpace& observationSpace, | ||
Observation& observation) = 0; | ||
|
||
// Optional. This will be called after all applyAction() and | ||
// computeObservation() in a step. Use this method if you would like to | ||
// perform post-transform validation of compiler state. | ||
[[nodiscard]] virtual grpc::Status endOfStep(bool actionHadNoEffect, bool& endOfEpisode, | ||
std::optional<ActionSpace>& newActionSpace); | ||
|
||
protected: | ||
// Get the working directory, which is a local filesystem directory that this | ||
// CompilationSession can use to store temporary files such as build | ||
// artifacts. | ||
inline const boost::filesystem::path& workingDirectory() { return workingDirectory_; } | ||
|
||
CompilationSession(const boost::filesystem::path& workingDirectory); | ||
|
||
virtual ~CompilationSession() = default; | ||
|
||
private: | ||
const boost::filesystem::path workingDirectory_; | ||
}; | ||
|
||
} // namespace compiler_gym |