Skip to content

Qualcomm AI Engine Direct - Support MSVC-compatible code#19686

Open
zhaoxul-qti wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/zhaoxul/support_msvc_compatible
Open

Qualcomm AI Engine Direct - Support MSVC-compatible code#19686
zhaoxul-qti wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/zhaoxul/support_msvc_compatible

Conversation

@zhaoxul-qti
Copy link
Copy Markdown
Contributor

Summary

1. Remove the designated initializers for C++

Why it compiles on Linux but not on Windows MSVC?

  • Designated initializers for C++ aggregates were standardized in C++20. GCC and Clang have supported them as a C++11/14/17 extension — they silently accept the syntax even when compiling in -std=c++17 mode. MSVC is strictly conformant: it only accepts designated initializers when /std:c++20 (or /std:c++latest) is active.

2. Remove the GNU statement expressions

Why it compiles on Linux but not on Windows MSVC?

  • The GNU statement expression is a GNU C / GNU C++ language extension that lets you treat a block of statements as if it were a single expression that produces a value. It is not part of standard C or C++, but it is widely supported by GCC and Clang. MSVC does not support it.

3. Replace constexpr inside the lambda [&]

  • ET_INTERNAL_SWITCH wraps the NAME in [&] { ... }(). The [&] capture means the lambda captures all local variables by reference, including NAME.
  • However, inside the lambda [&], NAME is accessed via the closure's implicit this pointer — it is (*this).name in the closure's internal representation to capture variables by reference. Dereferencing this is not a constant expression because this is a runtime pointer to the closure object, which is not a constant expression and only exists at runtime.

Why it compiles on Linux but not on Windows MSVC?

  • GCC and Clang are more permissive here. They apply a special rule: if the captured variable is itself constexpr and its value is a compile-time constant, they allow it to be used as a constant expression inside the lambda, effectively treating the capture as a constant propagation rather than a runtime dereference. This is a quality-of-implementation extension beyond what the standard strictly requires.

4. Replace the __attribute__((visibility("default"))) with corresponding MSVC-compatible syntax

  • Use Microsoft-specific C/C++ extensions __declspec(dllexport) and __declspec(dllimport) to control symbol visibility when working with Windows DLLs.

- Remove the designated initializers for C++
- Remove the GNU statement expressions
- Replace constexpr inside the lambda [&]
- Replace the __attribute__((visibility("default"))) with corresponding MSVC-compatible syntax
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 20, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19686

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⚠️ 15 Awaiting Approval

As of commit d7cddf0 with merge base a4bd823 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 20, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@zhaoxul-qti
Copy link
Copy Markdown
Contributor Author

This PR also fix the issue mentioned in 4b7bea2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant