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

HostIR integration to FusionExecutorCache PR 1/n #3707

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

nsarka
Copy link
Member

@nsarka nsarka commented Jan 14, 2025

In this PR I add a vector of KernelExecutor* to HostIrContainer, and new HostIR called LaunchKernel that takes an index to the vector and launches the kernel. I also add a test to verify correctness.

This is the first in a series of PRs for integration with FusionExecutorCache.

@nsarka nsarka self-assigned this Jan 14, 2025
@nsarka nsarka force-pushed the nsarka/hostir-integration branch from 94b4d48 to 5852eb7 Compare January 14, 2025 18:01
csrc/host_ir/container.h Outdated Show resolved Hide resolved
csrc/host_ir/executor.cpp Outdated Show resolved Hide resolved
@nsarka
Copy link
Member Author

nsarka commented Jan 14, 2025

Thanks, updated.

Copy link
Collaborator

@wujingyue wujingyue left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

csrc/host_ir/executor.cpp Outdated Show resolved Hide resolved
csrc/host_ir/host_ir.cpp Outdated Show resolved Hide resolved
csrc/host_ir/host_ir.h Outdated Show resolved Hide resolved
csrc/host_ir/host_ir.h Outdated Show resolved Hide resolved
csrc/host_ir/host_ir.h Outdated Show resolved Hide resolved
tests/cpp/test_multidevice_host_ir_integration.cpp Outdated Show resolved Hide resolved
tests/cpp/test_multidevice_host_ir_integration.cpp Outdated Show resolved Hide resolved
tests/cpp/test_multidevice_host_ir_integration.cpp Outdated Show resolved Hide resolved
tests/cpp/test_multidevice_host_ir_integration.cpp Outdated Show resolved Hide resolved
tests/cpp/test_multidevice_host_ir_integration.cpp Outdated Show resolved Hide resolved
@nsarka nsarka force-pushed the nsarka/hostir-integration branch from 581d0c9 to 4409faa Compare January 14, 2025 21:13
@nsarka
Copy link
Member Author

nsarka commented Jan 14, 2025

!test

@nsarka nsarka force-pushed the nsarka/hostir-integration branch from 2590d88 to bab9bff Compare January 14, 2025 21:32
Comment on lines +126 to +127
std::vector<Val*> inputs,
std::vector<Val*> outputs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
std::vector<Val*> inputs,
std::vector<Val*> outputs);
const std::vector<Val*>& inputs,
const std::vector<Val*>& outputs);

so it's easier to avoid unnecessary copies -- no std::move needed.

return ss.str();
}

int64_t LaunchKernel::getIndex() const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Style nit: I'd inline trivial implementation like this in the class declaration so the readers don't need to jump to cpp to understand what the method does.


int64_t getIndex() const;

int64_t hic_executor_index_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

private?

Comment on lines +48 to +49
hic->addInput(launch_kernel_inputs.back());
hic->addOutput(launch_kernel_outputs.back());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
hic->addInput(launch_kernel_inputs.back());
hic->addOutput(launch_kernel_outputs.back());
hic->addInput(tv2);
hic->addOutput(tv3);

hic->addOutput(launch_kernel_outputs.back());

auto launch_kernel = IrBuilder::create<LaunchKernel>(
0, launch_kernel_inputs, launch_kernel_outputs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
0, launch_kernel_inputs, launch_kernel_outputs);
0, {tv2}, {tv3});

This way, it's less code and you can remove launch_kernel_inputs/outputs.


IrCloner ir_cloner(hic.get());
auto tv2 = ir_cloner.clone(tv0);
auto tv3 = ir_cloner.clone(tv1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming nit: I'd rename tv0/1/2/3 to something more meaningful, e.g., in, out, hic_in, hic_out. This way, the reader knows their meaning without reading how they are defined.

HostIrEvaluator hie(std::move(hic));

at::Tensor output = at::empty({32, 32}, options);
auto outputs = hie.runWithInput({{tv2, t0}, {tv3, output}});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Therefore, this output is not used by HostIrEvaluator? What happens if you remove {tv3, output}?

That said, sooner or later, we will make output allocations explicit in host IR (see this section), and will run a KernelExecutor with pre-allocated outputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants