-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] AST support for SYCL kernel entry point functions.
A SYCL kernel entry point function is a non-member function or a static member function declared with the `sycl_kernel_entry_point` attribute. Such functions define a pattern for an offload kernel entry point function to be generated to enable execution of a SYCL kernel on a device. A SYCL library implementation orchestrates the invocation of these functions with corresponding SYCL kernel arguments in response to calls to SYCL kernel invocation functions specified by the SYCL 2020 specification. The offload kernel entry point function (sometimes referred to as the SYCL kernel caller function) is generated from the SYCL kernel entry point function by a transformation of the function parameters followed by a transformation of the function body to replace references to the original parameters with references to the transformed ones. Exactly how parameters are transformed will be explained in a future change that implements non-trivial transformations. For now, it suffices to state that a given parameter of the SYCL kernel entry point function may be transformed to multiple parameters of the offload kernel entry point as needed to satisfy offload kernel argument passing requirements. Parameters that are decomposed in this way are reconstituted as local variables in the body of the generated offload kernel entry point function. For example, given the following SYCL kernel entry point function definition: template<typename KernelNameType, typename KernelType> [[clang::sycl_kernel_entry_point(KernelNameType)]] void sycl_kernel_entry_point(KernelType kernel) { kernel(); } and the following call: struct Kernel { int dm1; int dm2; void operator()() const; }; Kernel k; sycl_kernel_entry_point<class kernel_name>(k); the corresponding offload kernel entry point function that is generated might look as follows (assuming `Kernel` is a type that requires decomposition): void offload_kernel_entry_point_for_kernel_name(int dm1, int dm2) { Kernel kernel{dm1, dm2}; kernel(); } Other details of the generated offload kernel entry point function, such as its name and callng convention, are implementation details that need not be reflected in the AST and may differ across target devices. For that reason, only the transformation described above is represented in the AST; other details will be filled in during code generation. These transformations are represented using new AST nodes introduced with this change. `OutlinedFunctionDecl` holds a sequence of `ImplicitParamDecl` nodes and a sequence of statement nodes that correspond to the transformed parameters and function body. `SYCLKernelCallStmt` wraps the original function body and associates it with an `OutlinedFunctionDecl` instance. For the example above, the AST generated for the `sycl_kernel_entry_point<kernel_name>` specialization would look as follows: FunctionDecl 'sycl_kernel_entry_point<kernel_name>(Kernel)' TemplateArgument type 'kernel_name' TemplateArgument type 'Kernel' ParmVarDecl kernel 'Kernel' SYCLKernelCallStmt CompoundStmt <original statements> OutlinedFunctionDecl ImplicitParamDecl 'dm1' 'int' ImplicitParamDecl 'dm2' 'int' CompoundStmt VarDecl 'kernel' 'Kernel' <initialization of 'kernel' with 'dm1' and 'dm2'> <transformed statements with redirected references of 'kernel'> Any ODR-use of the SYCL kernel entry point function will (with future changes) suffice for the offload kernel entry point to be emitted. An actual call to the SYCL kernel entry point function will result in a call to the function. However, evaluation of a `SYCLKernelCallStmt` statement is a no-op, so such calls will have no effect other than to trigger emission of the offload kernel entry point.
- Loading branch information
1 parent
03eb786
commit d021c2b
Showing
34 changed files
with
734 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//===- StmtSYCL.h - Classes for SYCL kernel calls ---------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This file defines SYCL AST classes used to represent calls to SYCL kernels. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_AST_STMTSYCL_H | ||
#define LLVM_CLANG_AST_STMTSYCL_H | ||
|
||
#include "clang/AST/ASTContext.h" | ||
#include "clang/AST/Decl.h" | ||
#include "clang/AST/Stmt.h" | ||
#include "clang/Basic/SourceLocation.h" | ||
|
||
namespace clang { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// AST classes for SYCL kernel calls. | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// SYCLKernelCallStmt represents the transformation that is applied to the body | ||
/// of a function declared with the sycl_kernel_entry_point attribute. The body | ||
/// of such a function specifies the statements to be executed on a SYCL device | ||
/// to invoke a SYCL kernel with a particular set of kernel arguments. The | ||
/// SYCLKernelCallStmt associates an original statement (the compound statement | ||
/// that is the function body) with an OutlinedFunctionDecl that holds the | ||
/// kernel parameters and the transformed body. During code generation, the | ||
/// OutlinedFunctionDecl is used to emit an offload kernel entry point suitable | ||
/// for invocation from a SYCL library implementation. If executed, the | ||
/// SYCLKernelCallStmt behaves as a no-op; no code generation is performed for | ||
/// it. | ||
class SYCLKernelCallStmt : public Stmt { | ||
friend class ASTStmtReader; | ||
friend class ASTStmtWriter; | ||
|
||
private: | ||
Stmt *OriginalStmt = nullptr; | ||
OutlinedFunctionDecl *OFDecl = nullptr; | ||
|
||
public: | ||
/// Construct a SYCL kernel call statement. | ||
SYCLKernelCallStmt(Stmt *OS, OutlinedFunctionDecl *OFD) | ||
: Stmt(SYCLKernelCallStmtClass), OriginalStmt(OS), OFDecl(OFD) {} | ||
|
||
/// Construct an empty SYCL kernel call statement. | ||
SYCLKernelCallStmt(EmptyShell Empty) | ||
: Stmt(SYCLKernelCallStmtClass, Empty) {} | ||
|
||
/// Retrieve the model statement. | ||
Stmt *getOriginalStmt() { return OriginalStmt; } | ||
const Stmt *getOriginalStmt() const { return OriginalStmt; } | ||
void setOriginalStmt(Stmt *S) { OriginalStmt = S; } | ||
|
||
/// Retrieve the outlined function declaration. | ||
OutlinedFunctionDecl *getOutlinedFunctionDecl() { return OFDecl; } | ||
const OutlinedFunctionDecl *getOutlinedFunctionDecl() const { return OFDecl; } | ||
|
||
/// Set the outlined function declaration. | ||
void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) { | ||
OFDecl = OFD; | ||
} | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { | ||
return getOriginalStmt()->getBeginLoc(); | ||
} | ||
|
||
SourceLocation getEndLoc() const LLVM_READONLY { | ||
return getOriginalStmt()->getEndLoc(); | ||
} | ||
|
||
SourceRange getSourceRange() const LLVM_READONLY { | ||
return getOriginalStmt()->getSourceRange(); | ||
} | ||
|
||
static bool classof(const Stmt *T) { | ||
return T->getStmtClass() == SYCLKernelCallStmtClass; | ||
} | ||
|
||
child_range children() { | ||
return child_range(&OriginalStmt, &OriginalStmt + 1); | ||
} | ||
|
||
const_child_range children() const { | ||
return const_child_range(&OriginalStmt, &OriginalStmt + 1); | ||
} | ||
}; | ||
|
||
} // end namespace clang | ||
|
||
#endif |
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
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
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
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
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
Oops, something went wrong.