compiler_gym/service

This directory contains the base class for implementing compilation sessions.

CompilationSession.h

#include "compiler_gym/service/CompilationSession.h"

namespace compiler_gym
class CompilationSession
#include <CompilationSession.h>

Base class for encapsulating an incremental compilation session.

To add support for a new compiler, subclass from this base and provide implementations of the abstract methods, then call createAndRunCompilerGymService() and parametrize it with your class type:

#include "compiler_gym/service/CompilationSession.h"
#include "compiler_gym/service/runtime/Runtime.h"

using namespace compiler_gym;

class MyCompilationSession final : public CompilationSession { ... }

int main(int argc, char** argv) {
    runtime::createAndRunCompilerGymService<MyCompilationSession>();
}

Subclassed by compiler_gym::llvm_service::LlvmSession, compiler_gym::mlir_service::MlirSession

Public Functions

virtual std::string getCompilerVersion() const

Get the compiler version.

Returns

A string indicating the compiler version.

virtual std::vector<ActionSpace> getActionSpaces() const = 0

A list of action spaces describing the capabilities of the compiler.

Returns

A list of ActionSpace instances.

virtual std::vector<ObservationSpace> getObservationSpaces() const = 0

A list of feature vectors that this compiler provides.

Returns

A list of ObservationSpace instances.

virtual grpc::Status init(const ActionSpace &actionSpace, const Benchmark &benchmark) = 0

Start a CompilationSession.

This will be called after construction and before applyAction() or computeObservation(). This will only be called once.

Parameters
  • actionSpace – The action space to use.

  • benchmark – The benchmark to use.

Returns

OK on success, else an error code and message.

virtual grpc::Status init(CompilationSession *other)

Initialize a CompilationSession from another CompilerSession.

Think of this like a copy constructor, except that this method is allowed to fail.

This will be called after construction and before applyAction() or computeObservation(). This will only be called once.

Parameters

other – The CompilationSession to initialize from.

Returns

OK on success, else an errro code and message.

virtual grpc::Status applyAction(const Event &action, bool &endOfEpisode, std::optional<ActionSpace> &newActionSpace, bool &actionHadNoEffect) = 0

Apply an action.

Parameters
  • action – The action to apply.

  • newActionSpace – If applying the action mutated the action space, set this value to the new action space.

  • actionHadNoEffect – If the action had no effect, set this to true.

Returns

OK on success, else an errro code and message.

virtual grpc::Status computeObservation(const ObservationSpace &observationSpace, Event &observation) = 0

Compute an observation.

Returns

OK on success, else an errro code and message.

virtual grpc::Status endOfStep(bool actionHadNoEffect, bool &endOfEpisode, std::optional<ActionSpace> &newActionSpace)

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.

Returns

OK on success, else an errro code and message.

CompilationSession(const boost::filesystem::path &workingDirectory)
virtual ~CompilationSession() = default
virtual grpc::Status handleSessionParameter(const std::string &key, const std::string &value, std::optional<std::string> &reply)

Handle a session parameter send by the frontend.

Session parameters provide a method to send ad-hoc key-value messages to a compilation session through the env.send_session_parameter() method. It us up to the client/service to agree on a common schema for encoding and decoding these parameters.

Implementing this method is optional.

Parameters
  • key – The parameter key.

  • value – The parameter value.

  • reply – A string response message for the parameter, or leave as std::nullopt if the parameter is unknown.

Returns

OK on success, else an errro code and message.

Protected Functions

inline const boost::filesystem::path &workingDirectory()

Get the working directory.

The working directory is a local filesystem directory that this CompilationSession can use to store temporary files such as build artifacts. The directory exists.

Note

If you need to store very large files for a CompilationSession then consider using an alternate filesystem path as, when possible, an in-memory filesystem will be used for the working directory.

Note

A single working directory may be shared by multiple CompilationSession instances. Do not assume that you have exclusive access.

Returns

A path.

Private Members

const boost::filesystem::path workingDirectory_