-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More constness, removal of vector copies, and movement of general-pur…
…pose alpaka functions
- Loading branch information
Showing
30 changed files
with
863 additions
and
815 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
HeterogeneousCore/AlpakaInterface/interface/binarySearch.h
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef HeterogeneousCore_AlpakaInterface_interface_binarySearch_h | ||
#define HeterogeneousCore_AlpakaInterface_interface_binarySearch_h | ||
|
||
namespace cms::alpakatools { | ||
|
||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE int binary_search(const unsigned int* data, // Array that we are searching over | ||
const unsigned int search_val, // Value we want to find in data array | ||
const unsigned int ndata) // Number of elements in data array | ||
{ | ||
unsigned int low = 0; | ||
unsigned int high = ndata - 1; | ||
|
||
while (low <= high) { | ||
unsigned int mid = (low + high) / 2; | ||
unsigned int test_val = data[mid]; | ||
if (test_val == search_val) | ||
return mid; | ||
else if (test_val > search_val) | ||
high = mid - 1; | ||
else | ||
low = mid + 1; | ||
} | ||
// Couldn't find search value in array. | ||
return -1; | ||
}; | ||
|
||
} // namespace cms::alpakatools | ||
|
||
#endif // HeterogeneousCore_AlpakaInterface_interface_binarySearch_h |
57 changes: 57 additions & 0 deletions
57
HeterogeneousCore/AlpakaInterface/interface/geomFunctions.h
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef HeterogeneousCore_AlpakaInterface_interface_geomFunctions_h | ||
#define HeterogeneousCore_AlpakaInterface_interface_geomFunctions_h | ||
|
||
namespace cms::alpakatools { | ||
|
||
template <typename TAcc> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float eta(TAcc const& acc, const float x, const float y, const float z) { | ||
float r3 = alpaka::math::sqrt(acc, x * x + y * y + z * z); | ||
float rt = alpaka::math::sqrt(acc, x * x + y * y); | ||
float eta = ((z > 0) - (z < 0)) * alpaka::math::acosh(acc, r3 / rt); | ||
return eta; | ||
}; | ||
|
||
template <typename TAcc> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi_mpi_pi(TAcc const& acc, const float x) { | ||
if (alpaka::math::abs(acc, x) <= float(M_PI)) | ||
return x; | ||
|
||
constexpr float o2pi = 1.f / (2.f * float(M_PI)); | ||
float n = alpaka::math::round(acc, x * o2pi); | ||
return x - n * float(2.f * float(M_PI)); | ||
}; | ||
|
||
template <typename TAcc> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float phi(TAcc const& acc, const float x, const float y) { | ||
return phi_mpi_pi(acc, float(M_PI) + alpaka::math::atan2(acc, -y, -x)); | ||
}; | ||
|
||
template <typename TAcc> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhi(TAcc const& acc, const float x1, const float y1, const float x2, const float y2) { | ||
float phi1 = phi(acc, x1, y1); | ||
float phi2 = phi(acc, x2, y2); | ||
return phi_mpi_pi(acc, (phi2 - phi1)); | ||
}; | ||
|
||
template <typename TAcc> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE float deltaPhiChange(TAcc const& acc, const float x1, const float y1, const float x2, const float y2) { | ||
return deltaPhi(acc, x1, y1, x2 - x1, y2 - y1); | ||
}; | ||
|
||
ALPAKA_FN_ACC ALPAKA_FN_INLINE float calculate_dPhi(const float phi1, const float phi2) { | ||
// Calculate dPhi | ||
float dPhi = phi1 - phi2; | ||
|
||
// Normalize dPhi to be between -pi and pi | ||
if (dPhi > float(M_PI)) { | ||
dPhi -= 2 * float(M_PI); | ||
} else if (dPhi < -float(M_PI)) { | ||
dPhi += 2 * float(M_PI); | ||
} | ||
|
||
return dPhi; | ||
}; | ||
|
||
} // namespace cms::alpakatools | ||
|
||
#endif // HeterogeneousCore_AlpakaInterface_interface_geomFunctions_h |
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
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.