Skip to content

Conversation

v-klochkov
Copy link
Contributor

Signed-off-by: Vyacheslav N Klochkov [email protected]

@v-klochkov v-klochkov requested a review from a team as a code owner December 21, 2020 21:44
@v-klochkov
Copy link
Contributor Author

This pull request implements the SPEC: #2913
Also, the initial changes for this feature were merged here: #2901

@@ -0,0 +1,110 @@
//===------- ocloc_api.h --------------------------------------------------===//
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@v-klochkov v-klochkov Dec 22, 2020

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

Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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");
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

replied right above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 392cc46

Copy link
Contributor

Choose a reason for hiding this comment

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

same suggestion as above

@v-klochkov
Copy link
Contributor Author

@vladimirlaz , the test on Linux reported "libclangFEWrapper.so: cannot open shared object file: No such file or directory"
because ocloc uses that library if '-cmc' option is passed to it.
I believe libclangFEWrapper.so is part of ONEAPI package. Does CI need some fix? Please advise how to proceed with CM test

…ly ocloc_api.h from git

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
@vladimirlaz
Copy link
Contributor

@vladimirlaz , the test on Linux reported "libclangFEWrapper.so: cannot open shared object file: No such file or directory"
because ocloc uses that library if '-cmc' option is passed to it.
I believe libclangFEWrapper.so is part of ONEAPI package. Does CI need some fix? Please advise how to proceed with CM test

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]>
@AaronBallman
Copy link
Contributor

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:
https://godbolt.org/z/hnhq35
https://godbolt.org/z/TPPnWq
https://godbolt.org/z/vvYEf3
https://godbolt.org/z/4WPzxb

@kbobrovs
Copy link
Contributor

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.

No specific security review was made. What particular security issue do you see - API, scenario?

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
Copy link
Contributor

@keryell keryell left a 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);
Copy link
Contributor

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

Suggested change
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.

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 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 = {});

Copy link
Contributor

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;
}

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@v-klochkov
Copy link
Contributor Author

v-klochkov commented Dec 23, 2020

@vladimirlaz , the test on Linux reported "libclangFEWrapper.so: cannot open shared object file: No such file or directory"
because ocloc uses that library if '-cmc' option is passed to it.
I believe libclangFEWrapper.so is part of ONEAPI package. Does CI need some fix? Please advise how to proceed with CM test

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.

@yamanwan
The test on Windows failed because ocloc64.dll was not found, which is unexpected. ocloc64.dll is expected to be placed together with ocloc.exe. Can this be fixed in CI environment as well, please?

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
@v-klochkov v-klochkov force-pushed the public_vklochkov_online_compiler branch from 5839689 to 893852b Compare December 23, 2020 07:36
@v-klochkov v-klochkov requested a review from kbobrovs December 23, 2020 07:39
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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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);
Copy link
Contributor

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]>
Comment on lines +149 to +150
assert(TestPassed &&
"Failed to throw an exception for unrecognized option");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert(TestPassed &&
"Failed to throw an exception for unrecognized option");

Comment on lines +151 to +152
if (!TestPassed)
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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");
Copy link
Contributor

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);
Copy link
Contributor

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]));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

.

kbobrovs
kbobrovs previously approved these changes Dec 24, 2020
Copy link
Contributor

@kbobrovs kbobrovs left a comment

Choose a reason for hiding this comment

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

LGTM

…ned off on Linux)

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
@v-klochkov v-klochkov force-pushed the public_vklochkov_online_compiler branch from f42dd53 to ee66600 Compare December 24, 2020 21:31
@romanovvlad romanovvlad merged commit 9112252 into intel:sycl Dec 29, 2020
@v-klochkov v-klochkov deleted the public_vklochkov_online_compiler branch February 24, 2023 19:39
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.

8 participants