Skip to content

Commit

Permalink
[XLA:CPU] Remove CompiledFunctionLibrary from JitCompiler.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 712484420
  • Loading branch information
Google-ML-Automation committed Jan 6, 2025
1 parent 8647577 commit 3a063ca
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 52 deletions.
1 change: 1 addition & 0 deletions xla/backends/cpu/codegen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ cc_library(
srcs = ["jit_compiler.cc"],
hdrs = ["jit_compiler.h"],
deps = [
":compiled_function_library",
":contiguous_section_memory_manager",
":cpu_features",
":ir_compiler",
Expand Down
29 changes: 1 addition & 28 deletions xla/backends/cpu/codegen/jit_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ limitations under the License.
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Host.h"
#include "xla/backends/cpu/codegen/compiled_function_library.h"
#include "xla/backends/cpu/codegen/contiguous_section_memory_manager.h"
#include "xla/backends/cpu/codegen/cpu_features.h"
#include "xla/backends/cpu/codegen/ir_compiler.h"
Expand Down Expand Up @@ -349,32 +350,4 @@ void JitCompiler::TaskDispatcher::shutdown() {
absl::MutexLock lock(&mu_, absl::Condition(&all_tasks_finished));
}

JitCompiler::CompiledFunctionLibrary::CompiledFunctionLibrary(
std::unique_ptr<llvm::orc::ExecutionSession> execution_session,
std::unique_ptr<llvm::orc::RTDyldObjectLinkingLayer> object_layer,
absl::flat_hash_map<std::string, ResolvedSymbol> symbols_map)
: execution_session_(std::move(execution_session)),
object_layer_(std::move(object_layer)),
symbols_map_(std::move(symbols_map)) {
DCHECK(execution_session_) << "Execution session must not be null";
}

JitCompiler::CompiledFunctionLibrary::~CompiledFunctionLibrary() {
if (auto err = execution_session_->endSession()) {
execution_session_->reportError(std::move(err));
}
}

absl::StatusOr<void*> JitCompiler::CompiledFunctionLibrary::ResolveFunction(
TypeId type_id, absl::string_view name) {
if (auto it = symbols_map_.find(name); it != symbols_map_.end()) {
if (it->second.type_id != type_id) {
return Internal("Symbol %s has type id %d, expected %d", name,
it->second.type_id.value(), type_id.value());
}
return it->second.ptr;
}
return NotFound("Function %s not found (type id: %d)", name, type_id.value());
}

} // namespace xla::cpu
24 changes: 0 additions & 24 deletions xla/backends/cpu/codegen/jit_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,6 @@ class JitCompiler {
size_t num_dispatched_tasks_ ABSL_GUARDED_BY(mu_) = 0;
};

// Function library constructed from the set of jit-compiled symbols.
class CompiledFunctionLibrary : public FunctionLibrary {
public:
struct ResolvedSymbol {
TypeId type_id;
void* ptr;
};

CompiledFunctionLibrary(
std::unique_ptr<llvm::orc::ExecutionSession> execution_session,
std::unique_ptr<llvm::orc::RTDyldObjectLinkingLayer> object_layer,
absl::flat_hash_map<std::string, ResolvedSymbol> symbols_map);

~CompiledFunctionLibrary() final;

absl::StatusOr<void*> ResolveFunction(TypeId type_id,
absl::string_view name) final;

private:
std::unique_ptr<llvm::orc::ExecutionSession> execution_session_;
std::unique_ptr<llvm::orc::RTDyldObjectLinkingLayer> object_layer_;
absl::flat_hash_map<std::string, ResolvedSymbol> symbols_map_;
};

JitCompiler(IrCompiler::TargetMachineBuilder target_machine_builder,
std::shared_ptr<llvm::TargetMachine> target_machine,
TaskDispatcher* task_dispatcher,
Expand Down

0 comments on commit 3a063ca

Please sign in to comment.