Skip to content

Commit a2e2135

Browse files
committed
hacky support .so file seperation by hardcoding file path
1 parent 243cede commit a2e2135

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

backends/aoti/aoti_backend.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
PreprocessResult,
1717
)
1818
from executorch.exir.backend.compile_spec_schema import CompileSpec
19-
19+
import os
20+
import shutil
2021

2122
@final
2223
class AotiBackend(BackendDetails):
@@ -31,13 +32,18 @@ def preprocess(
3132
copy_edge_program = copy.deepcopy(edge_program)
3233
graph_module = copy_edge_program.graph_module
3334
args, kwargs = copy_edge_program.example_inputs
34-
so_path = torch._inductor.aot_compile(graph_module, args, kwargs, options={}) # type: ignore[arg-type]
35-
print(so_path)
35+
temp_so_path = torch._inductor.aot_compile(graph_module, args, kwargs, options={}) # type: ignore[arg-type]
36+
so_path = os.path.join(os.getcwd(), 'aoti.so')
37+
print("so_path after aot_compile: ", temp_so_path)
38+
print("so path we will using ", so_path)
39+
shutil.copyfile(temp_so_path, so_path)
40+
3641
check_call(
3742
f"patchelf --remove-needed libtorch.so --remove-needed libc10.so --remove-needed libtorch_cuda.so --remove-needed libc10_cuda.so --remove-needed libtorch_cpu.so --add-needed libcudart.so {so_path}",
3843
shell=True,
3944
)
4045

41-
with open(so_path, "rb") as f:
42-
data = f.read()
43-
return PreprocessResult(data)
46+
# with open(so_path, "rb") as f:
47+
# data = f.read()
48+
49+
return PreprocessResult(so_path.encode("utf-8"))

backends/aoti/runtime/AotiBackend.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,24 @@ class AOTIBackend final : public ::executorch::runtime::BackendInterface {
430430
// We could load the .so content directly. But I don't want to deal with
431431
// relocation. So dumping a file and using dlopen
432432

433-
// Create a temporary file
434-
std::ofstream outfile("/tmp/test.so", std::ios::binary);
433+
// // Create a temporary file
434+
// std::ofstream outfile("/tmp/test.so", std::ios::binary);
435435

436-
// Write the ELF buffer to the temporary file
437-
outfile.write((char*)processed->data(), sizeof(void*) * processed->size());
436+
// // Write the ELF buffer to the temporary file
437+
// outfile.write((char*)processed->data(), sizeof(void*) * processed->size());
438438

439-
// Finish writing the file to disk
440-
outfile.close();
439+
// // Finish writing the file to disk
440+
// outfile.close();
441441

442-
// Free the in-memory buffer
443-
processed->Free();
442+
// // Free the in-memory buffer
443+
// processed->Free();
444+
445+
const char* so_path = static_cast<const char*>(processed->data());
446+
447+
printf("so path: %s\n", so_path);
444448

445449
// Load the ELF using dlopen
446-
void* so_handle = dlopen("/tmp/test.so", RTLD_LAZY | RTLD_LOCAL);
450+
void* so_handle = dlopen(so_path, RTLD_LAZY | RTLD_LOCAL);
447451
if (so_handle == nullptr) {
448452
std::cout << dlerror() << std::endl;
449453
return Error::AccessFailed;

0 commit comments

Comments
 (0)