timholy / ComputationalResources.jl

Julia package for selecting hardware, libraries, and algorithms for a computation
Other
34 stars 5 forks source link

Add resource for CUDAnative? #7

Open Evizero opened 7 years ago

Evizero commented 7 years ago

One discussion that might be worth having is to differentiate between

  1. supporting CUDAnative, which requires the user to have a self-compiled julia version, or
  2. supporting the executing of *.ptx files using CUDAdrv.

maybe CUDADev vs CUDALibs. ? Whats interesting about CUDAnative is that one can emit and store the produced ptx output, like the following example shows (taken verbatim from https://github.com/JuliaGPU/CUDAnative.jl/blob/master/examples/reduce/benchmark.jl#L16-L22)

# PTX generation
open(joinpath(@__DIR__, "reduce.jl.ptx"), "w") do f
    code_ptx(f, reduce_grid,
                        Tuple{typeof(+), CuDeviceArray{Int32,1},
                              CuDeviceArray{Int32,1}, Int32};
                        cap=v"6.1.0")
end

This means that if one is clever about it, it is possible to ship with pre-compiled ptx kernels to reduce user requirements, while as developers still write everything using CUDAnative

Naturally this is only part of the puzzle, but we gotta start the discussion somewhere :)

timholy commented 7 years ago

I'd be a supporter of such kinds of differentiation. As you surely know, "resources" are pretty thin wrappers, so adding a bazillion of them doesn't seem like a problem, especially when there's a genuine need like in this case.

Evizero commented 7 years ago

One pitfall that came to mind is if there should be some kind of "superset" logic in such a case. For example if someone declares addresource(CUDADev), does (s)he still have to declare addresource(CUDAlib)?

timholy commented 7 years ago

Would the algorithm be shared in any sense? Or would they be executing completely different code?

Evizero commented 7 years ago

In my understanding this was more about declaring capabilities. I didn't really consider shared dispatch. For that purpose ::Union{CUDADev,CUDALib} seems easy enough (?) I am lacking data on this. I'll play around with the idea

timholy commented 7 years ago

Well, the main issue is that the algorithm dispatches on the resource,

myalg(::CPU1, args...) = 1
myalg(::CPUThreads, args...) = 2
...
navidcy commented 6 years ago

@Evizero I'm interested in this feature as well. Have you got around it eventually?

Evizero commented 6 years ago

not so far, no

timholy commented 6 years ago

@navidcy, it's only a couple of lines of code to add a new resource, so if you are ready to use such a feature I'd recommend just submitting a PR.

AFAICT CUDAnative no longer requires a source-build of Julia, so life just keeps getting better :smile:.