-
Notifications
You must be signed in to change notification settings - Fork 70
Opencl set for kernel args #589
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
91d21cf
Parse pipeline SET command for OpenCL POD args
alan-baker e071c49
Simple struct to record set commands
alan-baker f965a67
Generate the PoD argument buffers
alan-baker 1ddba45
Fixes and improvements
alan-baker 973fecb
Add end-to-end test
alan-baker 18ffd5f
Document SET command
alan-baker cafb9fe
formatting and build fix
alan-baker 9d18cdb
formatting
alan-baker 6a9e0c0
changes for review
alan-baker 7178031
Changes for review
alan-baker 2878fab
explanatory comment
alan-baker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,245 @@ | ||
| // Copyright 2019 The Amber Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or parseried. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "gtest/gtest.h" | ||
| #include "src/amberscript/parser.h" | ||
|
|
||
| namespace amber { | ||
| namespace amberscript { | ||
|
|
||
| using AmberScriptParserTest = testing::Test; | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingKernel) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET ARG_NAME a AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: missing KERNEL in SET command", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingArgName) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL a AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected ARG_NAME or ARG_NUMBER", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingArgIdentifier) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: missing AS in SET command", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingArgIdentifierNumber) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NUMBER AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected argument number", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingAs) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME a uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: missing AS in SET command", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingDataType) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME a AS 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected data type", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetMissingDataValue) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME a AS uint32 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("8: expected data value", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetExtraTokens) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME a AS uint32 0 BLAH | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: extra parameters after SET command", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetArgNameNotString) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME 0 AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected argument identifier", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetArgNumberNotInteger) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NUMBER 1.0 AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected argument number", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetDataTypeNotString) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NUMBER 0 AS 0 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected data type", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetDataValueString) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader OPENCL-C | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NUMBER 0 AS uint32 data | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: expected data value", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, OpenCLSetWrongShaderFormat) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader SPIRV-ASM | ||
| #shader | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader | ||
| SET KERNEL ARG_NAME arg_a AS uint32 0 | ||
| END | ||
| )"; | ||
|
|
||
| Parser parser; | ||
| auto r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("7: SET can only be used with OPENCL-C shaders", r.Error()); | ||
| } | ||
|
|
||
| } // namespace amberscript | ||
| } // namespace amber | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we test that SET is called on an OPENCL-C shader type?
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 way the buffers are generated, the information in the SET is ignored if the shader is not an OPENCL-C shader. Would you prefer an error to that behaviour?
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.
My concern is that you either set the shader type wrong, or are trying to use set for something it isn't designed for at this point. So, even though it will do nothing, I think it would be useful to generate an error to say something along the lines of "SET must be used with OPENCL shaders`
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.
Ok, I'll add an error.