Skip to content

[rocisa] Use comgr instead of calling amdclang++ #1952

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

KKyang
Copy link
Contributor

@KKyang KKyang commented Apr 18, 2025

Use comgr C API instead of calling amdclang++ directly.

@KKyang KKyang changed the title [rocisa] Use comgr instead of subprocess [rocisa] Use comgr instead Apr 18, 2025
@KKyang KKyang changed the title [rocisa] Use comgr instead [rocisa] Use comgr instead of calling amdclang++ Apr 18, 2025
hcman2
hcman2 previously approved these changes Apr 18, 2025
Copy link
Contributor

@hcman2 hcman2 left a comment

Choose a reason for hiding this comment

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

ok if ci pass

Copy link
Contributor

@stellaraccident stellaraccident left a comment

Choose a reason for hiding this comment

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

Let's land #1951 first since that introduces a structural improvement.

This needs more work to not leak and be exception safe and should be implemented in the helper.cpp introduced in the above.

Also, please don't land those cmake changes to rocm_path. I couldn't follow why they were needed so we can discuss more what the intent is.

// Create data set and add the input data
CHECK_COMGR(amd_comgr_create_data_set(&dataSet));
CHECK_COMGR(amd_comgr_create_data_set(&outputDataSet));
CHECK_COMGR(amd_comgr_data_set_add(dataSet, data));
Copy link
Contributor

@stellaraccident stellaraccident Apr 18, 2025

Choose a reason for hiding this comment

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

What happens if any of these get an error and throw? As I read it, every one of them leaks memory.

You need to rewrite this so that your allocated entities are contained by a raii instance that will deallocate any allocated things on destruction. See #1951 for one (of many) ways you can do this to bridge to a c based API safely.

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'll change to unique_ptr instead

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that is a good way: these have explicit apis for create/release and do not have the same semantics as delete with respect to nullptr afaict. But I'll have a look at what you come up with.

@KKyang
Copy link
Contributor Author

KKyang commented Apr 18, 2025

Merge after #1951 is merged

@KKyang KKyang marked this pull request as draft April 18, 2025 11:36
@KKyang KKyang force-pushed the comgr branch 3 times, most recently from 4d47f27 to 70046a7 Compare April 21, 2025 02:40
@KKyang KKyang marked this pull request as ready for review April 21, 2025 02:40
@KKyang KKyang force-pushed the comgr branch 2 times, most recently from d51a5ee to e1c0a12 Compare April 21, 2025 03:59
@stellaraccident
Copy link
Contributor

I tested this on Windows, and indeed, we are going to need more work there. The issue is that you can't just have a cross-filesystem dep on a DLL like this (which is what a Python extension is) without making arrangements for how to find it at runtime (i.e. there is no RPATH on Windows).

ImportError: DLL load failed while importing rocisa: The specified module could not be found.

The Python frameworks solve this in one of two ways:

  1. Bundle ROCm as a sibling to the Python binary distribution in a way that it can be found. PyTorch does this in the current version and it is as invasive as it sounds.
  2. Use a Python level pre-loading mechanism to load the necessary DLLs prior to importing the Python extension (which links to DLLs by name). This is what CUDA based dependencies do and what ROCm based PyTorch will do in the next version.

Neither option is particularly satisfying for this kind of situation. In this case, since it is a build-only dep, we would most likely want to emulate the Linux RPATH mechanic to ensure the DLL is loaded properly. However, doing that properly will require a bit more pre-work.

Could we put this change on ice for a little while? I know roughly how to enable it but have other priorities right this minute and would like to come up with a mechanism that will work for any ROCm project vs just a one off. If this becomes urgent, I could do something project specific in a few hours if needed.

Copy link
Contributor

@stellaraccident stellaraccident left a comment

Choose a reason for hiding this comment

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

Marking request changes per the above discussion. We can apply this once a bit more work is done on the windows side.

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