-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Patatrack integration - common tools (2/N) #29110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce7301f
Add common tools for processing on GPUs
VinInn 9b10f92
CUDA does not support C++17 yet, so we define here some of the missin…
fwyzard e4ead5a
Implement vector-like classes for use on GPUs
felicepantaleo 020fdd1
Update BuildFile
fwyzard 35ffe1f
Fix AtomicPairCounter unit test
fwyzard bfc0df7
Rename the cudaCompat namespace to cms::cudacompat
fwyzard 85a0b47
Remove extra semicolon
fwyzard 591a0c3
Move SimpleVector and VecArray to the cms::cuda namespace
fwyzard f4dc650
Add missing dependency
fwyzard 68de0b3
Move HistoContainer, AtomicPairCounter, prefixScan and radixSort to t…
fwyzard d76ad8e
Fix code rule violations
fwyzard 1f91c73
Add an exception for cudaCompat.h
fwyzard c52b855
Protect the header to compile only with a CUDA compiler
fwyzard 6248000
choleskyInversion.h: expand source notice
fwyzard 8ce9631
Rename namespace choleskyInversion to math::cholesky
fwyzard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
DataFormats/GeometrySurface/test/gpuFrameTransformKernel.cu
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <cstdint> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
|
|
||
| #include "DataFormats/GeometrySurface/interface/SOARotation.h" | ||
| #include "HeterogeneousCore/CUDAUtilities/interface/launch.h" | ||
|
|
||
| __global__ void toGlobal(SOAFrame<float> const* frame, | ||
| float const* xl, | ||
| float const* yl, | ||
| float* x, | ||
| float* y, | ||
| float* z, | ||
| float const* le, | ||
| float* ge, | ||
| uint32_t n) { | ||
| int i = blockDim.x * blockIdx.x + threadIdx.x; | ||
| if (i >= n) | ||
| return; | ||
|
|
||
| frame[0].toGlobal(xl[i], yl[i], x[i], y[i], z[i]); | ||
| frame[0].toGlobal(le[3 * i], le[3 * i + 1], le[3 * i + 2], ge + 6 * i); | ||
| } | ||
|
|
||
| void toGlobalWrapper(SOAFrame<float> const* frame, | ||
| float const* xl, | ||
| float const* yl, | ||
| float* x, | ||
| float* y, | ||
| float* z, | ||
| float const* le, | ||
| float* ge, | ||
| uint32_t n) { | ||
| int threadsPerBlock = 256; | ||
| int blocksPerGrid = (n + threadsPerBlock - 1) / threadsPerBlock; | ||
| std::cout << "CUDA toGlobal kernel launch with " << blocksPerGrid << " blocks of " << threadsPerBlock << " threads" | ||
| << std::endl; | ||
|
|
||
| cms::cuda::launch(toGlobal, {blocksPerGrid, threadsPerBlock}, frame, xl, yl, x, y, z, le, ge, n); | ||
| } |
114 changes: 114 additions & 0 deletions
114
DataFormats/GeometrySurface/test/gpuFrameTransformTest.cpp
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <cmath> | ||
| #include <cstdint> | ||
| #include <cstdint> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <numeric> | ||
|
|
||
| #include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h" | ||
| #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" | ||
| #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h" | ||
| #include "DataFormats/GeometrySurface/interface/SOARotation.h" | ||
| #include "DataFormats/GeometrySurface/interface/TkRotation.h" | ||
| #include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h" | ||
|
|
||
| void toGlobalWrapper(SOAFrame<float> const *frame, | ||
| float const *xl, | ||
| float const *yl, | ||
| float *x, | ||
| float *y, | ||
| float *z, | ||
| float const *le, | ||
| float *ge, | ||
| uint32_t n); | ||
|
|
||
| int main(void) { | ||
| cms::cudatest::requireDevices(); | ||
|
|
||
| typedef float T; | ||
| typedef TkRotation<T> Rotation; | ||
| typedef SOARotation<T> SRotation; | ||
| typedef GloballyPositioned<T> Frame; | ||
| typedef SOAFrame<T> SFrame; | ||
| typedef typename Frame::PositionType Position; | ||
| typedef typename Frame::GlobalVector GlobalVector; | ||
| typedef typename Frame::GlobalPoint GlobalPoint; | ||
| typedef typename Frame::LocalVector LocalVector; | ||
| typedef typename Frame::LocalPoint LocalPoint; | ||
|
|
||
| constexpr uint32_t size = 10000; | ||
| constexpr uint32_t size32 = size * sizeof(float); | ||
|
|
||
| float xl[size], yl[size]; | ||
| float x[size], y[size], z[size]; | ||
|
|
||
| // errors | ||
| float le[3 * size]; | ||
| float ge[6 * size]; | ||
|
|
||
| auto d_xl = cms::cuda::make_device_unique<float[]>(size, nullptr); | ||
| auto d_yl = cms::cuda::make_device_unique<float[]>(size, nullptr); | ||
|
|
||
| auto d_x = cms::cuda::make_device_unique<float[]>(size, nullptr); | ||
| auto d_y = cms::cuda::make_device_unique<float[]>(size, nullptr); | ||
| auto d_z = cms::cuda::make_device_unique<float[]>(size, nullptr); | ||
|
|
||
| auto d_le = cms::cuda::make_device_unique<float[]>(3 * size, nullptr); | ||
| auto d_ge = cms::cuda::make_device_unique<float[]>(6 * size, nullptr); | ||
|
|
||
| double a = 0.01; | ||
| double ca = std::cos(a); | ||
| double sa = std::sin(a); | ||
|
|
||
| Rotation r1(ca, sa, 0, -sa, ca, 0, 0, 0, 1); | ||
| Frame f1(Position(2, 3, 4), r1); | ||
| std::cout << "f1.position() " << f1.position() << std::endl; | ||
| std::cout << "f1.rotation() " << '\n' << f1.rotation() << std::endl; | ||
|
|
||
| SFrame sf1(f1.position().x(), f1.position().y(), f1.position().z(), f1.rotation()); | ||
|
|
||
| auto d_sf = cms::cuda::make_device_unique<char[]>(sizeof(SFrame), nullptr); | ||
| cudaCheck(cudaMemcpy(d_sf.get(), &sf1, sizeof(SFrame), cudaMemcpyHostToDevice)); | ||
|
|
||
| for (auto i = 0U; i < size; ++i) { | ||
| xl[i] = yl[i] = 0.1f * float(i) - float(size / 2); | ||
| le[3 * i] = 0.01f; | ||
| le[3 * i + 2] = (i > size / 2) ? 1.f : 0.04f; | ||
| le[2 * i + 1] = 0.; | ||
| } | ||
| std::random_shuffle(xl, xl + size); | ||
| std::random_shuffle(yl, yl + size); | ||
|
|
||
| cudaCheck(cudaMemcpy(d_xl.get(), xl, size32, cudaMemcpyHostToDevice)); | ||
| cudaCheck(cudaMemcpy(d_yl.get(), yl, size32, cudaMemcpyHostToDevice)); | ||
| cudaCheck(cudaMemcpy(d_le.get(), le, 3 * size32, cudaMemcpyHostToDevice)); | ||
|
|
||
| toGlobalWrapper((SFrame const *)(d_sf.get()), | ||
| d_xl.get(), | ||
| d_yl.get(), | ||
| d_x.get(), | ||
| d_y.get(), | ||
| d_z.get(), | ||
| d_le.get(), | ||
| d_ge.get(), | ||
| size); | ||
| cudaCheck(cudaMemcpy(x, d_x.get(), size32, cudaMemcpyDeviceToHost)); | ||
| cudaCheck(cudaMemcpy(y, d_y.get(), size32, cudaMemcpyDeviceToHost)); | ||
| cudaCheck(cudaMemcpy(z, d_z.get(), size32, cudaMemcpyDeviceToHost)); | ||
| cudaCheck(cudaMemcpy(ge, d_ge.get(), 6 * size32, cudaMemcpyDeviceToHost)); | ||
|
|
||
| float eps = 0.; | ||
| for (auto i = 0U; i < size; ++i) { | ||
| auto gp = f1.toGlobal(LocalPoint(xl[i], yl[i])); | ||
| eps = std::max(eps, std::abs(x[i] - gp.x())); | ||
| eps = std::max(eps, std::abs(y[i] - gp.y())); | ||
| eps = std::max(eps, std::abs(z[i] - gp.z())); | ||
| } | ||
|
|
||
| std::cout << "max eps " << eps << std::endl; | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or 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,6 +1,7 @@ | ||
| <use name="DataFormats/Common"/> | ||
| <use name="rootmath"/> | ||
| <use name="eigen"/> | ||
fwyzard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <use name="rootmath"/> | ||
| <use name="DataFormats/Common"/> | ||
|
|
||
| <export> | ||
| <lib name="1"/> | ||
| <lib name="1"/> | ||
| </export> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.