Skip to content

add UR loader, null adapter and basic example #93

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 1 commit into from
Dec 9, 2022

Conversation

pbalcer
Copy link
Contributor

@pbalcer pbalcer commented Dec 7, 2022

The components this patch implements are mostly derived from the ones implemented by level-zero.

This patch otherwise makes only the minimal amount of changes required for loader:

  • adds new CI that builds the loader
  • updates cmake scripts to build and install the loader
  • adds generate and check-generated custom cmake targets
  • adds a tiny hello-world example to verify loader functionality

Co-authored-by: Brandon Yates brandon.yates@intel.com
Co-authored-by: Lisanna Dettwyler lisanna.dettwyler@intel.com
Co-authored-by: Patryk Kaminski patryk.kaminski@intel.com
Co-authored-by: Krzysztof Swiecicki krzysztof.swiecicki@intel.com

run: cmake --build ${{github.workspace}}/build --target check-generated --config ${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Copy link
Contributor

Choose a reason for hiding this comment

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

For me this --config param doesn't change anything. What is relevant here for setting up debug or release build is the -DCMAKE_BUILD_TYPE argument which you added in the previous step.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe --config is important when using the Visual Studio project generator. This will be defaulting to the Unix Makefiles generation though.

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 used a template :) I'll remove that config part. Windows is probably going to need its own separate job anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.gitignore Outdated
@@ -53,6 +53,9 @@
# Debug files
scripts/**/*.json

# Python cache
scripts/templates/__pycache__/
Copy link
Contributor

Choose a reason for hiding this comment

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

This dir can be generated in scripts/, too. Maybe generalize this to sth like scripts/**/__pycache__/?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


**General**:

If you've made modifications to the specification, you can also run a custom `generate` target prior to building.
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 it's better to move this section to be one of the first ones, so this will be something that the user will try using first instead of doing this the hard way (by figuring out which script should be run and with which params, see Source Code Generation section and the linked README).

@kbenzie
Copy link
Contributor

kbenzie commented Dec 7, 2022

Its going to take me a whole to review this and I have a busy day today, I'll get back to it tomorrow.

@pbalcer
Copy link
Contributor Author

pbalcer commented Dec 7, 2022

No rush - I know it's a huge PR, but I think it's the bare minimum that makes sense. Thankfully most of it is automatically generated...

}
static const size_t DEVICE_NAME_MAX_LEN = 1024;
char device_name[DEVICE_NAME_MAX_LEN] = {0};
status = urDeviceGetInfo(d, UR_DEVICE_INFO_NAME, DEVICE_NAME_MAX_LEN - 1, static_cast<void *>(&device_name), nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be extended by the check on the actual device name length returned from this function (with a last parameter).

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'd rather keep the example short. Checking the length here doesn't add much - device_name will be a valid NULL-terminated C string, which cout should output correctly.

In a test, on the other hand, we should verify that if this function returns success, the name is populated with a non-zero length string.

if args.loader:
generate_code.generate_loader(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.layers:
generate_code.generate_layers(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no generate_layers() in generate_code module. Safe to remove this call?

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 don't want to remove it entirely since we will be adding the layer functionality soon. I commented out these lines, so it's impossible to call this a non-existent method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* SPDX-License-Identifier: MIT
*
*/
#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

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

Although this is probably supported by almost any compiler, I think it is still non-standard, so it might be better to favour a traditional #ifndef guard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


//////////////////////////////////////////////////////////////////////////
/// a abstract factory for creation of singleton objects
template<typename _singleton_t, typename _key_t>
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 prefixing types with _ is UB since they are reserved by the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/

#if defined(__cplusplus)
#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

env = getenv(name);
#endif

if( ( nullptr == env ) || ( 0 == strcmp( "0", env ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think ( 0 == strcmp( "0", env ) ) is neccesarry here since we do return ( 0 == strcmp( "1", env ) ); on the line below which will return false if env is 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.

Good catch :) Done

auto key = getKey( std::forward<Ts>( _params )... );

if(key == 0) // No zero keys allowed in map
return static_cast<_singleton_t*>(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to always have {} in any control flow statements.

Copy link
Contributor Author

@pbalcer pbalcer Dec 8, 2022

Choose a reason for hiding this comment

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

That's my preference as well. But I refrained from making any stylistic changes (the coding style is all over the place :-)). I suggest we pick a single style and enforce it with clang-format (we were planning on doing that soon after this PR was merged).

I can do it with this PR, but a) it might conflict with the generated files, so it's not trivial addition, and b) it would probably affect the entire repo, not just the loader, so might clutter the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we have an issue to track these changes linked here, I'd be happy for them to be addressed in a future 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.

Done. I'll add an issue about adding style checking to the build system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressing them in a future issue works for me 👍

* @file ur_lib.h
*
*/
#pragma once
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 we should use #ifndef here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* SPDX-License-Identifier: MIT
*
*/
#pragma once
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 we should use #ifndef here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* @file ur_object.h
*
*/
#pragma once
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 we should use #ifndef here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*
*/

#include "../ur_lib.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to avoid relative file paths here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*
*/

#include "../ur_loader.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@kbenzie kbenzie left a comment

Choose a reason for hiding this comment

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

Besides the minor things which could be addressed later, I think this looks good.

@pbalcer pbalcer force-pushed the ur-rebase branch 2 times, most recently from 0a22152 to 05280a9 Compare December 8, 2022 14:31
@pbalcer
Copy link
Contributor Author

pbalcer commented Dec 8, 2022

In addition to the review commits, I needed to address the conflicting workflow change that verified the python module. So I added a test/python/basic.py test that runs in the new cmake workflow. Once #94 is merged, we can modify that test to instantiate the UR_DDI class, and it should just work.

@pbalcer pbalcer force-pushed the ur-rebase branch 2 times, most recently from 1159f4b to 76173e7 Compare December 8, 2022 15:54
Copy link
Contributor

@FranklandJack FranklandJack left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments I've made - LGTM.

@pbalcer pbalcer force-pushed the ur-rebase branch 2 times, most recently from 40e896d to 2b6e5c3 Compare December 8, 2022 16:03
The components this patch implements are mostly derived from
the ones implemented by level-zero.

This patch otherwise makes only the minimal amount of changes
required for loader:
 - adds new CI that builds the loader
 - updates cmake scripts to build and install the loader
 - adds generate and check-generated custom cmake targets
 - adds a tiny hello-world example to verify loader functionality

Co-authored-by: Brandon Yates <brandon.yates@intel.com>
Co-authored-by: Lisanna Dettwyler <lisanna.dettwyler@intel.com>
Co-authored-by: Patryk Kaminski <patryk.kaminski@intel.com>
Co-authored-by: Krzysztof Swiecicki <krzysztof.swiecicki@intel.com>
@pbalcer pbalcer merged commit 7ef04f9 into oneapi-src:main Dec 9, 2022
git diff
exit 1
fi
cd ../include
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this check get lost in the move to doing this in CMake?

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.

4 participants