Skip to content

[GPU] Enable custom op with dynamic shape #30880

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

Conversation

xipingyan
Copy link
Contributor

@xipingyan xipingyan commented Jun 6, 2025

Details:

  • Wrapper gws and lws calculation, and move it to custom_gpu_primitive.hpp
  • Pass OP(customer provided) to cldnn::custom_gpu_primitive, we need to call it(new_op->validate_and_infer_types()) to inference real output shape.
  • Add test case.

Tickets:

@github-actions github-actions bot added the category: GPU OpenVINO GPU plugin label Jun 6, 2025
@xipingyan xipingyan requested a review from peterchen-intel June 6, 2025 06:17
@sshlyapn
Copy link
Contributor

By the way, the current version implements dynamism through kernel recompilation for each new dynamic shape configuration. However, we could support a shape_agnostic kernel version that can be compiled once and reused with any shape. That said, this implementation looks like a good step toward supporting dynamic custom operations

@xipingyan xipingyan force-pushed the xp/enable_custom_op_with_dynamic_shape branch from acd0c40 to 977877a Compare June 19, 2025 07:26
Remove overrided get_fake_aligned_params.

Signed-off-by: xiping.yan <[email protected]>
@xipingyan
Copy link
Contributor Author

xipingyan commented Jun 19, 2025

By the way, the current version implements dynamism through kernel recompilation for each new dynamic shape configuration. However, we could support a shape_agnostic kernel version that can be compiled once and reused with any shape. That said, this implementation looks like a good step toward supporting dynamic custom operations

hi @sshlyapn , I got your idea, you just want to compile the kernel once for dynamic shape, customer should make sure their kernel is shape_agnostic.
Currently I have no good idea about this.

