File indexing completed on 2025-08-03 08:19:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #define __CL_ENABLE_EXCEPTIONS
0027
0028
0029 #include <cstdlib>
0030 #include <cstdio>
0031 #include <string>
0032 #include <vector>
0033 #include <cmath>
0034 #include <iostream>
0035 #include <fstream>
0036 #include <sstream>
0037 #include <cassert>
0038 #include <ctime>
0039 #include <algorithm>
0040 #include <map>
0041
0042 #include <random>
0043
0044 #include "include/Config.h"
0045 #include "include/opencl_backend.h"
0046 #include "include/bulkinfo.h"
0047 #include "include/error_msgs.h"
0048
0049 namespace clvisc {
0050
0051
0052 BulkInfo::BulkInfo(int nx, int ny, int neta,
0053 int nx_skip, int ny_skip, int neta_skip,
0054 const OpenclBackend & backend,
0055 const std::string & compile_option): nx_(nx), ny_(ny), neta_(neta),
0056 nx_skip_(nx_skip), ny_skip_(ny_skip), neta_skip_(neta_skip),
0057 backend_(backend), compile_option_(compile_option){
0058 nx_out_ = int(floor((nx_-1)/nx_skip_)) + 1;
0059 ny_out_ = int(floor((ny_-1)/ny_skip_)) + 1;
0060 neta_out_ = int(floor((neta_-1)/neta_skip_)) + 1;
0061
0062
0063 data_info_.push_back("energy_density");
0064 data_info_.push_back("entropy_density");
0065 data_info_.push_back("temperature");
0066 data_info_.push_back("pressure");
0067 data_info_.push_back("vx");
0068 data_info_.push_back("vy");
0069 data_info_.push_back("vz");
0070 data_info_.push_back("qgp_fraction");
0071 data_info_.push_back("pi00");
0072 data_info_.push_back("pi01");
0073 data_info_.push_back("pi02");
0074 data_info_.push_back("pi03");
0075 data_info_.push_back("pi11");
0076 data_info_.push_back("pi12");
0077 data_info_.push_back("pi13");
0078 data_info_.push_back("pi22");
0079 data_info_.push_back("pi23");
0080 data_info_.push_back("pi33");
0081
0082 size_t size_out = nx_out_ * ny_out_ * neta_out_ * data_info_.size();
0083 h_bulk3d_1step_.resize(size_out);
0084 try {
0085
0086 auto prg = backend_.BuildProgram("clvisc_kernel/kernel_bulk3d.cl", compile_option_);
0087 kernel_bulk3d_ = cl::Kernel(prg, "kernel_bulk3d");
0088 d_bulk3d_1step_ = backend_.CreateBuffer(size_out * sizeof(float));
0089 } catch (cl::Error & err ){
0090 std::cerr<<"Error:"<<err.what()<<"("<<err.err()<<")\n";
0091 std::cerr<<"@" << __FILE__ << ":line " << __LINE__ << std::endl;
0092 std::cerr<<ErrorMessage(err.err())<<std::endl;
0093 throw(err);
0094 }
0095 }
0096
0097
0098 void BulkInfo::add_data(const cl::Buffer & d_ev,
0099 const cl::Buffer & d_shear_pi,
0100 const cl::Buffer & d_bulk_pi,
0101 const cl::Image2D & eos_table){
0102 kernel_bulk3d_.setArg(0, d_bulk3d_1step_);
0103 kernel_bulk3d_.setArg(1, d_ev);
0104 kernel_bulk3d_.setArg(2, d_shear_pi);
0105 kernel_bulk3d_.setArg(3, d_bulk_pi);
0106 kernel_bulk3d_.setArg(4, eos_table);
0107 backend_.enqueue_run(kernel_bulk3d_,
0108 cl::NDRange(nx_out_, ny_out_, neta_out_),
0109 cl::NullRange);
0110 backend_.enqueue_copy(d_bulk3d_1step_, h_bulk3d_1step_);
0111 for (auto val : h_bulk3d_1step_) {
0112 bulk_data_.push_back(val);
0113 }
0114 }
0115
0116 const std::vector<float> & BulkInfo::get_data() {
0117 return bulk_data_;
0118 }
0119
0120 const std::vector<std::string> & BulkInfo::get_data_info() {
0121 return data_info_;
0122 }
0123
0124 void BulkInfo::save(const std::string & fpath){
0125
0126 std::ofstream fout(fpath);
0127 int idx = 0;
0128 fout << "# nx=" << nx_out_ << std::endl;
0129 fout << "# ny=" << ny_out_ << std::endl;
0130 fout << "# nz=" << neta_out_ << std::endl;
0131 fout << "# num_entries =" << data_info_.size() << std::endl;
0132 fout << "# ";
0133 for (auto val : data_info_) {
0134 fout << val << " ";
0135 }
0136 fout << std::endl;
0137 for (auto val : bulk_data_) {
0138 idx ++;
0139 fout << val << " ";
0140 if (idx % data_info_.size() == 0) {
0141 fout << std::endl;
0142 }
0143 }
0144 fout.close();
0145 }
0146
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164