-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForce.h
96 lines (74 loc) · 2.29 KB
/
Force.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef FORCE_H
#define FORCE_H
#include <cuda.h>
#include "cuda_utils.h"
//
// Simple strided storage class for forces
//
template <typename T>
class Force {
private:
// Stride of the force data:
// x data is in data[0...size-1];
// y data is in data[stride...stride+size-1];
// z data is in data[stride*2...stride*2+size-1];
//int stride;
// Force data
//int data_len;
//T *data;
int _size;
int _stride;
int _capacity;
T *_xyz;
//cudaXYZ<T> xyz;
public:
Force() {
_size = 0;
_stride = 0;
_capacity = 0;
_xyz = NULL;
}
Force(const int size) {
_size = 0;
_stride = 0;
_capacity = 0;
_xyz = NULL;
this->realloc(size);
}
Force(const char *filename);
~Force() {
if (_xyz != NULL) deallocate<T>(&_xyz);
}
void clear(cudaStream_t stream=0) {
clear_gpu_array<T>(this->_xyz, 3*this->_stride, stream);
}
bool compare(Force<T>& force, const double tol, double& max_diff);
// Re-allocates array, does not preserve content
void realloc(int size, float fac=1.0f) {
this->_size = size;
// Returns stride that aligns with 256 byte boundaries
this->_stride = (( (size-1+32)*sizeof(T) - 1)/256 + 1)*256/sizeof(T);
int new_capacity = (int)((double)(3*this->_stride)*(double)fac);
reallocate<T>(&this->_xyz, &this->_capacity, new_capacity, fac);
}
int stride() {return _stride;}
int size() {return _size;}
T* xyz() {return _xyz;}
T* x() {return &_xyz[0];}
T* y() {return &_xyz[_stride];}
T* z() {return &_xyz[_stride*2];}
void getXYZ(T* h_x, T* h_y, T* h_z);
int stride() const {return _stride;}
int size() const {return _size;}
const T* xyz() const {return _xyz;}
const T* x() const {return &_xyz[0];}
const T* y() const {return &_xyz[_stride];}
const T* z() const {return &_xyz[_stride*2];}
template <typename T2> void convert(Force<T2>& force, cudaStream_t stream=0);
template <typename T2> void convert(cudaStream_t stream=0);
template <typename T2, typename T3> void convert_to(Force<T3>& force, cudaStream_t stream=0);
template <typename T2, typename T3> void convert_add(Force<T3>& force, cudaStream_t stream=0);
template <typename T2> void add(float3 *force_data, int force_n, cudaStream_t stream=0);
template <typename T2> void save(const char* filename);
};
#endif // FORCE_H