Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ff/camera
- Loading branch information
Showing
72 changed files
with
1,519 additions
and
1,206 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,68 @@ | ||
using CUDA, GLMakie | ||
using CUDA, GLMakie, NVTX | ||
using GLMakie.GLAbstraction | ||
# from https://discourse.julialang.org/t/cuarray-glmakie/52461/11?u=maleadt | ||
|
||
function cu_plot(; T=Float32, N=1024, resolution=(800, 600)) | ||
t = CUDA.rand(T, N) | ||
X = CUDA.rand(T, N) | ||
|
||
scene = scatter(rand(Point2f, 10_000), show_axis=false) | ||
screen = display(scene) | ||
# so that we can create a GLBuffer before having rendered anything. | ||
fig = Figure(; resolution) | ||
ax = Axis(fig[1, 1]; limits=(0, 1, 0, 1)) | ||
screen = display(fig) | ||
|
||
buffer = screen.renderlist[1][3][:position] | ||
resource = | ||
cuGraphicsGLRegisterBuffer(&resource, pbo, cudaGraphicsRegisterFlagsReadOnly) | ||
# get a buffer object and register it with CUDA | ||
buffer = GLAbstraction.GLBuffer(Point2f, N) | ||
resource = let | ||
ref = Ref{CUDA.CUgraphicsResource}() | ||
CUDA.cuGraphicsGLRegisterBuffer(ref, buffer.id, | ||
CUDA.CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD) | ||
ref[] | ||
end | ||
|
||
CUDA.cuGraphicsMapResources | ||
NVTX.@range "main" begin | ||
# process data, generate points | ||
NVTX.@range "CUDA" begin | ||
# map OpenGL buffer object for writing from CUDA | ||
CUDA.cuGraphicsMapResources(1, [resource], stream()) | ||
|
||
# get a CuArray object that we can work with | ||
array = let | ||
ptr_ref = Ref{CUDA.CUdeviceptr}() | ||
numbytes_ref = Ref{Csize_t}() | ||
CUDA.cuGraphicsResourceGetMappedPointer_v2(ptr_ref, numbytes_ref, resource) | ||
|
||
ptr = reinterpret(CuPtr{Point2f}, ptr_ref[]) | ||
len = Int(numbytes_ref[] ÷ sizeof(Point2f)) | ||
|
||
unsafe_wrap(CuArray, ptr, len) | ||
end | ||
|
||
# generate points | ||
broadcast!(array, t, X) do x, y | ||
return Point2f(x, y) | ||
end | ||
|
||
# wait for the GPU to finish | ||
synchronize() | ||
|
||
CUDA.cuGraphicsUnmapResources(1, [resource], stream()) | ||
end | ||
|
||
# generate and render plot | ||
NVTX.@range "Makie" begin | ||
scatter!(ax, buffer) | ||
# force everything to render (for benchmarking purposes) | ||
GLMakie.render_frame(screen; resize_buffers=false) | ||
GLMakie.glFinish() | ||
end | ||
end | ||
|
||
## clean-up | ||
|
||
CUDA.cuGraphicsUnregisterResource(resource) | ||
|
||
return | ||
end | ||
|
||
cu_plot() |
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
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
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
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
Oops, something went wrong.