Skip to content

Commit

Permalink
performance increasing update
Browse files Browse the repository at this point in the history
-50% performance increase on medium sized systems with DDI (256x256x64 open system with DDI jumped from 50 to 75 IPS on VP-OSO)
-fixed energy calculation for custom geometries (now we divide only by amount of nonzero spins)
-ui bugfix
  • Loading branch information
DTolm committed Sep 1, 2020
1 parent 8b1f6aa commit fda7fc3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 29 deletions.
8 changes: 6 additions & 2 deletions core/include/data/Vulkan_Compute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace VulkanCompute
scalar max_move=200;
scalar kernel_accuracy=6.0;
int GPU_ID=0;
int num_nonzero_Ms = 1;
} VulkanSpiritLaunchConfiguration;

typedef struct {
Expand Down Expand Up @@ -670,7 +671,7 @@ namespace VulkanCompute
forward_configuration.isInputFormatted = false;
forward_configuration.isOutputFormatted = false;
forward_configuration.device = &device;

forward_configuration.coalescedMemory = 32;
sprintf(forward_configuration.shaderPath, SHADER_DIR);

bufferSizeKernel = forward_configuration.coordinateFeatures * 2 * sizeof(scalar) * (forward_configuration.size[0] / 2 + 1) * (forward_configuration.size[1]) * (forward_configuration.size[2]);
Expand Down Expand Up @@ -755,9 +756,12 @@ namespace VulkanCompute
free( data_regions_book);
}
void updateRegions(int* regions) {
launchConfiguration.num_nonzero_Ms = SIZES[0] * SIZES[1] * SIZES[2];
int* data_regions = (int*)malloc(sizeof(int) * SIZES[0] * SIZES[1] * SIZES[2]);
for (uint32_t i = 0; i < SIZES[0] * SIZES[1] * SIZES[2]; ++i) {
data_regions[i] = regions[i];
if (regions_book_local[regions[i]].Ms == 0)
launchConfiguration.num_nonzero_Ms--;
}
transferDataFromCPU(data_regions, bufferSizeRegions, &bufferRegions);
free( data_regions);
Expand Down Expand Up @@ -1072,7 +1076,7 @@ namespace VulkanCompute

MaxForce[0] = temp[0];
for (int i = 1; i < 6; i++) {
energy[i-1] = temp[i] * 0.5f * regions_book_local[0].Ms;
energy[i-1] = temp[i] * 0.5f;
}
meanMag[0][0] = temp[6];
meanMag[0][1] = temp[7];
Expand Down
9 changes: 5 additions & 4 deletions core/include/engine/Solver_CG_OSO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ void Method_Solver<Solver::CG_OSO>::Iteration ()
scalar max_Force;
scalar time;
this->systems[0]->app.getEnergy(energy, &meanMag, &max_Force, &time);

energy[0] *= 2;
for (int i = 0; i < 5; i++) {
energy_full += energy[i];
this->systems[0]->hamiltonian->energy_array[i].second = energy[i];
energy[i] /= this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
energy_full += energy[i];
}

this->systems[0]->M = meanMag / (this->systems[0]->geometry->nos);
this->systems[0]->M = meanMag / this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
//scalar max_Force =this->systems[0]->app.getMaxForce();
if (this->force_max_abs_component == sqrt(max_Force)) this->systems[0]->iteration_allowed = false;
this->force_max_abs_component = sqrt(max_Force);
if (this->force_max_abs_component < this->systems[0]->app.launchConfiguration.maxTorque) this->systems[0]->iteration_allowed = false;
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full << " Ezeeman: " << energy[0] << " Eanis: " << energy[1] << " Eexch: " << energy[2] << " Edmi: " << energy[3] << " Eddi: " << energy[4] << "\n";

}

Expand Down
9 changes: 5 additions & 4 deletions core/include/engine/Solver_Depondt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ void Method_Solver<Solver::Depondt>::Iteration ()
this->systems[0]->app.getEnergy(energy, &meanMag, &max_Force, &time);
energy[0] *= 2;
for (int i = 0; i < 5; i++) {
energy_full += energy[i];
this->systems[0]->hamiltonian->energy_array[i].second = energy[i];
energy[i] /= this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
energy_full += energy[i];
}
//this->systems[0]->hamiltonian->energy_contributions_per_spin[0].second[0] = energy_full;
this->systems[0]->M = meanMag / this->systems[0]->geometry->nos;
this->systems[0]->M = meanMag / this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
//scalar max_Force =this->systems[0]->app.getMaxForce();
this->force_max_abs_component = sqrt(max_Force);
std::cout << "time_const_dt(ps): " << iterations * this->systems[0]->app.launchConfiguration.groupedIterations * this->systems[0]->app.launchConfiguration.gamma / 0.176085964411 << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
std::cout << "time_const_dt(ps): " << iterations * this->systems[0]->app.launchConfiguration.groupedIterations * this->systems[0]->app.launchConfiguration.gamma / 0.176085964411 << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full << " Ezeeman: " << energy[0] << " Eanis: " << energy[1] << " Eexch: " << energy[2] << " Edmi: " << energy[3] << " Eddi: " << energy[4] << "\n";

