Skip to content

Instantly share code, notes, and snippets.

@robosina
Created May 7, 2020 10:02
Show Gist options
  • Save robosina/7c82353d2a31790f6a26e5fe2235b1c1 to your computer and use it in GitHub Desktop.
Save robosina/7c82353d2a31790f6a26e5fe2235b1c1 to your computer and use it in GitHub Desktop.
struct GPUData {
int number_of_finger;
int number_of_cyliner;
float * q_theta_arrs;
int * x_arrs;
int * y_arrs;
unsigned long long* byte_arrs_offset0;
unsigned long long* byte_arrs_offset1;
unsigned long long* byte_arrs_offset2;
unsigned long long* byte_arrs_offset3;
float * sum_of_bits_arrs;
int * size_arrs;
int * jindex;
};
//////////////allocate data
inline void create_tensors(const std::vector<FINGERPRINT_META_DATA>& fingerprint_dataset,
size_t number_of_cylinders,
float **q_theta_arrs,
unsigned long long** byte_arrs_offset0,
unsigned long long** byte_arrs_offset1,
unsigned long long** byte_arrs_offset2,
unsigned long long** byte_arrs_offset3,
float ** sum_of_bits_arrs,
int ** size_arrs,
int ** jindex)
{
size_t number_of_fingers = fingerprint_dataset.size();
*q_theta_arrs = (float*)malloc(number_of_cylinders * sizeof(float)); //combline q_theta of all cylenders from all fingers to just an arrays (all_finger * max_number_of_cylender)
*byte_arrs_offset0 = (unsigned long long*)malloc(number_of_cylinders * sizeof(unsigned long long));
*byte_arrs_offset1 = (unsigned long long*)malloc(number_of_cylinders * sizeof(unsigned long long));
*byte_arrs_offset2 = (unsigned long long*)malloc(number_of_cylinders * sizeof(unsigned long long));
*byte_arrs_offset3 = (unsigned long long*)malloc(number_of_cylinders * sizeof(unsigned long long));
*sum_of_bits_arrs = (float*)malloc(number_of_cylinders * sizeof(float));
*size_arrs = (int*)malloc(number_of_fingers * sizeof(int)); //each finger will be have specific number of cylinders
*jindex = (int*)malloc(number_of_cylinders * sizeof(int));
//std::cout << "number of jindex:" << number_of_cylinders << std::endl;
}
//////transfer data
inline void fill_tensors(const std::vector<FINGERPRINT_META_DATA>& fingerprint_dataset,
GPUData& gpudata,
size_t max_num_cylinder)
{
std::vector<size_t> indexes;
#if debug_mode==1
int index_num = -1;
int number_of_jump = 0;
#endif
size_t inc = 0;
for (size_t f = 0; f < fingerprint_dataset.size(); f++)
{
FINGERPRINT_META_DATA finger_meta_data = fingerprint_dataset[f];
for (size_t i = 0; i < finger_meta_data.num_of_cylinders; i++)
{
indexes.push_back(inc);
gpudata.q_theta_arrs[inc] = finger_meta_data.cylinders_of_finger[i].q_theta;
gpudata.sum_of_bits_arrs[inc] = finger_meta_data.cylinders_of_finger[i].sum_of_setbits;
gpudata.jindex[inc] = f;
for (size_t b = 0; b < 4; b++)
{
size_t index_step4 = inc*4 + b;
if (b == 0)
{
gpudata.byte_arrs_offset0[inc] = finger_meta_data.cylinders_of_finger[i].byte[b];
}
else if (b == 1)
{
gpudata.byte_arrs_offset1[inc] = finger_meta_data.cylinders_of_finger[i].byte[b];
}
else if (b == 2)
{
gpudata.byte_arrs_offset2[inc] = finger_meta_data.cylinders_of_finger[i].byte[b];
}
else if (b == 3)
{
gpudata.byte_arrs_offset3[inc] = finger_meta_data.cylinders_of_finger[i].byte[b];
}
#if debug_mode==1
int diff = index2 - index_num;
if (diff != 1)
{
number_of_jump++;
std::cout << "total finger:"<< fingerprint_dataset.size()<<" number of jump:" <<number_of_jump<< std::endl;
}
index_num = index2;
#endif
}
inc++;
//std::cout << index << "real value:" << finger_meta_data.cylinders_of_finger[i].q_theta << " value:" << gpudata.q_theta_arrs[index] << std::endl;
}
gpudata.size_arrs[f] = finger_meta_data.num_of_cylinders;
}
gpudata.number_of_cyliner = max_num_cylinder;
gpudata.number_of_finger = fingerprint_dataset.size();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment