When I use metal to render, the application switch to the background resulting in metal rendering failure in iOS 15 sys.
How can I do?
Error:
Execution of the command buffer was aborted due to an error during execution.Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted)
Metal
RSS for tagRender advanced 3D graphics and perform data-parallel computations using graphics processors using Metal.
Post
Replies
Boosts
Views
Activity
I am trying to use a CIColorKernel or CIBlendKernel with sampler arguments but the program crashes. Here is my shader code which compiles successfully.
extern "C" float4 wipeLinear(coreimage::sampler t1, coreimage::sampler t2, float time) {
float2 coord1 = t1.coord();
float2 coord2 = t2.coord();
float4 innerRect = t2.extent();
float minX = innerRect.x + time*innerRect.z;
float minY = innerRect.y + time*innerRect.w;
float cropWidth = (1 - time) * innerRect.w;
float cropHeight = (1 - time) * innerRect.z;
float4 s1 = t1.sample(coord1);
float4 s2 = t2.sample(coord2);
if ( coord1.x > minX && coord1.x < minX + cropWidth && coord1.y > minY && coord1.y <= minY + cropHeight) {
return s1;
} else {
return s2;
}
}
And it crashes on initialization.
class CIWipeRenderer: CIFilter {
var backgroundImage:CIImage?
var foregroundImage:CIImage?
var inputTime: Float = 0.0
static var kernel:CIColorKernel = { () -> CIColorKernel in
let url = Bundle.main.url(forResource: "AppCIKernels", withExtension: "ci.metallib")!
let data = try! Data(contentsOf: url)
return try! CIColorKernel(functionName: "wipeLinear", fromMetalLibraryData: data) //Crashes here!!!!
}()
override var outputImage: CIImage? {
guard let backgroundImage = backgroundImage else {
return nil
}
guard let foregroundImage = foregroundImage else {
return nil
}
return CIWipeRenderer.kernel.apply(extent: backgroundImage.extent, arguments: [backgroundImage, foregroundImage, inputTime])
}
}
It crashes in the try line with the following error:
Fatal error: 'try!' expression unexpectedly raised an error: Foundation._GenericObjCError.nilError
If I replace the kernel code with the following, it works like a charm:
extern "C" float4 wipeLinear(coreimage::sample_t s1, coreimage::sample_t s2, float time)
{
return mix(s1, s2, time);
}
I downloaded this sample:
https://developer.apple.com/documentation/metal/basic_tasks_and_concepts/using_metal_to_draw_a_view_s_contents?preferredLanguage=occ
I commented out this line in AAPLViewController.mm
// _view.enableSetNeedsDisplay = YES;
I modified the presentDrawable line in AAPLRenderer.mm to add afterMinimumDuration:
[commandBuffer presentDrawable:drawable afterMinimumDuration:1.0/60];
I then added a presentedHandler before the above line that records the time between successive presents.
Most of the time it correctly reports 0.166667s. However, about every dozen or so frames (it varies) it seems to present a frame early with an internal of 0.0083333333s followed by the next frame after around 0.24s.
Is this expected behaviour, I was hoping that afterMinimumDuration would specifically make things consistent. Why would it present a frame early?
This is on a new MacBook Pro 16 running latest macOS Monterrey, and the sample project upgraded to have a minimum deployment target of 11.0. Xcode latest public release 13.1.
I'm interested in using CatBoost and XGBoost for some machine learning projects on my Mac, and I was wondering if it's possible to run these algorithms on my GPU(s) to speed up training times.
I have a Mac with an AMD Radeon Pro 5600M and an Intel UHD Graphics 630 GPUs, and I'm running macOS Ventura 13.2.1. I've read that both CatBoost and XGBoost support GPU acceleration, but I'm not sure if this is possible on my system.
Can anyone point me in the right direction for getting started with GPU-accelerated CatBoost/XGBoost on macOS? Are there any specific drivers or tools I need to install, or any other considerations I should be aware of?
Thank you.
Hi,
I am training an adversarial auto encoder using PyTorch 2.0.0 on Apple M2 (Ventura 13.1), with conda 23.1.0 as manager.
I encountered this error:
/AppleInternal/Library/BuildRoots/5b8a32f9-5db2-11ed-8aeb-7ef33c48bc85/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShaders/MPSNDArray/Kernels/MPSNDArrayConvolutionA14.mm:3967: failed assertion `destination kernel width and filter kernel width mismatch'
/Users/vk/miniconda3/envs/betavae/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
To my knowledge, the code broke down when running self.manual_backward(loss["g_loss"]) this block:
g_opt.zero_grad()
self.manual_backward(loss["g_loss"])
g_opt.step()
The same code run without problems on linux distribution.
Any thoughts on how to fix it are highly appreciated!
We are using AVAssetWriter to write videos using both HEVC and H.264 encoding. Occasionally, we get reports of choppy footage in which frames appear out of order when played back on a Mac (QuickTime) or iOS device (stock Photos app). This occurs extremely unpredictably, often not starting until 20+ minutes of filming, but occasionally happening as soon as filming starts.
Interestingly, users have reported the issue goes away while editing or viewing on a different platform (e.g. Linux) or in the built-in Google Drive player, but comes back as soon as the video is exported or downloaded again. When this occurs in an HEVC file, converting to H.264 seems to resolve it. I haven't found a similar fix for H.264 files.
I suspect an AVAssetWriter encoding issue but haven't been able to uncover the source.
Running a stream analyzer on HEVC files with this issue reveals the following error:
Short-term reference picture with POC = [some number] seems to have been removed or not correctly decoded.
However, running a stream analyzer on H.264 files with the same playback issue seems to show nothing wrong.
At a high level, our video pipeline looks something like this:
Grab a sample buffer in captureOutput(_ captureOutput: AVCaptureOutput!, didOutputVideoSampleBuffer sampleBuffer: CMSampleBuffer!)
Perform some Metal rendering on that buffer
Pass the resulting CVPixelBuffer to the AVAssetWriterInputPixelBufferAdaptor associated with our AVAssetWriter
Example files can be found here: https://drive.google.com/drive/folders/1OjDZ3XaC-ubD5hyDiNvMQGl2NVqZbWnR?usp=sharing
This includes a video file suffering this issue, the same file fixed after converting to mp4, and a screen recording of the distorted playback in QuickTime.
Can anyone help point me in the right direction to solving this issue? I can provide more details as necessary.
Hello,
I’ve started testing the Metal Shader Converter to convert my HLSL shaders to metallib directly, and I was wondering if the option ’-frecord-sources’ was supported in any way?
Usually I’m compiling my shaders as follows (from Metal):
xcrun -sdk macosx metal -c -frecord-sources shaders/shaders.metal -o shaders/shaders.air
xcrun -sdk macosx metallib shaders/shaders.air -o shaders/shaders.metallib
The -frecord-sources allow me to see the source when debugging and profiling a Metal frame.
Now with DXC we have a similar option, I can compile a typical HLSL shader with embedded debug symbols with:
dxc -T vs_6_0 -E VSMain shaders/triangle.hlsl -Fo shaders/triangle.dxil -Zi -O0 -Qembed_debug
The important options here are ’-Zi` and ’-Qembed_debug’, as they make sure debug symbols are embedded in the DXIL.
It seems that right now Metal Shader Converter doesn’t pass through the DXIL debug information, and I was wondering if it was possible. I’ve looked at all the options in the utility and haven’t seen anything that looked like it.
Right now debug symbols in my shaders is a must-have, so I’ll explore other routes to convert my HLSL shaders to Metal (I’ve been testing spir-v cross to do the conversion, I haven’t actually tested the debug symbols yet, I’ll report back later).
Thank you for your time!
I'm trying to create an app similar to PolyCam using Lidar . I'm using SceneKit mesh reconstruction and able to apply some random textures. But need real-world textures in generated output 3D Model. Found few examples available which are related to MetalKit and Point Cloud, which was not helpful.
Can you help me out with any references/steps/tutorial to how to achieve it .
In the video here, the speaker refers to MPSGraphTool, which is supposed to convert from CoreML and other formats to the new MPSGraphPackage format.
Searching for MPSGraphTool on Google returns only that video, and there is no mention of it on the forums here or elsewhere.
When can we expect the tool to be released? How can we find out more information about it?
My use case is that the ANECompilerService that runs on the Mac / iOS devices to compile CoreML Models / Programs is extremely slow and unreliable for large models. It often crashes entirely, sitting at 100% CPU usage forever and never completing the task at hand, meaning the user is stuck in a loading state. This also applies in Xcode when running a performance test. I would really like to compile the graph once and just run it on device directly.
Hello,
I am trying to use gpu for machine learning task from apple using "mps" as device for GPU but it is not working. I am using PyTorch Stable version. How can I use MacBook GPU for machine learning tasks?
I use Macmini with MacOS Ventura 13.3.1, while the Mac running MetalFX sample code, and choose Temporal Scaler, makeTemporalScaler return nil value, and print "The temporal scaler effect is not usable!". If i choose SpatialScaler, it is ok.
guard let temporalScaler = desc.makeTemporalScaler(device: device) else {
print("The temporal scaler effect is not usable!")
mfxScalingMode = .defaultScaling
return
}
Sample code:
https://developer.apple.com/documentation/metalfx/applying_temporal_antialiasing_and_upscaling_using_metalfx?language=objc
with my MacBook m2.
The code works correctly both on CPU and GPU, but the speed on GPU is much slower!
I have loaded my statistic and my model on GPU, and it seemed to work.
/Users/guoyijun/Desktop/iShot_2023-08-20_09.57.41.png
I printed my code runtime. when the following function "train" is called, the loop speed among them runs extraordinarily slow.
def train(net, device, train_features, train_labels, test_features, test_labels,
num_epochs, learning_rate, weight_decay, batch_size):
train_ls, test_ls = [], []
train_iter = d2l.load_array((train_features, train_labels), batch_size, device)
# Adam
optimizer = torch.optim.Adam(net.parameters(), lr = learning_rate, weight_decay = weight_decay)
for epoch in range(num_epochs):
for X, y in train_iter:
optimizer.zero_grad()
l = loss(net(X), y)
l.backward()
optimizer.step() #
train_ls.append(log_rmse(net, train_features, train_labels))
return train_ls, test_ls
I know opengl is marked as deprecated since ios12 but I have an old project using it and I want to update some feature of it then release the update version.
So I'm wondering if I can still release an app using opengl to app store currently?
(I know it's better to shift to MetalKit but for some reason I want to cut the cost if I can. )
Response appreciated.
Hello.
I'm working with Metal in Apple Vision Pro, and I've assumed that I can use Mesh shaders to work with Meshlets. But when creating the RenderPipeline, I get the following error message: "device does not support mesh shaders". The test is on the simulator, and my question is: Will Apple Vision Pro support Mesh shaders on physical devices?
Thanks.
Hi,
I am trying to extend the pytorch library. I would like to add MPS native Cholesky Decomposition. I finally got it working (mostly).
But I am struggling to implement the status codes.
What I did:
// init status
id<MTLBuffer> status = [device newBufferWithLength:sizeof(int) options:MTLResourceStorageModeShared];
if (status) {
int* statusPtr = (int*)[status contents];
*statusPtr = 42; // Set the initial content to 42
NSLog(@"Status Value: %d", *statusPtr);
}
else {
NSLog(@"Failed to allocate status buffer");
}
...
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
// Your completion code here
int* statusPtr = (int*)[status contents];
int statusVal = *statusPtr;
NSLog(@"Status Value: %d", statusVal);
// Update the 'info' tensor here based on statusVal
// ...
}];
for (const auto i : c10::irange(batchSize)) {
...
[filter encodeToCommandBuffer:commandBuffer
sourceMatrix:sourceMatrix
resultMatrix:solutionMatrix
status:status];
}
(full code here: https://github.com/pytorch/pytorch/blob/ab6a550f35be0fdbb58b06ff8bfda1ab0cc236d0/aten/src/ATen/native/mps/operations/LinearAlgebra.mm)
But this code prints the following when input with a non positive definite tensor:
2023-09-02 19:06:24.167 python[11777:2982717] Status Value: 42
2023-09-02 19:06:24.182 python[11777:2982778] Status Value: 0
initial tensor: tensor([[-0.0516, 0.7090, 0.9474],
[ 0.8520, 0.3647, -1.5575],
[ 0.5346, -0.3149, 1.9950]], device='mps:0')
L: tensor([[-0.0516, 0.0000, 0.0000],
[ 0.8520, -0.3612, 0.0000],
[ 0.5346, -0.3149, 1.2689]], device='mps:0')
What am I doing wrong? Why do I get a 0 (success) status even tough the matrix is not positive definite.
Thank you in advance!
Hello,
I've been working on an app that involves training a neural network model on the iPhone. I've been using the Metal Performance Shaders Graph (MPS Graph) for this purpose. In the training process the loss becomes Nan on iOS17 (21A329).
I noticed that the official sample code for Training a Neural Network using MPS Graph (link) works perfectly fine on Xcode 14.3.1 with iOS 16.6.1. However, when I run the same code on Xcode 15.0 beta 8 with iOS 17.0 (21A329), the training process produces a NaN loss in function updateProgressCubeAndLoss. The official sample code and my own app exhibit the same issue.
Has anyone else experienced this issue? Is this a known bug, or is there something specific that needs to be adjusted for iOS 17?
Any guidance would be greatly appreciated.
Thank you!
I'm experimenting with Vision OS and Apple Vision Pro using the Xcode Beta. I'm using Xcode 15.1 Beta and visionOS 1.0 beta 4.
I'm currently doing a project where I draw a polygon using a mesh generated from MeshDescriptor/MeshResource and present it in an ImmersiveView.
I want to change the color of parts, i.e. not all of, my 3D rendered polygon and I want to do it dynamically. For example when the user presses a button.
I have gotten into Shaders and the CustomMaterial from RealityKit, only to find out that CustomMaterial is not supported on Vision OS!
Does anyone know how I can color portions/parts of a mesh that is generated from MeshDescriptor and MeshResource?
Hi,
Is transparency supported in MetalFX?
I have a project that sets a texture to a particular alpha value. It works fine. However, as soon as I enable MetalFX, the transparency stops working. The alpha value is set to 1.0.
If transparency is supported in MetalFX, how do I enable it?
Thank you
I Instrument's CPU Profiling tool I've noticed that a significant portion (22.5%) of the CPU-side overhead related to MPS matrix multiplication (GEMM) is in a call to getenv(). Please see attached screenshot.
It seems unnecessary to perform this same check over and over, as whatever hack that needs this should be able to perform the getenv() only once and cache the result for future use.