Post not yet marked as solved
I've got a MLTBuffer with 20 Floats in it. I want each thread to have 4 floats available for it to work on, meaning a total of 5 threads.
I've been playing around with this for a day and so far no joy/luck. I have attempted to manipulate the two MTLSizes that are passed to dispatchThreads without success. I can get this to work if both MTLSizes are (MemoryLayout<Float>.stride*20,1,1) but then the number of threads used is much too large.
Any ideas?
Thanks ahead of time.
Lee
Post not yet marked as solved
I'm trying to call a function in a C .o file from within a metal function. The function being called doesn't have the device modifier in front of its parameters. As a simple example, here is function declaration in a C header.
void add(const float* a, const float* b, float* sum);
Is there a way around this problem that doesn't require re-writing the entire function?
I'm attempting to get to the point that I can use a library of compiled Fortran that has a C interface.
Any help appreciated
Post not yet marked as solved
So I've read the documentation, downloaded the Accelerate source, and created a simple example.
I'm attempting to solve a system of two equations,
90x+85y=400, and
y-x=0.
The result should be just greater than 2.25 for both x and y. What I get is [x,y]=[2.2857144, 205.7143].
I'm new to this, so I'm sure I've misread the docs, but I can't see where.
Here is the code I modified to do my experiment.
do{
let aValues: [Float] = [85, 90,
1,-1]
/// The _b_ in _Ax = b_.
let bValues: [Float] = [400,0]
/// Call `nonsymmetric_general` to compute the _x_ in _Ax = b_.
let x = nonsymmetric_general(a: aValues,
dimension: 2,
b: bValues,
rightHandSideCount: 1)
/// Calculate _b_ using the computed _x_.
if let x = x {
let b = matrixVectorMultiply(matrix: aValues,
dimension: (m: 2, n: 2),
vector: x)
/// Prints _b_ in _Ax = b_ using the computed _x_: `~[70, 160, 250]`.
print("\nx = ",x)
print("\nb =", b)
}
}
What did I misunderstand?
Thanks
Post not yet marked as solved
Here is some simplified code that attempts to use AVKit in Swift to record a video to a file. No errors are thrown, yet no file exists when checked. What have I left out?
I've tried several different variations, all with the same result. No file is created.
import UIKit
import AVKit
extension UIViewController:AVCaptureFileOutputRecordingDelegate{
public func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if let error = error{
print(error.localizedDescription)
}
print("checking if \(outputFileURL.absoluteString) exists: \(FileManager.default.fileExists(atPath: outputFileURL.absoluteString))")
}
}
class ViewController: UIViewController {
var captureSession = AVCaptureSession()
var movieOutput = AVCaptureMovieFileOutput()
var previewLayer = AVCaptureVideoPreviewLayer()
@IBOutlet var cameraView: UIView!
override func viewWillAppear(_ animated: Bool) {
self.cameraView = self.view
guard let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front) else{
return
}
if camera.hasTorch && camera.isTorchModeSupported(.auto){
camera.torchMode = .auto
}
do{
let input = try AVCaptureDeviceInput(device: camera)
if captureSession.canAddInput(input){
captureSession.addInput(input)
if captureSession.canAddOutput(movieOutput){
captureSession.addOutput(movieOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
previewLayer.connection?.videoOrientation = AVCaptureVideoOrientation.portrait
cameraView.layer.addSublayer(previewLayer)
previewLayer.position = CGPoint(x: self.cameraView.frame.width / 2, y: self.cameraView.frame.height / 2)
previewLayer.bounds = cameraView.frame
captureSession.startRunning()
let fileUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("output.mp4")
try? FileManager.default.removeItem(at: fileUrl)
print("recording to: \(fileUrl.absoluteString)")
movieOutput.startRecording(to: fileUrl, recordingDelegate: self)
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
self.movieOutput.stopRecording()
}
}
}
}
catch{
print("Error")
}
}
}