Microsoft_Excel_2013_logo

CUDA Scripting in Excel Part I

In this video, we use the Tsunami IDE to do CUDA scripting inside Excel. We show how to code a CUDA kernel, launch and modify it.

Here is the test code:

[sourcecode language=”fsharp”]
#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]
[/sourcecode]