-
Notifications
You must be signed in to change notification settings - Fork 2
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
Layer MVP #14
base: main
Are you sure you want to change the base?
Layer MVP #14
Conversation
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.
Thanks for the contribution! That'll make the project much more directly useful to the casual user. I've tried to get it to build and run on my Linux machine and faced a number of issues (see changes on https://github.com/kpet/spirv2clc/tree/layer-fixes):
- We will need to build position independent code for *nix. I've already done that on
main
since this also made sense for another PR I've just merged. You will want to rebase past those recent changes. - When running the spirv_new CTS test, I've found a few off-by-one errors in the query handling code (see my branch). After fixing these, the test is still complaining that
CL_DEVICE_IL_VERSION_KHR
is not supported. What tests have you run? I think passing spirv_new (as much as the translator itself allows that is) is a good target for merging this PR.
Lastly, I've had a cursory look at the code. Nothing really surprising, certainly not in a bad way :). I've left a few comments.
lib/layer.cpp
Outdated
else | ||
return false; | ||
} else { | ||
if (err != nullptr) |
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.
Maybe you could require err
to be non-nullptr
to avoid having to check everywhere.
lib/layer.cpp
Outdated
if (err != nullptr) | ||
*err = CL_SUCCESS; | ||
return false; | ||
} |
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.
Early returns might make the code easier to read.
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'm not too happy with the deep nesting of code as well. Personally I'm in favor of making the "happy path" of code as straightforward as possible, and error handling be centrallized, or in some other way "out of sight" not to increase noise. I'm not a big fan of the goto-style error handling what the C samples exhibit, but it does tick all the boxes for me. (It's manual exception handling, really.) I was thinking of using the C++ API here, but that wraps the global namespace API and not the dispatch table. This use case mildly resembles this issue (that refers to the wrapping name, not the wrapped contents), but we may be able to hit two birds with one stone.
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'm not advocating for goto and I don't think you'd need goto's here. I think early returns would work well:
err = call();
if (err != SUCCESS) {
return err;
}
err = call2();
...
Granted that means the "happy path" is cluttered with error checking code but I think it would still be easier to read.
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 put some early returns in the code to make it easier to read.
lib/layer.cpp
Outdated
|
||
cl_program layer::clCreateProgramWithIL(cl_context context, const void *il, | ||
size_t length, cl_int *errcode_ret) { | ||
spirv2clc::translator translator; |
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.
It doesn't practically matter for now but we'll have to think about how to select the OpenCL version used for the translation. If you don't want to address this in this first PR, I suggest you leave a TODO.
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.
Added.
lib/layer.cpp
Outdated
#include <algorithm> | ||
#include <iterator> | ||
#include <map> | ||
#include <regex> |
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 this is unused
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.
Removed. (algorithm is needed, std::copy
is invoked.
lib/layer.cpp
Outdated
return tdispatch->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, | ||
param_value_size, param_value, | ||
param_value_size_ret); | ||
} 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.
The else and nesting are unnecessary.
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.
Removed.
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.
Just to be clear: that comment applies to several locations in the code. I just pointed out one occurrence.
Indeed, I've glossed over the difference in the query name difference when core or KHR. I have little experience running CTS tests, so if you think it's okay, I may add tests which make use of the layer. |
I think you might need to add support for extension function queries as well. Applications that target the extension will be using these.
I'm certainly not opposed to adding more tests :). |
@kpet Could you elaborate on the off-by-one fixes in this commit? The only error I see in my ways is not accounting for the extra null-terminator I append to the extensions string because I append a literal and that has a null at the end. The best fix I see is |
So what I observed and hacked through was (in line order of my commit):
|
@MathiasMagnus FYI C++17 is now the default (see #21) |
I pushed some WIP to show the initiative is not dead. There is an ICD initiate of sorts which is prepared to behave in one of multiple ways to test whether the layer activates when it should. Ultimately it will be able to behave as a 1.x, 2.y and 3.0 ICD with or without core/extension support for SPIR-V. A sample executable will feed SPIR-V programs using the approrpiate APIs and with the layer being put into tracing mode (still missing) it will check whether the layer activated or not as expected. (It is my first time writing an ICD from scratch, and even the ICD-Loader stub driver isn't the best source of inspiration, as it's doing a lot of extra work, seemingly due to |
97d31fa
to
aebb260
Compare
@kpet Is there anything else to be done here? Last I left this PR here it looked to me everything got addressed. Since then main has progressed to diverge. Were there any comments needing triage? I'll have some time to dedicate to it in the coming days if you can say what's left to do. |
This is an MVP of a layer wrapping the translator library. Some of the features:
cl_khr_il_program
extension.I don't have proper tests in place, but it seems to function fine atop AMD's, Microsoft's and Intel's CPU runtime. Tested on Windows.
(I do have toy CTest support setup on my end, but I'd like to polish it further to make it easier to add new tests and testing more robust in general.)