How to get the device architecture inside a kernel? - aleagpu

Just as the title asks. Both
let blockReducer = BlockReduce.RakingCommutativeOnly<float32>(dims,DeviceArch.Create("sm35"))
and
let blockReducer = BlockReduce.RakingCommutativeOnly<float32>(dims,worker.Device.Arch)
fail on compilation.

Actually, let blockReducer = BlockReduce.RakingCommutativeOnly<float32>(dims,worker.Device.Arch) should be called outside the kernel. Then there are no problems at all.

Related

Best way to determine the amount of space available for storing app files with Xamarin forms?

From research I have found that it is possible to determine the available space for storing app files on iOS, Android and UWP using dependency services with the Platform specific code below:
For iOS:
private double GetRemainingStorageSpace(string directoryPath)
{
var freeExternalStorage = NSFileManager.DefaultManager.GetFileSystemAttributes(directoryPath).FreeSize;

 return (double)freeExternalStorage;

}
For Android it can be done like:
var path = new StatFs(directoryPath);
long blockSize = path.BlockSizeLong;
long avaliableBlocks = path.AvailableBlocksLong;
double freeSpace = blockSize * avaliableBlocks;

return freeSpace
or like this:
var fl = new Java.IO.File(directoryPath);
var freeSpace = fl.UsableSpace;
return (double)freeSpace;
For UWP:
string freeSpaceKey = "System.FreeSpace";

StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(directoryPath);
var properties = await folder.Properties.RetrievePropertiesAsync(new string[]
{
freeSpaceKey
});

var freeSpace = properties[freeSpaceKey];

return (UInt64)freeSpace;
My question then is:
1.) Do these lines of code above actually return the amount of bytes that can be stored in a specific directory? Or do they return the amount of bytes that can be stored on the whole device?
2.) For Android I am not too sure what the difference between the two ways of doing this are I am hoping for an explanation of the difference between the both of then and which is a better to use?
Would appreciate an explanation.
1.) Do these lines of code above actually return the amount of bytes that can be stored in a specific directory? Or do they return the amount of bytes that can be stored on the whole device?
Obviously it is specific directory ,because in the code it needs specific folder path as parameter .
You can try to set directoryPath as
System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)
and
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
to see the difference.
2.) For Android I am not too sure what the difference between the two ways of doing this are I am hoping for an explanation of the difference between the both of then and which is a better to use?
I can't tell the difference or which is better, because based on my test the result comes the same , and for details you can refer to here , it's maybe helpful .

MacOs OpenGl forward compatibilty?

I am trying to set up some very simple graphic windows which I also have to use on MacOS version Big Sur unfortunately. I am using the F# programming language and the OpenTK package.
This is the code I have at the moment.
open OpenTK.Windowing.Desktop
open OpenTK.Mathematics
open OpenTK.Windowing.Common
open OpenTK.Graphics
[<EntryPoint>]
let main argv =
let prof = ContextProfile.Compatability
let windowSettings = NativeWindowSettings()
windowSettings.Size <- Vector2i(800, 600)
windowSettings.Title <- "OpenTK Window"
windowSettings.Profile <- prof
windowSettings.APIVersion <- Version "3.3"
use window = new GameWindow(GameWindowSettings.Default, windowSettings)
//window.MakeCurrent()
//window.Run ()
0
Whenever I run this I get:
Unhandled exception. OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: NSGL: The targeted version of macOS only supports forward-compatible core profile contexts for OpenGL 3.2 and above
at OpenTK.Windowing.Desktop.GLFWProvider.<>c.<.cctor>b__5_0(ErrorCode errorCode, String description)
I have tried every single configuration possible but I am stumped, is there anyone that can give me a pointer on how to set the compatibility for this?
Change this
let prof = ContextProfile.Compatability
to
let prof = ContextProfile.Core

Get the window handle in PyGI on MacOS

