YaccConstructor / Brahma.FSharp

F# quotation to OpenCL translator and respective runtime to utilize GPGPUs in F# applications.
http://yaccconstructor.github.io/Brahma.FSharp
Eclipse Public License 1.0
74 stars 17 forks source link

Added kernel caching support #117

Closed dpanfilyonok closed 3 years ago

dpanfilyonok commented 3 years ago

Proposed Changes

Added support of kernel caching. (For experimentation only)

gsvgit commented 3 years ago

Looks good.

  1. Can you provide an example of end-user code? How caching can be enabled/disabled? On which step it should be done?
  2. Is this implementation allows one to enable/disable caching for each specific kernel independently?
dpanfilyonok commented 3 years ago

Usage:

opencl {

}
|> OpenCLEvaluationContext(IsCachingEnabled = true).RunSync
let ctx = OpenCLEvaluationContext()

// without caching
opencl {

}
|>  ctx.RunSync

// with caching
ctx.IsCachingEnabled  <- true
opencl {

}
|>  ctx.RunSync
opencl {
  let kernel1 = <@ .. @>
  let kernel2 = <@ .. @>

  // with caching
  do! RunCommand kernel1 ... 

  // without caching 
  let! ctx = getEvaluationContext
  let oldContext = ctx.Clone()
  ctx.IsCachingEnabled  <- false
  do! RunCommand kernel2

  ctx.IsCachingEnabled  <- oldContext.IsCachingEnabled
}
|> OpenCLEvaluationContext(IsCachingEnabled = true).RunSync

It should be noted that the proposed solution is suitable for experimentation only. It will crash on caching equal expressions but with different types in it (because string representation of Expr erase types).

simpletonDL commented 3 years ago

This solution is suitable for experiments and can also be improved in the future (correct hashing, refactoring). So I think I can make a release

gsvgit commented 3 years ago

@simpletonDL well. Please, publish new package.