@@ -39,6 +39,22 @@ AT_FLOAT *createGrid(AT_FLOAT x1,AT_FLOAT y1,AT_FLOAT x2,AT_FLOAT y2,uint32_t nb
39
39
40
40
}
41
41
42
+ AT_FLOAT *createArc (AT_FLOAT radius,AT_FLOAT startAngle,AT_FLOAT endAngle,uint32_t nbParticles) {
43
+
44
+ uint32_t rinSize = nbParticles * 6 * sizeof (AT_FLOAT);
45
+ AT_FLOAT* rin = (AT_FLOAT*)malloc (rinSize);
46
+ memset (rin,0 ,rinSize);
47
+
48
+ for (int i=0 ;i<nbParticles;i++) {
49
+ AT_FLOAT angle = startAngle + (endAngle-startAngle)*(AT_FLOAT)i/(AT_FLOAT)(nbParticles-1 );
50
+ RINPTR (i)[0 ] = radius*cos (angle);
51
+ RINPTR (i)[2 ] = radius*sin (angle);
52
+ }
53
+
54
+ return rin;
55
+
56
+ }
57
+
42
58
void printGPUInfo () {
43
59
44
60
try {
@@ -51,43 +67,130 @@ void printGPUInfo() {
51
67
52
68
}
53
69
54
- int main ( int argc, char **arv ) {
70
+ Lattice * loadLattice (string latticeName,SymplecticIntegrator& integrator, int gpu, double stepSize= 0.0 ) {
55
71
56
- printGPUInfo ();
57
-
58
- SymplecticIntegrator integrator (4 );
59
72
CppInterface *dI = new CppInterface ();
60
73
AbstractInterface::setHandler (dI);
61
74
vector<CppObject> elements;
62
- int DEVID = 1 ;
63
75
76
+ REPRLoader *loader = new REPRLoader (latticeName);
77
+ loader->parseREPR (elements);
78
+ if ( stepSize!=0.0 ) {
79
+ // Adjust NumIntSteps to be as close as possible to stepSize
80
+ for (auto & element : elements) {
81
+ try {
82
+ // For element that has NumIntSteps attribute
83
+ string &stepStr = element.getField (" NumIntSteps" );
84
+ string &lengthStr = element.getField (" Length" );
85
+ double length = stod (lengthStr);
86
+ int nstep = (int )((length / stepSize)+0.5 );
87
+ if (nstep<1 ) nstep = 1 ;
88
+ element.addField (" NumIntSteps" , to_string (nstep));
89
+ } catch (string&) {
90
+ }
91
+ }
92
+ }
93
+ delete loader;
64
94
65
- try {
66
- // REPRLoader *loader = new REPRLoader("Z:/tmp/pons/at/test/lattice/betamodel_radon.repr");
67
- REPRLoader *loader = new REPRLoader (" /segfs/tmp/pons/at/test/lattice/betamodel_radon.repr" );
68
- // REPRLoader *loader = new REPRLoader("/segfs/tmp/pons/lattice/simple_ebs.repr");
69
- loader->parseREPR (elements);
70
- } catch (string& errStr) {
71
- cout << " Parse failed: " << errStr << endl;
72
- exit (0 );
95
+ Lattice *l = new Lattice (0 , integrator, 6e9 , gpu);
96
+ double t0 = AbstractGPU::get_ticks ();
97
+ for (auto &element: elements) {
98
+ dI->setObject (&element);
99
+ l->addElement ();
73
100
}
101
+ l->generateGPUKernel ();
102
+ double t1 = AbstractGPU::get_ticks ();
103
+ cout << " Ring build: " << (t1 - t0) * 1000.0 << " ms" << endl;
104
+
105
+ t0 = AbstractGPU::get_ticks ();
106
+ l->fillGPUMemory ();
107
+ t1 = AbstractGPU::get_ticks ();
108
+ cout << " GPU lattice loading: " << (t1 - t0) * 1000.0 << " ms" << endl;
109
+
110
+ return l;
111
+
112
+ }
113
+
114
+ void integratorTest (int gpu,string latticeName) {
115
+
116
+ SymplecticIntegrator integrator (4 );
117
+
118
+ npy::npy_data<double > refPoints = npy::read_npy<double >(" /segfs/tmp/pons/at/test/data/ref_arc_yfr_10000.npy" );
74
119
75
120
try {
76
121
77
- Lattice *l = new Lattice (0 , integrator, 6e9 , DEVID);
78
- double t0 = AbstractGPU::get_ticks ();
79
- for (auto &element: elements) {
80
- dI->setObject (&element);
81
- l->addElement ();
122
+ for (int integ=1 ;integ<7 ;integ++) {
123
+
124
+ integrator.setType (integ);
125
+ Lattice *l = loadLattice (latticeName,integrator,gpu,0.01 );
126
+
127
+ uint32_t nbTurn = 1 ;
128
+ uint32_t nbPart = 256 ;
129
+ uint32_t refs[] = {l->getNbElement ()};
130
+ uint32_t nbRef = sizeof (refs) / sizeof (uint32_t );
131
+ uint64_t routSize = nbTurn * nbPart * nbRef * 6 * sizeof (AT_FLOAT);
132
+ AT_FLOAT *rout = (AT_FLOAT *) malloc (routSize);
133
+
134
+ // Choose an arc close to 1mm where unexpected tune drift is observed when step size in too small (EBS lattice)
135
+ AT_FLOAT *rin = createArc (0.001 ,M_PI/2.0 ,-M_PI/2.0 ,nbPart);
136
+
137
+ l->run (nbTurn, nbPart, rin, rout, nbRef, refs, 0 , nullptr , nullptr , nullptr , nullptr );
138
+
139
+ double err = 0 ;
140
+ double max = 0 ;
141
+ int pMax;
142
+ int cMax;
143
+ for (int p=0 ;p<256 ;p++) {
144
+ AT_FLOAT *P = ROUTPTR (p, 0 , nbTurn - 1 );
145
+ err += SQR (P[0 ] - refPoints.data [p*6 +0 ]);
146
+ err += SQR (P[1 ] - refPoints.data [p*6 +1 ]);
147
+ err += SQR (P[2 ] - refPoints.data [p*6 +2 ]);
148
+ err += SQR (P[3 ] - refPoints.data [p*6 +3 ]);
149
+ err += SQR (P[4 ] - refPoints.data [p*6 +4 ]);
150
+ err += SQR (P[5 ] - refPoints.data [p*6 +5 ]);
151
+ if ( abs (P[0 ] - refPoints.data [p*6 +0 ])>max ) {max = abs (P[0 ] - refPoints.data [p*6 +0 ]);pMax=p;cMax=0 ;}
152
+ if ( abs (P[1 ] - refPoints.data [p*6 +1 ])>max ) {max = abs (P[1 ] - refPoints.data [p*6 +1 ]);pMax=p;cMax=1 ;}
153
+ if ( abs (P[2 ] - refPoints.data [p*6 +2 ])>max ) {max = abs (P[2 ] - refPoints.data [p*6 +2 ]);pMax=p;cMax=2 ;}
154
+ if ( abs (P[3 ] - refPoints.data [p*6 +3 ])>max ) {max = abs (P[3 ] - refPoints.data [p*6 +3 ]);pMax=p;cMax=3 ;}
155
+ if ( abs (P[4 ] - refPoints.data [p*6 +4 ])>max ) {max = abs (P[4 ] - refPoints.data [p*6 +4 ]);pMax=p;cMax=4 ;}
156
+ if ( abs (P[5 ] - refPoints.data [p*6 +5 ])>max ) {max = abs (P[5 ] - refPoints.data [p*6 +5 ]);pMax=p;cMax=5 ;}
157
+ }
158
+ err = sqrt (err) / (6.0 *256.0 );
159
+ AT_FLOAT *P = ROUTPTR (pMax, 0 , nbTurn - 1 );
160
+ cout << " [" << integ << " ]" << err << " max=" << max << " @" << P[cMax] << " " << abs (max/P[cMax]) << endl;
161
+
162
+ /*
163
+ if( integ==4 ) {
164
+ // Save ref
165
+ npy::npy_data_ptr<double> d;
166
+ d.data_ptr = (double *) rout;
167
+ d.shape = {6, nbPart, nbRef, nbTurn};
168
+ d.fortran_order = true;
169
+ npy::write_npy("/segfs/tmp/pons/at/test/data/ref_arc_yfr_10000.npy", d);
170
+ }
171
+ */
172
+
173
+ free (rout);
174
+ free (rin);
175
+ delete l;
176
+
82
177
}
83
- l->generateGPUKernel ();
84
- double t1 = AbstractGPU::get_ticks ();
85
- cout << " Ring build: " << (t1 - t0) * 1000.0 << " ms" << endl;
86
178
87
- t0 = AbstractGPU::get_ticks ();
88
- l->fillGPUMemory ();
89
- t1 = AbstractGPU::get_ticks ();
90
- cout << " GPU lattice loading: " << (t1 - t0) * 1000.0 << " ms" << endl;
179
+ } catch (string& errStr) {
180
+ string err = " Fail: " + errStr;
181
+ cout << " Error: " << err << endl;
182
+ }
183
+
184
+ }
185
+
186
+ void performanceTest (int gpu,string latticeName) {
187
+
188
+ double t0,t1;
189
+ SymplecticIntegrator integrator (4 );
190
+
191
+ try {
192
+
193
+ Lattice *l = loadLattice (latticeName,integrator,gpu);
91
194
92
195
string gpuName = l->getGPUContext ()->name ();
93
196
cout << " Running test on " << gpuName << " (" << l->getGPUContext ()->coreNumber () << " units)"
@@ -108,6 +211,7 @@ int main(int argc,char **arv) {
108
211
uint32_t nbRef = sizeof (refs) / sizeof (uint32_t );
109
212
uint32_t starts[] = {0 ,100 ,200 ,300 ,400 ,500 ,600 ,700 };
110
213
uint32_t nbStride = sizeof (starts) / sizeof (uint32_t );
214
+ // uint32_t nbStride = 0;
111
215
112
216
uint64_t routSize = nbTurn * nbPart * nbRef * 6 * sizeof (AT_FLOAT);
113
217
AT_FLOAT *rout = (AT_FLOAT *) malloc (routSize);
@@ -168,10 +272,21 @@ int main(int argc,char **arv) {
168
272
delete l;
169
273
170
274
} catch (string& errStr) {
171
- string err = " at_gpupass() failed : " + errStr;
275
+ string err = " Fail : " + errStr;
172
276
cout << " Error: " << err << endl;
173
277
}
174
278
279
+ }
280
+
281
+ int main (int argc,char **arv) {
282
+
283
+ // printGPUInfo();
284
+
285
+ int DEVID = 0 ;
286
+ // performanceTest(DEVID,"Z:/tmp/pons/at/test/lattice/betamodel_radon.repr");
287
+ performanceTest (DEVID," /segfs/tmp/pons/at/test/lattice/betamodel_radon.repr" );
288
+ // performanceTest(DEVID,"/segfs/tmp/pons/lattice/simple_ebs.repr");
289
+ // integratorTest(DEVID,"/segfs/tmp/pons/at/test/lattice/betamodel_radon.repr");
175
290
176
291
return 0 ;
177
292
0 commit comments