I use PyGObject/PyGI and GStreamer to show a video in my GUI. The video is shown in a Gtk.DrawingArea and therefore I need to get it's window-handle in the realize-signal-handler. On Linux I can simply use drawing_area.get_property('window').get_xid() and on Windows I have to access the C-API (like described here):
drawingarea_window = drawingarea.get_property('window')
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object]
drawingarea_gpointer = ctypes.pythonapi.PyCapsule_GetPointer(drawingarea_window.__gpointer__, None)
gdkdll = ctypes.CDLL ('libgdk-3-0.dll')
self._drawingarea_handle = gdkdll.gdk_win32_window_get_handle(drawingarea_gpointer)
Now I want the same on MacOS. Since it is not using X11, but Quartz, I tried to use the C-API again. But this time to call gdk_quartz_window_get_nswindow instead of gdk_win32_window_get_handle (see gdkwindow-quartz.c):
// ... same lines as in Windows-example
gdkdll = ctypes.CDLL ('libgdk-3.0.dylib')
self._drawingarea_handle = gdkdll.gdk_quartz_window_get_nswindow(drawingarea_gpointer)
But this leads just to a Segmentation fault: 11.Any ideas on how to get the handle on MacOS?

Array and Dictionary type declarations in Swift

According to my understanding of the documentation, this should be correct:
var cookies: [NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as [NSHTTPCookie]
where I'm creating an array of NSHTTPCookie objects. The interpreter does not like this syntax, however, giving me "Expected type after 'as'" and putting a little pointer at the opening bracket of the [NSHTTPCookie] at the end.
However, this works:
var cookies:NSHTTPCookie[] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as NSHTTPCookie[]
From the documentation, it seems like the first version is more correct, however.
Here's another example, this time with someone else's code. No one else using this code has reported the same behavior I get. (This is just a snippet; if the context is relevant let me know and I'll post more)
func asDict(x: AnyObject) -> [String:AnyObject]? {
return x as? [String:AnyObject]
}
In this case the playground interpreter objects in both places [String:AnyObject] is used. It just doesn't seem to be recognizing it as a type.
I double-checked to make sure I have the most recent beta of Xcode 6, but it seems much more likely to me that the problem is in my understanding rather than in the tool, since this would be a mighty big bug for only me to experience.
You must be using an old beta, this works in Beta 5 playground:
import Foundation
println("hello")
var cookies:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as [NSHTTPCookie]
println("goodbye")

Need to get information from Qt4ruby Form's textedit(textbox) and pass back to string for console

I think this problem is best described in code. I'm sure the solution is close, I just haven't been able to find it. I've been looking over the Qt4 api as well as doing tutorials. Here is my code so far:
require 'Qt4'
class PictureCommentForm < Qt::Widget
def initialize(parent = nil)
super()
#setFixedSize(300, 100)
#comment_text = nil
picture = Qt::Label.new()
image = Qt::Image.new('image.jpeg')
picture.pixmap = image
comment = Qt::LineEdit.new()
layout = Qt::VBoxLayout.new()
layout.addWidget(picture)
layout.addWidget(comment)
setLayout(layout)
connect(comment, SIGNAL('returnPressed()'), self, setCommentText(comment.text) )
end
def setCommentText(text)
#comment_text = text
$qApp.quit()
end
end
app = Qt::Application.new(ARGV)
comment_form = PictureCommentForm.new()
comment_form.show()
app.exec
comment_text = comment_form.comment_text
puts "Comment was:\n #{comment_text}"
EDIT: Thanks for that answer integer. All I want done is a dialog box showing a picture and comment so I can get that data. I do plan on making a full GUI version with qt4, but that's for later.
I don't know Ruby, so bear with me, but I use Qt extensively in Python.
First point is that Qt really, really doesn't want to be used the way you're trying to use it. If you're making some sort of script, then Qt wants you to give it to Qt so it can run your code when it feels like:
We recommend that you connect clean-up
code to the aboutToQuit() signal,
instead of putting it in your
application's main() function because
on some platforms the
QCoreApplication::exec() call may not
return.
Working with Qt you pretty much have to do event-driven programming and give it control of your program flow / main loop.
If you really just want some "utility" that shows some GUI input box and prints whatever the user inputs to console, consider putting the puts directly in whatever function you connected to the text box. Then you can use that program's output in other console scripts.

Resources