-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL] Implement INTEL feature class online_compiler #2930
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] Implement INTEL feature class online_compiler #2930
Conversation
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
@@ -0,0 +1,110 @@ | |||
//===------- ocloc_api.h --------------------------------------------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to copy this header into SYCL rather than reusing the existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative solution requires pulling the whole https://github.com/intel/compute-runtime workspace just for the purpose of using this one ocloc_api.h header seems excessive. Do you agree?
Or did you suggest something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pulling just this header from https://github.com/intel/compute-runtime is enough. For example, SYCL uses OpenCL headers to build, and pulls in just the headers, not the entire repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot pull one file from repo. Git does not provide such functionality. Using other tools is not safe.
For OpenCL headers we pull the whole workspace: https://github.com/KhronosGroup/OpenCL-Headers.git
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Looks like this is necessary evil (duplication of the source) then :(
} | ||
} | ||
|
||
template <cl::sycl::INTEL::source_language Lang> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'll remove this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 392cc46
else | ||
std::cerr << "Unexpected exception: " << Msg << "\n"; | ||
} | ||
assert(TestPassed && "Failed to throw an exception for wrong program"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, can you elaborate this comment please? The commend above seems unrelated to this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replied right above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 392cc46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same suggestion as above
@vladimirlaz , the test on Linux reported "libclangFEWrapper.so: cannot open shared object file: No such file or directory" |
…ly ocloc_api.h from git Signed-off-by: Vyacheslav N Klochkov <[email protected]>
it looks like a gap in dependencies configuration (some libraries are missed for GPU RT or ocloc package used as dependency). @yamanwan could you please make sure that all libraries required for dependencies are available for testing. |
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
Just a drive-by question -- has this undergone any sort of security review? This sure smells like an easy attack vector given that the compiler has specific syntax for causing controlled crashes. (I recall Matt Godbolt saying he eventually gave up on trying to harden compiler explorer over exactly these sort of problems -- he spins up a VM that expects to get trashed by users and automatically resets itself if a watcher process notices the VM has gone bad.) Some examples: |
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
No specific security review was made. What particular security issue do you see - API, scenario? |
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the test here gives a nice way to program in OpenCL using the SYCL program, I think it worth the effort to simplify the code sample to the maximum, as it might be copied again and again forever in user code or tutorials...
return std::vector<byte>{}; | ||
} | ||
__SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile( | ||
const std::string &src, const std::vector<std::string> &options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling that
const std::string &src, const std::vector<std::string> &options); | |
const std::string &src, const std::vector<std::string> &options = {}); |
would make the first overload useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I surely thought about doing that, but it doesn't work and the attempt to add the default argument, then remove the overload accepting only 'src' causes this error during SYCL build phase:
llvm/sycl/include/CL/sycl/INTEL/online_compiler.hpp:195:73: error: default argument specified in explicit specialization [ -fpermissive ]
const std::string &src, const std::vector< std::string > &options = {});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, because you have the main definition as
template <typename... Tys>
std::vector<byte> compile(const std::string &src, const Tys &... args);
you cannot add this default parameter there either.
Actually I am even surprised that it is possible to specialize a variadic argument by a non variadic one...
But, at the end, why do you need to declare some super generic compile()
that you do not really use, instead of having extensions just adding incrementally the overload they want?
I have the feeling that this specialization just adds some complexity for nothing valuable.
And the variadic template derail some simple implementations like:
https://godbolt.org/z/Yfo9bd
#include <iostream>
#include <string>
#include <vector>
struct a {
template <typename... Types>
static void compile(Types... args) {
std::cout << "the generic default" << std::endl;
}
static void compile(std::string arg, std::vector<std::string> args = {}) {
std::cout << "single arg with vector" << std::endl;
}
};
int main() {
// This one is captured by the generic default because a `const char*` is not a `std::string`, but do we need this at all?
a::compile("default");
a::compile(std::string{});
a::compile(std::string{}, {"opt"});
a::compile("", {"opt"});
a::compile(std::string{}, {});
a::compile(std::string{}, {"opt"});
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, at the end, why do you need to declare some super generic compile() that you do not really use, instead of having extensions just adding incrementally the overload they want?
I have the feeling that this specialization just adds some complexity for nothing valuable.
And the variadic template derail some simple implementations like:
https://godbolt.org/z/Yfo9bd
@kbobrovs , is the one who wrote the feature SPEC, perhaps Konst can answer your question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assumption here is that different languages may have very different parameter sets for compile. Variadic templates provide the needed freedom. Concrete specializations fix variants used for particular language.
To avoid "derailing" mentioned above, we simply don't provide compile
specialization pairs which conflict in that way.
Overloading is surely an option too, but some overloads will be unavailable for certain languages, which adds confusion. Isn't variadic template is ok C++ way to go when parameter list can be arbitrary?
Adding @Pennycook and @rolandschulz for possible comments.
@yamanwan |
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
5839689
to
893852b
Compare
OCLOC_VERSION_1_0 = OCLOC_MAKE_VERSION(1, 0), ///< version 1.0 | ||
OCLOC_VERSION_CURRENT = OCLOC_MAKE_VERSION(1, 0), ///< latest known version | ||
OCLOC_VERSION_FORCE_UINT32 = 0x7fffffff | ||
} ocloc_version_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this code, perhaps it could be modernized upstream too if it is C++ by replacing OCLOC_MAKE_VERSION
by a constexpr
function in some nice namespace
and the enum
a C++ one without the typedef
.
But this would be outside of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be done. The alternative to modernizing the file is keeping it as close to the original as possible to make it easier follow the changes in the original file.
I did only clang-format changes over the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To give more context for others: this file is copied from the underlying Gen driver source base. See the discussion above.
return std::vector<byte>{}; | ||
} | ||
__SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile( | ||
const std::string &src, const std::vector<std::string> &options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, because you have the main definition as
template <typename... Tys>
std::vector<byte> compile(const std::string &src, const Tys &... args);
you cannot add this default parameter there either.
Actually I am even surprised that it is possible to specialize a variadic argument by a non variadic one...
But, at the end, why do you need to declare some super generic compile()
that you do not really use, instead of having extensions just adding incrementally the overload they want?
I have the feeling that this specialization just adds some complexity for nothing valuable.
And the variadic template derail some simple implementations like:
https://godbolt.org/z/Yfo9bd
#include <iostream>
#include <string>
#include <vector>
struct a {
template <typename... Types>
static void compile(Types... args) {
std::cout << "the generic default" << std::endl;
}
static void compile(std::string arg, std::vector<std::string> args = {}) {
std::cout << "single arg with vector" << std::endl;
}
};
int main() {
// This one is captured by the generic default because a `const char*` is not a `std::string`, but do we need this at all?
a::compile("default");
a::compile(std::string{});
a::compile(std::string{}, {"opt"});
a::compile("", {"opt"});
a::compile(std::string{}, {});
a::compile(std::string{}, {"opt"});
return 0;
}
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
assert(TestPassed && | ||
"Failed to throw an exception for unrecognized option"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(TestPassed && | |
"Failed to throw an exception for unrecognized option"); |
if (!TestPassed) | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!TestPassed) | |
return 1; | |
if (!TestPassed) { | |
std::cerr << "Failed to throw an expected exception for unrecognized option\n"; | |
return 1; | |
} |
else | ||
std::cerr << "Unexpected exception: " << Msg << "\n"; | ||
} | ||
assert(TestPassed && "Failed to throw an exception for wrong program"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same suggestion as above
#else | ||
static const std::string OclocLibraryName = "libocloc.so"; | ||
#endif | ||
void *OclocLibrary = sycl::detail::pi::loadOsLibrary(OclocLibraryName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
std::memcpy(SpirV, Outputs[I], SpirVSize); | ||
} else if (!strcmp(OutputNames[I], "stdout.log")) { | ||
CompileLog = std::string(reinterpret_cast<const char *>(Outputs[I])); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
…s with exception.hpp Signed-off-by: Vyacheslav N Klochkov <[email protected]>
…ned off on Linux) Signed-off-by: Vyacheslav N Klochkov <[email protected]>
f42dd53
to
ee66600
Compare
Signed-off-by: Vyacheslav N Klochkov [email protected]