Skip to content

Commit 01bea8e

Browse files
author
Ryan M. Bergmann
committed
changed init back to previous device set method, moved stream init to whitory init routine
1 parent 5f0c32f commit 01bea8e

File tree

5 files changed

+74
-45
lines changed

5 files changed

+74
-45
lines changed

main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ int main(int argc, char* argv[]){
313313
// INIT CUDA and HISTORY STUFF and LOAD/UNIONIZE CROS SECTIONS //
314314
/////////////////////////////////////////////////////////////////
315315

316-
unsigned compute_device = 0;
317-
whistory hist ( compute_device, N , geom );
316+
whistory hist ( N , geom );
317+
hist.set_device(0);
318318
hist.init();
319319
hist.print_xs_data();
320320
hist.print_materials_table();
@@ -325,7 +325,7 @@ int main(int argc, char* argv[]){
325325

326326
hist.set_run_type("criticality");
327327
hist.set_tally_cell(tallycell);
328-
hist.set_run_param(400,40); //run, skip
328+
hist.set_run_param(40,20); //run, skip
329329
hist.set_filename(filename);
330330
hist.run();
331331
hist.write_tally(0);

test.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@
7575

7676

7777
# init hist and run
78-
compute_device = int(0)
79-
N_per_cycle = 100000
80-
hist = warp.whistory(compute_device,N_per_cycle,geom)
78+
hist = warp.whistory(100000,geom)
79+
hist.set_device(0)
8180
hist.init()
8281
hist.print_xs_data()
8382
hist.print_materials_table()

whistory.cpp

+33-8
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
optix_stuff optix_obj;
2222
//wgeometry geom_obj;
2323

24-
whistory::whistory(unsigned compute_device_in, unsigned Nin, wgeometry problem_geom_in){
25-
//clear device
26-
cudaDeviceReset();
27-
// device must be set BEFORE an CUDA creation (streams included)
28-
compute_device = compute_device_in;
29-
cudaSetDevice(compute_device);
24+
whistory::whistory(unsigned Nin, wgeometry problem_geom_in){
3025
// do problem gemetry stuff first
3126
problem_geom = problem_geom_in;
3227
// set tally vector length
@@ -42,11 +37,20 @@ whistory::whistory(unsigned compute_device_in, unsigned Nin, wgeometry problem_g
4237
n_qnodes = 0;
4338
reduced_yields_total = 0;
4439
accel_type = "Sbvh";
40+
// default device to 0
41+
compute_device = 0;
42+
// not initialized
43+
is_initialized = 0;
44+
}
45+
void whistory::init(){
46+
// device must be set BEFORE an CUDA creation (streams included)
47+
cudaSetDevice(compute_device);
48+
//clear device
49+
cudaDeviceReset();
50+
// create streams
4551
for (int i = 0; i < 4; ++i){
4652
cudaStreamCreate(&stream[i]);
4753
}
48-
}
49-
void whistory::init(){
5054
// init optix stuff
5155
optix_obj.N=Ndataset;
5256
optix_obj.stack_size_multiplier=1;
@@ -135,6 +139,7 @@ void whistory::init(){
135139
load_cross_sections();
136140
//create_quad_tree();
137141
copy_data_to_device();
142+
is_initialized = 1;
138143
printf("Done with init\n");
139144
}
140145
whistory::~whistory(){
@@ -1889,6 +1894,26 @@ void whistory::set_run_param(unsigned n_cycles_in, unsigned n_skip_in){
18891894
n_skip = n_skip_in;
18901895
n_cycles = n_cycles_in;
18911896

1897+
}
1898+
void whistory::set_device(unsigned dev_in){
1899+
1900+
if (is_initialized){
1901+
printf("Cannot change device after initialization. Device already set to %u\n",compute_device);
1902+
return;
1903+
}
1904+
1905+
//get number to make sure this is a valid device
1906+
int n_devices;
1907+
cudaGetDeviceCount(&n_devices);
1908+
1909+
// set obj
1910+
if(dev_in < n_devices){
1911+
compute_device = dev_in;
1912+
}
1913+
else{
1914+
std::cout << "!!!! Device " << dev_in << " does not exist. Max devices is " << n_devices <<"\n";
1915+
}
1916+
18921917
}
18931918
void whistory::device_report(){
18941919

whistory.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class whistory {
5353
float keff2_sum;
5454
float keff_err;
5555
std::string filename; /**< file name */
56+
unsigned is_initialized; /**< init flag */
5657
source_point * space; /**< source point spatial pointer */
5758
/**
5859
* \brief cross section length numbers
@@ -333,7 +334,7 @@ class whistory {
333334
* \details makes geometry, sets tally vector length, creates dataset size, sets
334335
* compute device and acceleration type, creates CUDA streams.
335336
*/
336-
whistory(unsigned,unsigned,wgeometry);
337+
whistory(unsigned,wgeometry);
337338
/**
338339
* \brief destructor
339340
*/
@@ -405,6 +406,11 @@ class whistory {
405406
* available compute devices
406407
*/
407408
void device_report();
409+
/**
410+
* \brief sets device number to input value
411+
* @param[in] dev_in - device number
412+
*/
413+
void set_device(unsigned);
408414
/**
409415
* \brief does nothing
410416
* @param[in] accel_in - acceleration type

whistory_test.cpp

+29-30
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST_F(whistoryTest, Construction)
1111
{
1212
N = 10000;
1313
wgeometry geom;
14-
whistory construct_hist(0, N, geom);
14+
whistory construct_hist(N, geom);
1515
}
1616

1717
/**
@@ -40,7 +40,7 @@ TEST_F(whistoryTest, SetRunType)
4040
geom.set_outer_cell(999);
4141
geom.update();
4242
geom.check();
43-
whistory hist(0, N, geom);
43+
whistory hist(N, geom);
4444
hist.set_run_type("criticality");
4545
}
4646

@@ -70,7 +70,7 @@ TEST_F(whistoryTest, SetTallyCell)
7070
geom.set_outer_cell(999);
7171
geom.update();
7272
geom.check();
73-
whistory hist(0, N, geom);
73+
whistory hist(N, geom);
7474
hist.set_tally_cell(999);
7575
}
7676

@@ -100,7 +100,7 @@ TEST_F(whistoryTest, SetRunParam)
100100
geom.set_outer_cell(999);
101101
geom.update();
102102
geom.check();
103-
whistory hist(0, N, geom);
103+
whistory hist(N, geom);
104104
hist.set_run_param(40,20);
105105
}
106106

@@ -130,7 +130,7 @@ TEST_F(whistoryTest, SetFilename)
130130
geom.set_outer_cell(999);
131131
geom.update();
132132
geom.check();
133-
whistory hist(0, N, geom);
133+
whistory hist(N, geom);
134134
EXPECT_NO_THROW(hist.set_filename("whistory_test_log.txt"));
135135
}
136136

@@ -140,30 +140,29 @@ TEST_F(whistoryTest, SetFilename)
140140
* \details creates a wgeometry object that contains a fissile material and constructs a whistory with
141141
* that wgeometry. tests that no error is thrown when the device is set.
142142
*/
143-
// NO LONGER IMPLEMENTED
144-
//TEST_F(whistoryTest, SetDevice)
145-
//{
146-
// N = 10000;
147-
// wgeometry geom;
148-
// material = 1;
149-
// is_fissile = 1;
150-
// n_isotopes = 1;
151-
// density = 19.816;
152-
// isotopes.push_back(94239);
153-
// mat_fracs.push_back(1);
154-
// geom.add_material(material,is_fissile,n_isotopes,density,isotopes,mat_fracs);
155-
// type = 3;
156-
// min[0] = -5.1; min[1] = -5.1; min[2] = -5.1;
157-
// max[0] = 5.1; max[1] = 5.1; max[2] = 5.1;
158-
// origin[0] = 0; origin[1] = 0; origin[2] = 0;
159-
// geom.add_primitive(type, material, min, max, origin);
160-
// geom.add_transform(0,999,0,0,0,0,0);
161-
// geom.set_outer_cell(999);
162-
// geom.update();
163-
// geom.check();
164-
// whistory hist(N, geom);
165-
// EXPECT_NO_THROW(hist.set_device(0));
166-
//}
143+
TEST_F(whistoryTest, SetDevice)
144+
{
145+
N = 10000;
146+
wgeometry geom;
147+
material = 1;
148+
is_fissile = 1;
149+
n_isotopes = 1;
150+
density = 19.816;
151+
isotopes.push_back(94239);
152+
mat_fracs.push_back(1);
153+
geom.add_material(material,is_fissile,n_isotopes,density,isotopes,mat_fracs);
154+
type = 3;
155+
min[0] = -5.1; min[1] = -5.1; min[2] = -5.1;
156+
max[0] = 5.1; max[1] = 5.1; max[2] = 5.1;
157+
origin[0] = 0; origin[1] = 0; origin[2] = 0;
158+
geom.add_primitive(type, material, min, max, origin);
159+
geom.add_transform(0,999,0,0,0,0,0);
160+
geom.set_outer_cell(999);
161+
geom.update();
162+
geom.check();
163+
whistory hist(N, geom);
164+
EXPECT_NO_THROW(hist.set_device(0));
165+
}
167166

168167
/**
169168
* \brief initialization test
@@ -191,7 +190,7 @@ TEST_F(whistoryTest, Init)
191190
geom.set_outer_cell(999);
192191
geom.update();
193192
geom.check();
194-
whistory init_hist(0, N, geom);
193+
whistory init_hist(N, geom);
195194
init_hist.init();
196195
}
197196

0 commit comments

Comments
 (0)