-
Notifications
You must be signed in to change notification settings - Fork 46
@mtlprintf #418
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
tgymnich
wants to merge
16
commits into
main
Choose a base branch
from
os-log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
@mtlprintf #418
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9ab11f9
Implement @mtlprintf using os_log
tgymnich 9d33cc8
Simplify logic to work around hang.
maleadt ed5a72f
core println
tgymnich 9bff09f
Update log_state.jl
tgymnich ab3fb9a
Update src/compiler/execution.jl
tgymnich e08b028
Update test/output.jl
tgymnich 470a667
use wrappers
tgymnich 039180a
make macos_version check static
tgymnich b8b50ca
remove finalizer
tgymnich 4a0a719
add version checks
tgymnich 14e0070
Make new descriptors mutable
christiangnrd 70fda01
format
tgymnich a8eeb9f
Cleanup rebase glitches
christiangnrd 9e425a3
Add compat warning
christiangnrd 20e00f0
Hook up to KA
christiangnrd 97fa034
kutf
christiangnrd 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
Some comments aren't visible on the classic Files Changed page.
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
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,26 @@ | ||
| export MTLLogLevel | ||
|
|
||
| export MTLLogStateDescriptor | ||
|
|
||
| # @objcwrapper immutable = false MTLLogStateDescriptor <: NSObject | ||
|
|
||
| function MTLLogStateDescriptor() | ||
| handle = @objc [MTLLogStateDescriptor alloc]::id{MTLLogStateDescriptor} | ||
| obj = MTLLogStateDescriptor(handle) | ||
| finalizer(release, obj) | ||
| @objc [obj::id{MTLLogStateDescriptor} init]::id{MTLLogStateDescriptor} | ||
| return obj | ||
| end | ||
|
|
||
|
|
||
| export MTLLogState | ||
|
|
||
| # @objcwrapper immutable = true MTLLogState <: NSObject | ||
|
|
||
| function MTLLogState(dev::MTLDevice, descriptor::MTLLogStateDescriptor) | ||
| err = Ref{id{NSError}}(nil) | ||
| handle = @objc [dev::id{MTLDevice} newLogStateWithDescriptor:descriptor::id{MTLLogStateDescriptor} | ||
| error:err::Ptr{id{NSError}}]::id{MTLLogState} | ||
| err[] == nil || throw(NSError(err[])) | ||
| MTLLogState(handle) | ||
| end |
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 |
|---|---|---|
|
|
@@ -161,6 +161,7 @@ mtlconvert(arg, cce=nothing) = adapt(Adaptor(cce), arg) | |
| struct HostKernel{F,TT} | ||
| f::F | ||
| pipeline::MTLComputePipelineState | ||
| loggingEnabled::Bool | ||
| end | ||
|
|
||
| const mtlfunction_lock = ReentrantLock() | ||
|
|
@@ -186,15 +187,15 @@ function mtlfunction(f::F, tt::TT=Tuple{}; name=nothing, kwargs...) where {F,TT} | |
| cache = compiler_cache(dev) | ||
| source = methodinstance(F, tt) | ||
| config = compiler_config(dev; name, kwargs...)::MetalCompilerConfig | ||
| pipeline = GPUCompiler.cached_compilation(cache, source, config, compile, link) | ||
| pipeline, loggingEnabled = GPUCompiler.cached_compilation(cache, source, config, compile, link) | ||
|
|
||
| # create a callable object that captures the function instance. we don't need to think | ||
| # about world age here, as GPUCompiler already does and will return a different object | ||
| h = hash(pipeline, hash(f, hash(tt))) | ||
| kernel = get(_kernel_instances, h, nothing) | ||
| if kernel === nothing | ||
| # create the kernel state object | ||
| kernel = HostKernel{F,tt}(f, pipeline) | ||
| kernel = HostKernel{F, tt}(f, pipeline, loggingEnabled) | ||
| _kernel_instances[h] = kernel | ||
| end | ||
| return kernel::HostKernel{F,tt} | ||
|
|
@@ -277,7 +278,35 @@ end | |
|
|
||
| kernel_state = KernelState(Random.rand(UInt32)) | ||
|
|
||
| cmdbuf = MTLCommandBuffer(queue) | ||
| cmdbuf = if kernel.loggingEnabled | ||
| # TODO: make this a dynamic error, i.e., from the kernel (JuliaGPU/Metal.jl#433) | ||
| @static if !is_macos(v"15.0.0") | ||
| error("Logging is only supported on macOS 15 or higher") | ||
| end | ||
|
Comment on lines
+283
to
+285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The macOS 13/14 output test fails because compilation fails before reaching this check. I tested it before rebasing and the availability PR doesn't seem to affect it. |
||
|
|
||
| if MTLCaptureManager().isCapturing | ||
| error("Logging is not supported while GPU frame capturing") | ||
| end | ||
|
|
||
| log_state_descriptor = MTLLogStateDescriptor() | ||
| log_state_descriptor.level = MTL.MTLLogLevelDebug | ||
| log_state = MTLLogState(queue.device, log_state_descriptor) | ||
|
|
||
| function log_handler(subSystem, category, logLevel, message) | ||
| Core.print(String(NSString(message))) | ||
| return nothing | ||
| end | ||
|
|
||
| block = @objcblock(log_handler, Nothing, (id{NSString}, id{NSString}, NSInteger, id{NSString})) | ||
| @objc [log_state::id{MTLLogState} addLogHandler:block::id{NSBlock}]::Nothing | ||
|
|
||
| cmdbuf_descriptor = MTLCommandBufferDescriptor() | ||
| cmdbuf_descriptor.logState = log_state | ||
| MTLCommandBuffer(queue, cmdbuf_descriptor) | ||
| else | ||
| MTLCommandBuffer(queue) | ||
| end | ||
|
|
||
| cmdbuf.label = "MTLCommandBuffer($(nameof(kernel.f)))" | ||
| cce = MTLComputeCommandEncoder(cmdbuf) | ||
| argument_buffers = try | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.