//std::cout << "Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
//std::cout << "Efull: " << energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << "\n";
//std::cout << "time_const_dt(ps): " << iterations* this->systems[0]->app.launchConfiguration.groupedIterations* this->systems[0]->app.launchConfiguration.gamma/ 0.176085964411 << " time GPU(ps): "<< time <<" maxForce: " << max_Force << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << "\n";
this->systems[0]->hamiltonian->picoseconds_passed = time;
}
Expand Down
13 changes: 7 additions & 6 deletions core/include/engine/Solver_LBFGS_OSO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,29 @@ void Method_Solver<Solver::LBFGS_OSO>::Iteration()
this->systems[0]->app.getEnergy(energy, &meanMag, &max_Force, &maxmove);
energy[0] *= 2;
for (int i = 0; i < 5; i++) {
energy_full += energy[i] ;
this->systems[0]->hamiltonian->energy_array[i].second = energy[i];
energy[i] /= this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
energy_full += energy[i];
}
//this->systems[0]->hamiltonian->energy_contributions_per_spin[0].second[0] = energy_full;
this->systems[0]->M = meanMag/ (this->systems[0]->geometry->nos);
this->systems[0]->M = meanMag/ this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
//scalar max_Force =this->systems[0]->app.getMaxForce();
//if (this->force_max_abs_component == sqrt(max_Force)) this->systems[0]->iteration_allowed = false;

this->force_max_abs_component = sqrt(max_Force);
if (this->force_max_abs_component < this->systems[0]->app.launchConfiguration.maxTorque) this->systems[0]->iteration_allowed = false;
//std::cout << "maxTorque: " << this->force_max_abs_component<<" Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " m_sum: " << this->systems[0]->M[0]+ this->systems[0]->M[1]+this->systems[0]->M[2] <<" Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
//std::cout << "maxTorque: " << this->force_max_abs_component<<" Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " m_sum: " << this->systems[0]->M[0]+ this->systems[0]->M[1]+this->systems[0]->M[2] <<" Efull: " << energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << "\n";
/*if (iterations == 0) {
std::ofstream outfile;
outfile.open("output/2506/energy.txt", std::ios_base::app);
outfile << "init field: "<< " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " m_sum: " << this->systems[0]->M[0] + this->systems[0]->M[1] + this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
outfile << "init field: "<< " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " m_sum: " << this->systems[0]->M[0] + this->systems[0]->M[1] + this->systems[0]->M[2] << " Efull: " << energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << "\n";
}
*/
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full << " Ezeeman: " << energy[0] << " Eanis: " << energy[1] << " Eexch: " << energy[2] << " Edmi: " << energy[3] << " Eddi: " << energy[4] << "\n";

//std::cout <<"Efull: "<< energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
//std::cout <<"Efull: "<< energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << "\n";
//std::cout <<"maxForce: " << sqrt(max_Force) << " maxmove: " << maxmove << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << "\n";

//this->systems[0]->app.writeGradient((*this->configurations[0]).data());
Expand Down
7 changes: 4 additions & 3 deletions core/include/engine/Solver_RK4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ void Method_Solver<Solver::RungeKutta4>::Iteration ()
this->systems[0]->app.getEnergy(energy, &meanMag, &max_Force, &time);
energy[0] *= 2;
for (int i = 0; i < 5; i++) {
energy_full += energy[i];
this->systems[0]->hamiltonian->energy_array[i].second = energy[i];
energy[i] /= this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
energy_full += energy[i];
}
//this->systems[0]->hamiltonian->energy_contributions_per_spin[0].second[0] = energy_full;
this->systems[0]->M = meanMag / this->systems[0]->geometry->nos;
this->systems[0]->M = meanMag / this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
//scalar max_Force =this->systems[0]->app.getMaxForce();
this->force_max_abs_component = sqrt(max_Force);

std::cout << "time_const_dt(ps): " << iterations * this->systems[0]->app.launchConfiguration.groupedIterations * this->systems[0]->app.launchConfiguration.gamma / 0.176085964411 << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
std::cout << "time_const_dt(ps): " << iterations * this->systems[0]->app.launchConfiguration.groupedIterations * this->systems[0]->app.launchConfiguration.gamma / 0.176085964411 << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full << " Ezeeman: " << energy[0] << " Eanis: " << energy[1] << " Eexch: " << energy[2] << " Edmi: " << energy[3] << " Eddi: " << energy[4] << "\n";
//std::cout << "time_const_dt(ps): " << iterations * this->systems[0]->app.launchConfiguration.groupedIterations * this->systems[0]->app.launchConfiguration.gamma / 0.176085964411 << " time GPU(ps): " << time << " maxForce: " << max_Force << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << "\n";
this->systems[0]->hamiltonian->picoseconds_passed = time;
}
Expand Down
28 changes: 24 additions & 4 deletions core/include/engine/Solver_VP_OSO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,37 @@ void Method_Solver<Solver::VP_OSO>::Iteration ()
this->systems[0]->app.getEnergy(energy, &meanMag, &max_Force, &time);
energy[0] *= 2;
for (int i = 0; i < 5; i++) {
energy_full += energy[i];
this->systems[0]->hamiltonian->energy_array[i].second = energy[i];
energy[i] /= this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
energy_full += energy[i];
}
//this->systems[0]->hamiltonian->energy_contributions_per_spin[0].second[0] = energy_full;
//this->systems[0]->M = meanMag / this->systems[0]->geometry->nos;
this->systems[0]->M = meanMag / (this->systems[0]->geometry->nos);
//this->systems[0]->M = meanMag / num_nonzero_Ms;

this->systems[0]->M = meanMag / this->systems[0]->app.launchConfiguration.num_nonzero_Ms;
//scalar max_Force =this->systems[0]->app.getMaxForce();
//if (this->force_max_abs_component == sqrt(max_Force)) this->systems[0]->iteration_allowed = false;
this->force_max_abs_component = sqrt(max_Force);
if (this->force_max_abs_component < this->systems[0]->app.launchConfiguration.maxTorque) this->systems[0]->iteration_allowed = false;
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / this->systems[0]->geometry->nos << " Ezeeman: " << energy[0] / this->systems[0]->geometry->nos << " Eanis: " << energy[1] / this->systems[0]->geometry->nos << " Eexch: " << energy[2] / this->systems[0]->geometry->nos << " Edmi: " << energy[3] / this->systems[0]->geometry->nos << " Eddi: " << energy[4] / this->systems[0]->geometry->nos << "\n";
/* if (iterations == 0) {
std::ofstream outfile;
outfile.open("output/3008/1st_sim/energy.txt", std::ios_base::app);
outfile << "init iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << " Hopf radii: ";
for (int i = 0; i < k; i++)
outfile << hopf_radii[i] << " ";
outfile << "\n";
}
if (this->force_max_abs_component < this->systems[0]->app.launchConfiguration.maxTorque) {
std::ofstream outfile;
outfile.open("output/3008/1st_sim/energy.txt", std::ios_base::app);
outfile << "final iteration: " << iterations <<" maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full / num_nonzero_Ms << " Ezeeman: " << energy[0] / num_nonzero_Ms << " Eanis: " << energy[1] / num_nonzero_Ms << " Eexch: " << energy[2] / num_nonzero_Ms << " Edmi: " << energy[3] / num_nonzero_Ms << " Eddi: " << energy[4] / num_nonzero_Ms << " Hopf radii: ";
for (int i = 0; i < k; i++)
outfile << hopf_radii[i] << " ";
outfile << "\n";
}*/
std::cout << "iteration: " << iterations << " maxTorque: " << this->force_max_abs_component << " Mx: " << this->systems[0]->M[0] << " My: " << this->systems[0]->M[1] << " Mz: " << this->systems[0]->M[2] << " Efull: " << energy_full << " Ezeeman: " << energy[0] << " Eanis: " << energy[1] << " Eexch: " << energy[2] << " Edmi: " << energy[3] << " Eddi: " << energy[4] << "\n";

//this->systems[0]->app.writeGradient((*this->configurations[0]).data());
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/Spirit/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ try
// Fetch correct indices and pointers
from_indices( state, idx_image, idx_chain, image, chain );

return image->nos;
return image->app.launchConfiguration.num_nonzero_Ms;
}
catch( ... )
{
Expand Down
Loading

0 comments on commit fda7fc3

Please sign in to comment.