Skip to content

[MLIR][CAPI] add C API typedef to fix downstream C API usage #135380

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
Apr 11, 2025

Conversation

bangtianliu
Copy link
Contributor

@bangtianliu bangtianliu commented Apr 11, 2025

This PR is after #135253 and #134935 to fix the error reported by #135253 (comment). This PR Adds typedef declarations for MlirLinalgContractionDimensions and MlirLinalgConvolutionDimensions in the C API to ensure compatibility with pure C code.

I confirm that this fix resolves the reported error based on my testing.

@llvmbot llvmbot added the mlir label Apr 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 11, 2025

@llvm/pr-subscribers-mlir

Author: Bangtian Liu (bangtianliu)

Changes

This PR is after #135253 and #134935 to fix the error reported by #135253 (comment). This PR Adds typedef declarations for MlirLinalgContractionDimensions and MlirLinalgConvolutionDimensions in the C API to ensure compatibility with pure C code.

I confirm that this fix resolves the reported error based on my testing.


Full diff: https://github.com/llvm/llvm-project/pull/135380.diff

1 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/Linalg.h (+4-4)
diff --git a/mlir/include/mlir-c/Dialect/Linalg.h b/mlir/include/mlir-c/Dialect/Linalg.h
index 838c280903e2e..4f2ee0d434222 100644
--- a/mlir/include/mlir-c/Dialect/Linalg.h
+++ b/mlir/include/mlir-c/Dialect/Linalg.h
@@ -24,19 +24,19 @@ mlirLinalgFillBuiltinNamedOpRegion(MlirOperation mlirOp);
 
 MLIR_CAPI_EXPORTED bool mlirLinalgIsAContractionOp(MlirOperation op);
 
-struct MlirLinalgContractionDimensions {
+typedef struct MlirLinalgContractionDimensions {
   MlirAttribute batch;
   MlirAttribute m;
   MlirAttribute n;
   MlirAttribute k;
-};
+} MlirLinalgContractionDimensions;
 
 MLIR_CAPI_EXPORTED MlirLinalgContractionDimensions
 mlirLinalgInferContractionDimensions(MlirOperation op);
 
 MLIR_CAPI_EXPORTED bool mlirLinalgIsAConvolutionOp(MlirOperation op);
 
-struct MlirLinalgConvolutionDimensions {
+typedef struct MlirLinalgConvolutionDimensions {
   MlirAttribute batch;
   MlirAttribute outputImage;
   MlirAttribute outputChannel;
@@ -45,7 +45,7 @@ struct MlirLinalgConvolutionDimensions {
   MlirAttribute depth;
   MlirAttribute strides;
   MlirAttribute dilations;
-};
+} MlirLinalgConvolutionDimensions;
 
 MLIR_CAPI_EXPORTED MlirLinalgConvolutionDimensions
 mlirLinalgInferConvolutionDimensions(MlirOperation op);

@kuhar kuhar requested review from kuhar and makslevental April 11, 2025 14:35
@nikic nikic changed the title [CAPI] add C API typedef to fix downstream C API usage [MLIR][CAPI] add C API typedef to fix downstream C API usage Apr 11, 2025
Copy link
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

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

personally I prefer to just write struct and eschew typedef but I realize I've gotta be the only person in the world that feels that way :)

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

LGTM. This seems consistent with how other C sturcts are defined, e.g.:

struct name { \
storage *ptr; \
}; \
typedef struct name name

@kuhar kuhar merged commit 76b85d3 into llvm:main Apr 11, 2025
13 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…5380)

This PR is after llvm#135253 and llvm#134935 to fix the error reported by
llvm#135253 (comment).
This PR Adds typedef declarations for `MlirLinalgContractionDimensions`
and `MlirLinalgConvolutionDimensions` in the C API to ensure
compatibility with pure C code.

I confirm that this fix resolves the reported error based on my testing.

Signed-off-by: Bangtian Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants