All posts by dani


CUDA Scripting in Excel Part II

This video shows how to use some of our extension to quickly code a PI calculation with Monte-Carlo simulation inside Excel with Tsunami F# scripting. In this example we use Sobol sequence.

Here is the test code:

[sourcecode language=”fsharp”]
#r @”C:\Users\Xiang\Documents\FCell\Alea.CUDA.dll”
#r @”C:\Users\Xiang\Documents\FCell\Alea.CUDA.Extension.dll”
#r @”C:\Users\Xiang\Documents\FCell\FCell.ManagedXll.dll”

namespace Demo

open Alea.CUDA
open Alea.CUDA.Extension
open FCell.ManagedXll

module UDF =

let exc (e:exn) = XlScalar(XlString(e.Message))

let private worker = Engine.workers.DefaultWorker
let private sobol = worker.LoadPModule(PRandom.sobol <@ Sobol.toFloat64 @>).Invoke
let private sum = worker.LoadPModule(PArray.sum()).Invoke
let private map =
let transform =
<@ fun (x:float) (y:float) ->
let x = x – 0.5
let y = y – 0.5
let distance = sqrt(x * x + y * y)
match distance with
| distance when distance <= 0.5 -> 1.0
| _ -> 0.0 @>
worker.LoadPModule(PArray.map2 transform).Invoke
let private calc samples = pcalc {
let dimensions = 2
let vectors = samples
let! numbers = sobol dimensions vectors 0
let x = DArray.subView numbers 0 samples
let y = DArray.subView numbers samples samples
let! insides = map x y
let! inside = sum insides
let! inside = inside.Gather()
let total = float(samples)
return inside / total / 0.25 }
let CalcPI samples = calc samples |>


Alea.cuBase 1.3 Released

We are very pleased to announce the long awaited new version 1.3 of Alea.cuBase. This new version is a major step adding full support for debugging and several new features.

  • Debug support with Visual Nsight. To prepare your GPU code for debug with Visual Nsight you have to
    • Compile the kernel quotations with the fsc option –quotations-debug
    • Compile the template with diagnostics options
  • Improved support for profiling, including source code correlation at the single line of code
  • Representing C style unions with .NET structs
  • Support F# discriminated union, by using DiscriminatedUnionAttribute builder; note that the cases cannot contains function values
  • Compile a function to a device function by adding both ReflectedDefinition and DeviceFunction attribute to a function
  • A blob type that can handle “lazy” style memory allocation
  • Various bug fixings and improvements
  • Significantly improved API documentation

Alea.cuBase 1.3 is available on the NuGet.