Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #10638: Handle no-op custom call in the emitter
Imported from GitHub PR openxla/xla#10638 The AllocateBuffer custom call (a.k.a. `kNopCustomCallTarget`) is no-op because the runtime allocates the buffer. Let us handle AllocateBuffer by emitting nothing and returning. Copybara import of the project: -- 6ad7c399e05182a543e50ed14f34b99a281155ce by Jaroslav Sevcik <jsevcik@nvidia.com>: Emit no-op (AllocateBuffer custom-call) -- 0f78007475921031549c8555ad56ed8903efe6cb by Jaroslav Sevcik <jsevcik@nvidia.com>: Renamed allocate-buffer to nop in the test Merging this change closes #10638 PiperOrigin-RevId: 628129950
- Loading branch information
1 parent
4ac4d15
commit ef0d2e5
Showing
3 changed files
with
66 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
51 changes: 51 additions & 0 deletions
51
third_party/xla/xla/service/gpu/tests/nop_custom_call_test.cc
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,51 @@ | ||
/* Copyright 2024 The OpenXLA Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "xla/tests/hlo_test_base.h" | ||
|
||
namespace xla { | ||
namespace gpu { | ||
namespace { | ||
|
||
class NopCustomCallTest : public HloTestBase {}; | ||
|
||
TEST_F(NopCustomCallTest, RunAllocateBufferAndUpdate) { | ||
// The test uses a custom call with the AllocateBuffer target (also known as | ||
// kNopCustomCallTarget) to allocate an output buffer. Then it verifies | ||
// we can successfully modify the buffer. | ||
const char* hlo_text = R"( | ||
HloModule AllocateBuffer, is_scheduled=true | ||
overwrite_one { | ||
p0 = s32[1] parameter(0) | ||
c0 = s32[] constant(0) | ||
c1 = s32[1] constant({1}) | ||
ROOT dus0 = s32[1] dynamic-update-slice(p0, c1, c0) | ||
} | ||
ENTRY main { | ||
buffer = s32[1] custom-call(), custom_call_target="AllocateBuffer" | ||
ROOT fusion = s32[1] fusion(buffer), kind=kLoop, calls=overwrite_one | ||
})"; | ||
auto module = ParseAndReturnVerifiedModule(hlo_text).value(); | ||
|
||
Literal result = ExecuteNoHloPasses(std::move(module), {}); | ||
Literal expected = LiteralUtil::CreateR1<int32_t>({1}); | ||
EXPECT_TRUE(LiteralTestUtil::Equal(expected, result)); | ||
} | ||
|
||
} // namespace | ||
} // namespace gpu | ||
} // namespace xla |