Created
March 12, 2013 08:09
-
-
Save soloman817/5141059 to your computer and use it in GitHub Desktop.
CUDA scripting inside Excel with Tsunami IDE (Part I)
This file contains 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
#r @"C:\Users\Xiang\Documents\FCell\Alea.CUDA.dll" | |
#r @"C:\Users\Xiang\Documents\FCell\FCell.ManagedXll.dll" | |
namespace Demo | |
open Alea.CUDA | |
open FCell.ManagedXll | |
module UDF = | |
[<XlConverter>] | |
let exc (e:exn) = XlScalar(XlString(e.Message)) | |
let private worker = Engine.workers.DefaultWorker | |
let DeviceName() = worker.Device.Name | |
let DeviceMemory() = worker.Device.Memory |> int | |
let private pfunct = cuda { | |
let! kernel = | |
<@ fun (A:DevicePtr<float>) (B:DevicePtr<float>) (C:DevicePtr<float>) -> | |
let tid = threadIdx.x | |
C.[tid] <- A.[tid] + B.[tid] @> | |
|> defineKernelFunc | |
return PFunc(fun (m:Module) (A:float[]) (B:float[]) -> | |
use A = m.Worker.Malloc(A) | |
use B = m.Worker.Malloc(B) | |
use C = m.Worker.Malloc(A.Length) | |
let lp = LaunchParam(1, A.Length) | |
kernel.Launch m lp A.Ptr B.Ptr C.Ptr | |
C.ToHost()) } | |
let private pfuncm = worker.LoadPModule(pfunct) | |
let Test value idx = | |
let A = [| 1.1; 2.2; 3.3 |] | |
let B = Array.init A.Length (fun _ -> value) | |
let C = pfuncm.Invoke A B | |
C.[idx] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment