-
Notifications
You must be signed in to change notification settings - Fork 48
@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
14
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
14 commits
Select commit
Hold shift + click to select a range
3c1e9e8
Implement @mtlprintf using os_log
tgymnich b014e8d
Simplify logic to work around hang.
maleadt 81e3c71
core println
tgymnich 3789b40
Update log_state.jl
tgymnich 93b276f
Update src/compiler/execution.jl
tgymnich ff5d288
Update test/output.jl
tgymnich 202e3d9
use wrappers
tgymnich 68b42ac
make macos_version check static
tgymnich 4a2ec1e
remove finalizer
tgymnich 428a86f
add version checks
tgymnich 771932d
Make new descriptors mutable
christiangnrd 2e066c4
format
tgymnich 6b73773
Cleanup rebase glitches
christiangnrd 3e75f7f
Add compat warning
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
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
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} | ||
|
@@ -275,7 +276,35 @@ end | |
(threads.width * threads.height * threads.depth) > kernel.pipeline.maxTotalThreadsPerThreadgroup && | ||
throw(ArgumentError("Number of threads in group ($(threads.width * threads.height * threads.depth)) should not exceed $(kernel.pipeline.maxTotalThreadsPerThreadgroup)")) | ||
|
||
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
+281
to
+283
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.