Skip to content

Commit 4293d1a

Browse files
Automatically wrap Metal and MPS headers (feat. Properties) (#526)
* Stray `!= nothing` * @objcwrapper generation * @objcwrappers MTL * @objcwrapper MPS * Version gates immutable by default * Allow overriding supertypes * Reduce indentation * Change toml api format * Enable ObjCProperties type override * Comment out objcproperties blocks * Slightly breaking changes due to some instance methods previously disguised as properties * Wrap properties * Update README.md * Minor fixes * Switch to Runic.jl for post-wrapper formatting * Fix loading on unsupported platforms (again) * Bump ObjectiveC.jl compat * `api.propertytype.<name>` -> `api.<name>.proptype` * Refactor for consistency * Manually define struct constructors * Remove old `@objcproperties` declarations
1 parent e85bf52 commit 4293d1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4210
-709
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ KernelAbstractions = "0.9.1"
4242
LLVM = "7.2, 8, 9"
4343
LLVMDowngrader_jll = "0.6"
4444
LinearAlgebra = "1"
45-
ObjectiveC = "3.2"
45+
ObjectiveC = "3.3"
4646
PrecompileTools = "1"
4747
Preferences = "1"
4848
Printf = "1"

lib/mps/command_buf.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@
44
# - intermediate commits during encoding of MPS work using `commitAndContinue`
55
#
66

7-
# XXX: Not actually inheritance but MPSCommandBuffer conforms to MTLCommandBuffer protocol
8-
@objcwrapper MPSCommandBuffer <: MTLCommandBuffer
9-
10-
@objcproperties MPSCommandBuffer begin
11-
# Identifying the Command Buffer
12-
@autoproperty commandBuffer::id{MTLCommandBuffer}
13-
# @autoproperty heapProvider::id{MPSHeapProvider}
14-
# @autoproperty predicate::id{MPSPredicate}
15-
@autoproperty rootCommandBuffer::id{MTLCommandBuffer}
16-
end
7+
# @objcwrapper MPSCommandBuffer <: MTLCommandBuffer
178

189
function MPSCommandBuffer(commandBuffer::MTLCommandBuffer)
1910
handle = @objc [MPSCommandBuffer commandBufferWithCommandBuffer:commandBuffer::id{MTLCommandBuffer}]::id{MPSCommandBuffer}

lib/mps/copy.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export MPSMatrixCopyDescriptor
44

5-
@objcwrapper MPSMatrixCopyDescriptor <: NSObject
5+
# @objcwrapper MPSMatrixCopyDescriptor <: NSObject
66

77
function MPSMatrixCopyDescriptor(sourceMatrix, destinationMatrix, offsets = MPSMatrixCopyOffsets(Cuint(0), Cuint(0), Cuint(0), Cuint(0)))
88
desc = @objc [MPSMatrixCopyDescriptor descriptorWithSourceMatrix:sourceMatrix::id{MPSMatrix}
@@ -16,14 +16,7 @@ end
1616

1717
export MPSMatrixCopy, encode!
1818

19-
@objcwrapper immutable=false MPSMatrixCopy <: MPSKernel
20-
21-
@objcproperties MPSMatrixCopy begin
22-
@autoproperty copyRows::NSUInteger
23-
@autoproperty copyColumns::NSUInteger
24-
@autoproperty sourcesAreTransposed::Bool
25-
@autoproperty destinationsAreTransposed::Bool
26-
end
19+
# @objcwrapper immutable=false MPSMatrixCopy <: MPSKernel
2720

2821
function MPSMatrixCopy(dev, copyRows, copyColumns, sourcesAreTransposed, destinationsAreTransposed)
2922
kernel = @objc [MPSMatrixCopy alloc]::id{MPSMatrixCopy}

lib/mps/decomposition.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export MPSMatrixDecompositionLU, encode!
44

5-
@objcwrapper immutable=false MPSMatrixDecompositionLU <: MPSMatrixUnaryKernel
5+
# @objcwrapper immutable=false MPSMatrixDecompositionLU <: MPSMatrixUnaryKernel
66

77
function MPSMatrixDecompositionLU(dev, rows, columns)
88
kernel = @objc [MPSMatrixDecompositionLU alloc]::id{MPSMatrixDecompositionLU}
@@ -27,7 +27,7 @@ end
2727

2828
export MPSMatrixDecompositionCholesky, encode!
2929

30-
@objcwrapper immutable=false MPSMatrixDecompositionCholesky <: MPSMatrixUnaryKernel
30+
# @objcwrapper immutable=false MPSMatrixDecompositionCholesky <: MPSMatrixUnaryKernel
3131

3232
function MPSMatrixDecompositionCholesky(dev, lower, order)
3333
kernel = @objc [MPSMatrixDecompositionCholesky alloc]::id{MPSMatrixDecompositionCholesky}

lib/mps/images.jl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
## kernels
22

3-
@objcwrapper immutable=false MPSUnaryImageKernel <: MPSKernel
4-
5-
@objcproperties MPSUnaryImageKernel begin
6-
@autoproperty offset::MPSOffset
7-
@autoproperty clipRect::MTLRegion
8-
@autoproperty edgeMode::MPSImageEdgeMode setter=setEdgeMode
9-
end
3+
# @objcwrapper immutable=false MPSUnaryImageKernel <: MPSKernel
104

115
function encode!(cmdbuf::MTLCommandBuffer, kernel::K, sourceTexture::MTLTexture, destinationTexture::MTLTexture) where {K<:MPSUnaryImageKernel}
126
@objc [kernel::id{K} encodeToCommandBuffer:cmdbuf::id{MTLCommandBuffer}
@@ -21,22 +15,13 @@ end
2115
# fallbackCopyAllocator:copyAllocator::MPSCopyAllocator]::Bool
2216
# end
2317

24-
@objcwrapper immutable=false MPSBinaryImageKernel <: MPSKernel
25-
26-
@objcproperties MPSBinaryImageKernel begin
27-
@autoproperty primaryOffset::MPSOffset
28-
@autoproperty secondaryOffset::MPSOffset
29-
@autoproperty primaryEdgeMode::MPSImageEdgeMode
30-
@autoproperty secondaryEdgeMode::MPSImageEdgeMode
31-
@autoproperty clipRect::MTLRegion
32-
end
33-
18+
# @objcwrapper immutable=false MPSBinaryImageKernel <: MPSKernel
3419

3520
## gaussian blur
3621

3722
export MPSImageGaussianBlur, encode!
3823

39-
@objcwrapper immutable=false MPSImageGaussianBlur <: MPSUnaryImageKernel
24+
# @objcwrapper immutable=false MPSImageGaussianBlur <: MPSUnaryImageKernel
4025

4126
function MPSImageGaussianBlur(dev, sigma)
4227
kernel = @objc [MPSImageGaussianBlur alloc]::id{MPSImageGaussianBlur}
@@ -52,7 +37,7 @@ end
5237

5338
export MPSImageBox
5439

55-
@objcwrapper immutable=false MPSImageBox <: MPSUnaryImageKernel
40+
# @objcwrapper immutable=false MPSImageBox <: MPSUnaryImageKernel
5641

5742
function MPSImageBox(dev, kernelWidth, kernelHeight)
5843
kernel = @objc [MPSImageBox alloc]::id{MPSImageBox}

lib/mps/kernel.jl

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,13 @@
22
# kernels
33
#
44

5-
@objcwrapper MPSKernel <: NSObject
6-
7-
@objcproperties MPSKernel begin
8-
@autoproperty options::MPSKernelOptions setter=setOptions
9-
@autoproperty device::id{MTLDevice}
10-
@autoproperty label::id{NSString} setter=setLabel
11-
end
5+
# @objcwrapper MPSKernel <: NSObject
126

137
@autoreleasepool function Base.copy(kernel::K) where {K <: MPSKernel}
148
obj = @objc [kernel::MPSKernel copy]::id{MPSKernel}
159
K(reinterpret(id{K}, obj))
1610
end
1711

18-
@objcwrapper immutable=false MPSMatrixUnaryKernel <: MPSKernel
19-
20-
@objcproperties MPSMatrixUnaryKernel begin
21-
@autoproperty sourceMatrixOrigin::id{MTLOrigin} setter=setSourceMatrixOrigin
22-
@autoproperty resultMatrixOrigin::id{MTLOrigin} setter=setResultMatrixOrigin
23-
@autoproperty batchStart::NSUInteger setter=setBatchStart
24-
@autoproperty batchSize::NSUInteger setter=setBatchSize
25-
end
12+
# @objcwrapper immutable=false MPSMatrixUnaryKernel <: MPSKernel
2613

27-
28-
@objcwrapper immutable=false MPSMatrixBinaryKernel <: MPSKernel
29-
30-
@objcproperties MPSMatrixBinaryKernel begin
31-
@autoproperty primarySourceMatrixOrigin::id{MTLOrigin} setter=setPrimarySourceMatrixOrigin
32-
@autoproperty secondarySourceMatrixOrigin::id{MTLOrigin} setter=setSecondarySourceMatrixOrigin
33-
@autoproperty resultMatrixOrigin::id{MTLOrigin} setter=setResultMatrixOrigin
34-
@autoproperty batchStart::NSUInteger setter=setBatchStart
35-
@autoproperty batchSize::NSUInteger setter=setBatchSize
36-
end
14+
# @objcwrapper immutable=false MPSMatrixBinaryKernel <: MPSKernel

0 commit comments

Comments
 (0)