forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
constexpr for DetId member functions (cms-sw#55)
Included upstream via cms-sw#23332
- Loading branch information
1 parent
98846e3
commit 402490c
Showing
3 changed files
with
61 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<bin name="test_detid" file="test_detid.cu"> | ||
<use name="DataFormats/DetId"/> | ||
<use name="cuda"/> | ||
</bin> |
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,37 @@ | ||
#include <cuda_runtime.h> | ||
#include <cuda.h> | ||
|
||
#include <iostream> | ||
#include <assert.h> | ||
#include "DataFormats/DetId/interface/DetId.h" | ||
#include "DataFormats/HcalDetId/interface/HcalDetId.h" | ||
|
||
__global__ void test_gen_detid(DetId* id, int const rawid) { | ||
DetId did{rawid}; | ||
*id = did; | ||
} | ||
|
||
void test_detid() { | ||
// test det ids | ||
DetId h_id, h_id_test{100}; | ||
DetId h_test0{1}; | ||
DetId *d_id; | ||
|
||
cudaMalloc((void**)&d_id, sizeof(DetId)); | ||
cudaMemcpy(d_id, &h_id, sizeof(DetId), cudaMemcpyHostToDevice); | ||
test_gen_detid<<<1,1>>>(d_id, 100); | ||
cudaMemcpy(&h_id, d_id, sizeof(DetId), cudaMemcpyDeviceToHost); | ||
|
||
assert(h_id_test == h_id); | ||
assert(h_id != h_test0); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int nDevices; | ||
cudaGetDeviceCount(&nDevices); | ||
std::cout << "nDevices = " << nDevices << std::endl; | ||
|
||
// test det id functionality | ||
if (nDevices > 0) | ||
test_detid(); | ||
} |