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

[SYCL] Update aspect propagation for virtual functions #15703

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

jzc
Copy link
Contributor

@jzc jzc commented Oct 15, 2024

spec: #10540

@jzc jzc requested a review from a team as a code owner October 15, 2024 14:10
@jzc jzc temporarily deployed to WindowsCILock October 15, 2024 14:16 — with GitHub Actions Inactive
Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

not an expert on this feature but makes sense, just minor comments

@@ -655,16 +687,21 @@ buildFunctionsToAspectsMap(Module &M, TypeToAspectsMapTy &TypesWithAspects,
bool ValidateAspects, bool FP64ConvEmu) {
FunctionToAspectsMapTy FunctionToUsedAspects;
FunctionToAspectsMapTy FunctionToDeclaredAspects;
StringMap<std::vector<Function *>> VirtualFunctionSets;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we are using std::vector over SmallVector or some other LLVM data structure?
Also we might want to make a type alias so the type is cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

It should likely be SmallVector. At least for sequential containers LLVM Programmer's Manual is clear that you should pick the first one which suites your needs and std::vector is at the very end of the list

ret void
}

define spir_func void @subFoo() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check the aspects for subFoo and subBar too?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could, but that part should be already covered by tests for "core" aspects propagation mechanism. Those tests are specially focused on scenarios where a kernel does not use a function directly, but still inherits its aspects, because it uses a "set" where this function belongs to.

@jzc jzc temporarily deployed to WindowsCILock October 15, 2024 15:29 — with GitHub Actions Inactive
@@ -647,6 +647,38 @@ void setSyclFixedTargetsMD(const std::vector<Function *> &EntryPoints,
F->setMetadata("sycl_fixed_targets", MDN);
}

void collectVirtualFunctionSetInfo(
Function &F, StringMap<std::vector<Function *>> &VirtualFunctionSets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it won't require refactoring of existing code (due to shared data structures, or functions), I would add const to F argument (and everywhere else where it is applicable, i.e. to processDeclaredVirtualFunctionSets arguments as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put those into a subfolder to make codebase cleaner (in case we add more tests and in general)?

ret void
}

define spir_func void @subFoo() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could, but that part should be already covered by tests for "core" aspects propagation mechanism. Those tests are specially focused on scenarios where a kernel does not use a function directly, but still inherits its aspects, because it uses a "set" where this function belongs to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Design doc also states the following:

NOTE: if the aspects propagation pass is ever extended to track function
pointers, then aspects attached to virtual functions should not be attached
to kernels using this mechanism. For example, if a kernel uses a variable,
which is initialized with a function pointer to a virtual function which uses
an aspect, then such kernel should not be considered as using that aspect.
Properties-based mechanism which is described above should be used for aspects
propagation for virtual functions.

The idea was to support the case like this one:

struct set_fp64;
struct set_fp32;

struct Foo {
  virtual SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(indirectly_callable_in<set_fp64>)
  void bar() {
    double d;
  }

  virtual SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(indirectly_callable_in<set_fp32>)
  void baz() {
    float f;
  }
};

int main() {
  queue q;
  auto *ptr = malloc_device<Foo>(1, q);
  q.single_task<class Construct>([=]() {
    new (ptr) Foo;
  });
}

Construct kernel could be launched on a device which doesn't support fp64 and it shouldn't result in any errors, i.e. even though Construct kernel under the hood operates with a vtable which references Foo::bar, the kernel shouldn't be considered to use fp64 aspect.

That should be true already, because propagating aspects like that would require extra code, but I think that we should add a test to indicate to us that such addition should not be performed. Or, even if it is performed, then it should ignore virtual functions, because they use their own special mechanism.

@jzc jzc temporarily deployed to WindowsCILock October 17, 2024 14:32 — with GitHub Actions Inactive
@jzc jzc temporarily deployed to WindowsCILock October 17, 2024 15:24 — with GitHub Actions Inactive
@jzc jzc temporarily deployed to WindowsCILock October 21, 2024 17:19 — with GitHub Actions Inactive
@jzc jzc temporarily deployed to WindowsCILock October 21, 2024 18:43 — with GitHub Actions Inactive
@jzc jzc temporarily deployed to WindowsCILock November 5, 2024 15:42 — with GitHub Actions Inactive
@jzc jzc temporarily deployed to WindowsCILock November 5, 2024 17:18 — with GitHub Actions Inactive
@AlexeySachkov AlexeySachkov merged commit 37b339e into intel:sycl Nov 6, 2024
12 checks passed
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.

3 participants