File: MapTestClass.cu

package info (click to toggle)
vecgeom 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,928 kB
  • sloc: cpp: 88,717; ansic: 6,894; python: 1,035; sh: 582; sql: 538; makefile: 29
file content (65 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "VecGeom/backend/cuda/Interface.h"
#include "VecGeom/base/Map.h"
class MyClass {
private:
  float fData;

public:
  VECCORE_ATT_HOST_DEVICE
  MyClass() { fData = 0; }
  VECCORE_ATT_HOST_DEVICE
  MyClass(float data) { fData = data; }
  VECCORE_ATT_HOST_DEVICE
  float getData() const { return fData; }
};

__global__ void testNew(vecgeom::map<double, MyClass> *devMap, double *key, int N)
{
  for (int i = 0; i < N; i++) {
    MyClass key1 = (*devMap)[key[i]];
    MyClass key2 = devMap->find(key[i])->second;
    // printf("Key %f, Value from op[] = %f and from find %f\n",key[i],key1, key2);
  }
}

__global__ void rebuildMap(vecgeom::map<double, MyClass> *devMap, double *key, MyClass *value, int N)
{
  //  vecgeom::map<double,double> *myDevMap = new vecgeom::map<double, double>;
  // for (int i=0;i<N;i++)
  // std::cout<<" i "<<value[i]<<std::endl;

  for (int i = 0; i < N; i++) {
    (*devMap)[key[i]] = value[i];
    printf(" REBUILDING key %f and value %f from op[]\n ", key[i], ((*devMap)[key[i]]).getData());
    auto search = devMap->find(key[i]);
    printf(" REBUILDING key %f and value %f from find\n ", key[i], (search->second).getData());
  }
}

namespace vecgeom {
namespace cxx {

template size_t DevicePtr<MyClass>::SizeOf();
template void DevicePtr<MyClass>::Construct() const;
template size_t DevicePtr<cuda::map<double, MyClass>>::SizeOf();
template void DevicePtr<cuda::map<double, MyClass>>::Construct() const;

} // End cxx namespace
}

void launchTestNew(vecgeom::cxx::DevicePtr<vecgeom::cuda::map<double, MyClass>> &devMap,
                   vecgeom::cxx::DevicePtr<double> key, int N, int nBlocks, int nThreads)
{
  int threadsPerBlock = nThreads;
  int blocksPerGrid   = nBlocks;
  testNew<<<blocksPerGrid, threadsPerBlock>>>(devMap, key, N);
}

void launchRebuildMap(vecgeom::cxx::DevicePtr<vecgeom::cuda::map<double, MyClass>> &devMap,
                      vecgeom::cxx::DevicePtr<double> key, vecgeom::cxx::DevicePtr<MyClass> value, int N, int nBlocks,
                      int nThreads)
{
  int threadsPerBlock = nThreads;
  int blocksPerGrid   = nBlocks;
  rebuildMap<<<blocksPerGrid, threadsPerBlock>>>(devMap, key, value, N);
}