1: Maybe we can merge this solution as first step.(I still need to add test case.)
2: Or we add an item to kernel description(xml, for example: https://docs.openvino.ai/2025/documentation/openvino-extensibility/custom-gpu-operations.html#example-configuration-file), let customer tell us his kernel is shape_agnostic, so we just compile it once.(gws, lws, should be const, maybe ...)

Because we need to update public interface and wiki for the solution 2, so I'd like to merge current solution as first step, and then enable shape_agnostic kernel in the next step.
What's your idea? @sshlyapn

@github-actions github-actions bot added the category: build OpenVINO cmake script / infra label Jun 24, 2025
@peterchen-intel peterchen-intel added the pr: needs tests PR needs tests updating label Jul 2, 2025
@peterchen-intel peterchen-intel requested a review from sshlyapn July 2, 2025 06:38
Copy link
Contributor

@luo-cheng2021 luo-cheng2021 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@xipingyan xipingyan marked this pull request as ready for review July 3, 2025 07:11
@xipingyan xipingyan requested review from a team as code owners July 3, 2025 07:11
@xipingyan
Copy link
Contributor Author

@peterchen-intel Added test case. Remove draft and ready for review.

@peterchen-intel peterchen-intel removed the pr: needs tests PR needs tests updating label Jul 5, 2025
The root cause was unit test did not pass "global work size rule".

Signed-off-by: xipingyan <[email protected]>
Enable shape agnostic.

Signed-off-by: xipingya <[email protected]>
@xipingyan
Copy link
Contributor Author

By the way, the current version implements dynamism through kernel recompilation for each new dynamic shape configuration. However, we could support a shape_agnostic kernel version that can be compiled once and reused with any shape. That said, this implementation looks like a good step toward supporting dynamic custom operations

hi @sshlyapn , I got your idea, you just want to compile the kernel once for dynamic shape, customer should make sure their kernel is shape_agnostic. Currently I have no good idea about this.

1: Maybe we can merge this solution as first step.(I still need to add test case.) 2: Or we add an item to kernel description(xml, for example: https://docs.openvino.ai/2025/documentation/openvino-extensibility/custom-gpu-operations.html#example-configuration-file), let customer tell us his kernel is shape_agnostic, so we just compile it once.(gws, lws, should be const, maybe ...)

Because we need to update public interface and wiki for the solution 2, so I'd like to merge current solution as first step, and then enable shape_agnostic kernel in the next step. What's your idea? @sshlyapn

Hi @sshlyapn , @peterchen-intel
I just registered the dynamic_shape kernel for custom_op, I find it works for shape agnostic now. Please help review again.

@@ -261,6 +295,7 @@ static std::unique_ptr<primitive_impl> create(const custom_gpu_primitive_node& a
namespace detail {

attach_custom_gpu_primitive_impl::attach_custom_gpu_primitive_impl() {
implementation_map<custom_gpu_primitive>::add(impl_types::ocl, shape_types::dynamic_shape, create, {});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest reverting this dynamic impl registration changes, as it's not sufficient to support shape-agnostic kernel logic. It will only make the pipeline think it's requesting dynamic kernel, while it will still get static one - which could lead to issues. So let's merge the initial version first, and then extend it with proper dynamic support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I local test found: it can get dynamic kernel, because I used onetrace to profiling it, after registering the dynamic shape kernel, clBuildProgram will only be called once, regardless of whether the shape changes or not
If I don't register the dynamic shape kernel, clBuildProgram is called if the shape changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, when I added more dynamic dim to test case, I got some problems.
I just reverted dynamic shape kernel register. Take it as next step.

core.set_property(ov::test::utils::DEVICE_GPU, {{"CONFIG_FILE", TEST_CUSTOM_OP_DYNAMIC_CONFIG_PATH}});
}

TEST(CustomOpDynamic, Accuracy) {
Copy link
Contributor

@sshlyapn sshlyapn Jul 28, 2025

Choose a reason for hiding this comment

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

Can you please add smoke_ prefix to the tests name and double check them locally?

[----------] 2 tests from CustomOpDynamic
[ RUN      ] CustomOpDynamic.CanReadValidCustomOpConfig
[       OK ] CustomOpDynamic.CanReadValidCustomOpConfig (1 ms)
[ RUN      ] CustomOpDynamic.Accuracy
src/plugins/intel_gpu/tests/functional/custom_op/custom_op_dynamic.cpp:119: Failure
Expected equality of these values:
  actual[i]
    Which is: 0
  inp_data[i] * alpha + beta
    Which is: 0.40000001
[  FAILED  ] CustomOpDynamic.Accuracy (38 ms)
[----------] 2 tests from CustomOpDynamic (39 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (40 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] CustomOpDynamic.Accuracy

 1 FAILED TEST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, strange, I test pass locally,

@xipingyan xipingyan requested a review from sshlyapn July 29, 2025 10:00
2: more dynamic dim for test.
3: revert dynamic shape kernel register.
4: Add comment about check if inference output shape.

Signed-off-by: xipingya <[email protected]>
@sshlyapn
Copy link
Contributor

@xipingyan , can you please check CI test failures?

ov_gpu_func_tests-0 INFO: FAILED TESTS (1/39269):
ov_gpu_func_tests-0 INFO:     2909 ms: ov_gpu_func_tests smoke_CustomOpDynamic.Accuracy

@xipingyan
Copy link
Contributor Author

@xipingyan , can you please check CI test failures?

ov_gpu_func_tests-0 INFO: FAILED TESTS (1/39269):
ov_gpu_func_tests-0 INFO:     2909 ms: ov_gpu_func_tests smoke_CustomOpDynamic.Accuracy

I tested pass at local, ci log show:
Error loading custom layer configuration file: /home/jenkins/agent/workspace/private-ci/ie/build-linux-ubuntu22/b/repos/openvino/src/plugins/intel_gpu/tests/functional/custom_op/custom_op_dynamic.xml, File was not found at offset 0
The path to the XML file seems correct. I'll need to double-check that.

Use "ov::test::utils::createFile() and ov::test::utils::removeFile()" to manage config and cl files.

Signed-off-by: xipingya <[email protected]>
@sshlyapn sshlyapn added this to the 2025.3 milestone Aug 4, 2025
@sshlyapn sshlyapn added this pull request to the merge queue Aug 4, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 4, 2025
### Details:
- *Wrapper gws and lws calculation, and move it to
custom_gpu_primitive.hpp*
- *Pass OP(customer provided) to **cldnn::custom_gpu_primitive**, we
need to call it(new_op->**validate_and_infer_types()**) to inference
real output shape.*
 - *Add test case.*

### Tickets:
 - *CVS-170115*

---------

Signed-off-by: xiping.yan <[email protected]>
Signed-off-by: xipingyan <[email protected]>
Signed-off-by: xipingya <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 4, 2025
@peterchen-intel peterchen-intel added this pull request to the merge queue Aug 4, 2025
Merged via the queue into openvinotoolkit:master with commit 8c41361 Aug 4, 2025
198 of 202 checks passed
@peterchen-intel peterchen-intel deleted the xp/enable_custom_op_with_dynamic_shape branch August 4, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: GPU OpenVINO GPU plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants