# How to use timer in sample?

Discussion created by riza.guntur on Aug 25, 2009

I use it but it produces hundred thousand for a second operation >.<

I divide it by 100000. Dunno why it happens

Never mind I've found the answer

`#include "brookgenfiles/percobaan_pertama.h" #include "Timer.h" #include <ctime> #include <iostream> #include <iomanip> #include <fstream> using namespace std; using namespace brook; unsigned int jumlahData = 480; unsigned int jumlahDataTest = 120; unsigned int jumlahDataSatuOutput = 80; unsigned int jumlahDataSatuOutputTest = 20; unsigned int jumlahDiSatuGrup = 5; unsigned int jumlahDimensi = 16; unsigned int jumlahOutput = jumlahData / jumlahDataSatuOutput; unsigned int yA = jumlahData; unsigned int yB = yA/jumlahDiSatuGrup; unsigned int yC = 1;//how many last columns to be ignored in input file unsigned int yD = jumlahDataTest; unsigned int yE = jumlahDataTest/jumlahDiSatuGrup; unsigned int streamSize[] = {jumlahDimensi,yA}; unsigned int streamSizeTest[] = {jumlahDimensi,yD}; unsigned int streamSizeReduce[] = {jumlahDimensi,yB}; unsigned int streamSizeReduceTest[] = {jumlahDimensi,yE}; unsigned int streamSizeReduceRef[] = {jumlahDimensi,jumlahOutput}; unsigned int streamSizeMinOfVecCluster[] = {1,jumlahOutput}; unsigned int streamSizeMaxOfMin[] = {1,1}; float alpha = 0.05f; float kappa = 1.0f - alpha; unsigned short rank[3] = {0,1,2}; int num_of_epoch = 100; Stream<float4> *input_to_fuzzy(float2 *input_array, unsigned int rank, unsigned int *input_stream_size, unsigned int *fuzzy_stream_size) { Stream<float2> input(rank, input_stream_size);//stream input training Stream<float4> *fuzzy_number = new Stream<float4>(rank, fuzzy_stream_size);//x mean, y for max, z for min input.read(input_array); //var_max_min_mean(jumlahDiSatuGrup,input,*fuzzy_number); max_min_mean(input,*fuzzy_number); return fuzzy_number; } Stream<float4> *input_to_vec_ref(float2 *input_array, unsigned int rank, unsigned int *input_stream_size, unsigned int *fuzzy_stream_size) { Stream<float2> input(rank, input_stream_size);//stream input training Stream<float4> *fuzzy_number = new Stream<float4>(rank, fuzzy_stream_size);//x mean, y for max, z for min input.read(input_array); var_max_min_mean(jumlahDiSatuGrup,input,*fuzzy_number); return fuzzy_number; } int main(int argc, char* argv[]) { /*{ for(int i = 0; i < 100; i++) { unsigned int streamSize[] = {256, 4}; brook::Stream<int> output(2, streamSize); int *o0 = new int[256 * 4]; ati_test(output); output.write(o0); delete []o0; } }*/ printf("FNLVQ Program\n"); float2 *temporary_input_container = new float2[jumlahDimensi*yA]; float2 *temporary_input_container_test = new float2[jumlahDimensi*yD]; float4 *fuzzy_number_array = new float4[jumlahDimensi*yB]; float4 *vec_ref_array = new float4[jumlahDimensi*jumlahOutput]; float4 *myu_array= new float4[jumlahDimensi*jumlahOutput]; float4 *min_of_cluster_array = new float4[1*jumlahOutput]; float4 *winner_array = new float4[1*1]; memset(temporary_input_container, 0, jumlahDimensi * yA * sizeof(float2)); memset(fuzzy_number_array, 0, jumlahDimensi*yB * sizeof(float4)); memset(vec_ref_array, 0, jumlahDimensi * jumlahOutput * sizeof(float4)); memset(myu_array, 0, jumlahDimensi * jumlahOutput * sizeof(float4)); memset(min_of_cluster_array, 0, 1*jumlahOutput * sizeof(float4)); memset(winner_array, 0, 1*1 * sizeof(float4)); CPerfCounter Timer; { ifstream inFile; ifstream testFile; inFile.open("480x16.txt"); if (!inFile) { cout << "Unable to open file"; exit(1); // terminate with error } testFile.open("120x16test.txt"); if (!testFile) { cout << "Unable to open file"; exit(1); // terminate with error } //for(unsigned int i = 0; i < yD; i++)//reading from file //{ // //printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < jumlahDimensi + yC; j++) // { // unsigned int index = i * jumlahDimensi + j; // unsigned int target = i / jumlahDataSatuOutput; // float temp; // if( (testFile >> temp) && (j < jumlahDimensi)) // { // temporary_input_container_test[index].x = temp;//read input // temporary_input_container_test[index].y = (float) target; // //printf("%.8f %.0f ", temporary_input_container[index].x, temporary_input_container[index].y); // } // //else // //{ // // for(unsigned int u = index - jumlahDimensi; u < index; u++) // // { // // temporary_input_container[u].y = temp; // // //printf("%d %.8f ",u, temporary_input_container[u].y); // // } // //} // } // //printf("\n\n"); //} //printf("Isi dari file\n"); for(unsigned int i = 0; i < yA; i++)//reading from file { //printf("Row array ke-%d ",i); for(unsigned int j = 0; j < jumlahDimensi + yC; j++) { unsigned int index = i * jumlahDimensi + j; unsigned int target = i / jumlahDataSatuOutput; float temp; if( (inFile >> temp) && (j < jumlahDimensi)) { temporary_input_container[index].x = temp;//read input temporary_input_container[index].y = (float) target; //printf("%.8f %.0f ", temporary_input_container[index].x, temporary_input_container[index].y); } //else //{ // for(unsigned int u = index - jumlahDimensi; u < index; u++) // { // temporary_input_container[u].y = temp; // //printf("%d %.8f ",u, temporary_input_container[u].y); // } //} } //printf("\n\n"); } testFile.close(); inFile.close(); } printf("Fuzzify\n\n"); Stream<float4> *fuzzy_number = input_to_fuzzy(temporary_input_container,rank[2],streamSize,streamSizeReduce); Stream<float4> *fuzzy_number_test = input_to_fuzzy(temporary_input_container_test,rank[2],streamSizeTest,streamSizeReduceTest); //Sleep(10); Stream<float4> *vec_ref = input_to_vec_ref(temporary_input_container,rank[2],streamSize,streamSizeReduceRef); Stream<float4> myu(rank[2], streamSizeReduceRef);//myu streams Stream<float4> vec_ref_next(rank[2], streamSizeReduceRef); Stream<float4> myu_min(rank[2], streamSizeMinOfVecCluster);//streams of smallest myu in calculated vector reference cluster against fuzzy_number Stream<float4> winner(rank[2], streamSizeMaxOfMin);//biggest of smallest myu //*vec_ref = vec_ref_next; //Stream<float4> vec_ref_next = *vec_ref; fuzzy_number->write(fuzzy_number_array); printf("Isi fuzzy number\n"); for(unsigned int i = 0; i < streamSizeReduce[1]; i++) { printf("Row array ke-%d ",i); for(unsigned int j = 0; j < streamSizeReduce[0]; j++) { unsigned int index = i * jumlahDimensi + j; printf("%.8f %.8f %.8f %.0f ", fuzzy_number_array[index].x, fuzzy_number_array[index].y, fuzzy_number_array[index].z, fuzzy_number_array[index].w); } printf("\n\n"); } printf("Copy\n\n"); //copy4(*fuzzy_number,*vec_ref); //copy4(*vec_ref,vec_ref_next); copy4_gather(yB/(int)jumlahOutput,*fuzzy_number,*vec_ref); printf("Reference vector\n\n"); vec_ref->write(vec_ref_array); for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file { printf("Row array ke-%d ",i); for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) { unsigned int index = i * streamSizeReduceRef[0] + j; printf("%.8f %.8f %.8f %.0f ",vec_ref_array[index].x, vec_ref_array[index].y, vec_ref_array[index].z, vec_ref_array[index].w); } printf("\n\n"); } //Sleep(10); std::clock_t start_t = std::clock(); //std::cout << "waktu yang dibutuhkan = " << ( ( std::clock() - start ) / (double)CLOCKS_PER_SEC ) <<'\n'; Timer.Reset(); Timer.Start(); for( int epoch = 0; epoch < num_of_epoch; epoch++) { for( int row = 0; row < (int) yB; row++) { //printf("Reference vector %d\n",row); //vec_ref->write(vec_ref_array); //for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) // { // unsigned int index = i * streamSizeReduceRef[0] + j; // printf("%.8f %.8f %.8f %.0f ",vec_ref_array[index].x, vec_ref_array[index].y, vec_ref_array[index].z, vec_ref_array[index].w); // } // printf("\n\n"); //} /*uint start[] = {0,row}; uint end[] = {jumlahDimensi,row};*/ //printf("Myufy\n\n"); /*start_t = std::clock(); timer->Start();*/ /*std::clock_t start_t = std::clock();*/ myufy_opt(row, alpha,*fuzzy_number,*vec_ref,myu); //Sleep(10); //myu.write(myu_array); //printf("Isi myu\n"); //for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) // { // unsigned int index = i * streamSizeReduceRef[0] + j; // printf("%.8f %.0f %.0f %.0f ",myu_array[index].x, myu_array[index].y, myu_array[index].z, myu_array[index].w); // } // printf("\n\n"); //} //printf("Myu_min_all\n\n"); //as(myu,myu_min); //myu_min_all(myu,myu_min);//untuk dimensi besar myu_min_all_small(streamSize[0],myu,myu_min);//untuk dimensi kecil //Sleep(10); //myu_min.write(min_of_cluster_array); //printf("Isi min_of_cluster\n"); //for(unsigned int i = 0; i < streamSizeMinOfVecCluster[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeMinOfVecCluster[0]; j++) // { // unsigned int index = i * streamSizeMinOfVecCluster[0] + j; // printf("%.8f %.0f %.0f %.0f ",min_of_cluster_array[index].x, min_of_cluster_array[index].y, min_of_cluster_array[index].z, min_of_cluster_array[index].w); // } // printf("\n\n"); //} //printf("Winner\n\n"); //myu_max_min(myu_min,winner); myu_max_min_small(jumlahOutput,myu_min,winner); //Sleep(10); //winner.write(winner_array); //printf("Isi winner_array\n"); //for(unsigned int i = 0; i < streamSizeMaxOfMin[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeMaxOfMin[0]; j++) // { // unsigned int index = i * streamSizeMaxOfMin[0] + j; // printf("%.8f %.0f %.0f %.0f ",winner_array[index].x, winner_array[index].y, winner_array[index].z, winner_array[index].w); // } // printf("\n\n"); //} //printf("Update winner\n\n"); calc_vec_ref_next(row, alpha, kappa, winner, *fuzzy_number, *vec_ref, vec_ref_next); /*calc_vec_ref_nexta.domainOffset(uint4(0,0,0,0)); calc_vec_ref_nexta.domainSize(uint4((int)jumlahDimensi,1,1,1));*/ //calc_vec_ref_nexta(row, alpha, kappa, winner, *fuzzy_number, *vec_ref, vec_ref_next); //Sleep(10); //printf("Isi vector reference next\n"); //vec_ref_next.write(vec_ref_array); //for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) // { // unsigned int index = i * streamSizeReduceRef[0] + j; // printf("%.8f %.8f %.8f %.0f ",vec_ref_array[index].x, vec_ref_array[index].y, vec_ref_array[index].z, vec_ref_array[index].w); // } // printf("\n\n"); //} copy4(vec_ref_next,*vec_ref); /*printf( "%f\n", ( std::clock() - start_t ) / (double)CLOCKS_PER_SEC );*/ //timer->Stop(); //Sleep(10); } alpha = 0.9999f * alpha; kappa = 0.01f * alpha; } printf( "%f\n", ( std::clock() - start_t ) / (double)CLOCKS_PER_SEC ); /*start_t = clock(); for( int epoch = 0; epoch < 100000; epoch++) for( int row = 0; row < (int) yB; row++); printf( "%f\n", ( std::clock() - start_t ) / (double)CLOCKS_PER_SEC );*/ /*double time = timer->GetElapsedTime();*/ //printf("%f",time); Timer.Stop(); printf("GPU Time: %lf\n", Timer.GetElapsedTime()/100000); printf("Reference vector final\n"); vec_ref->write(vec_ref_array); for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file { printf("Row array ke-%d ",i); for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) { unsigned int index = i * streamSizeReduceRef[0] + j; printf("%.8f %.8f %.8f %.0f ",vec_ref_array[index].x, vec_ref_array[index].y, vec_ref_array[index].z, vec_ref_array[index].w); } printf("\n\n"); } for( int row = 0; row < (int) yB; row++) { //printf("Reference vector %d\n",row); //vec_ref->write(vec_ref_array); //for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) // { // unsigned int index = i * streamSizeReduceRef[0] + j; // printf("%.8f %.8f %.8f %.0f ",vec_ref_array[index].x, vec_ref_array[index].y, vec_ref_array[index].z, vec_ref_array[index].w); // } // printf("\n\n"); //} /*uint start[] = {0,row}; uint end[] = {jumlahDimensi,row};*/ //printf("Myufy\n\n"); /*start_t = std::clock(); timer->Start();*/ /*std::clock_t start_t = std::clock();*/ myufy_opt(row, alpha,*fuzzy_number,*vec_ref,myu); //Sleep(10); //myu.write(myu_array); //printf("Isi myu\n"); //for(unsigned int i = 0; i < streamSizeReduceRef[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeReduceRef[0]; j++) // { // unsigned int index = i * streamSizeReduceRef[0] + j; // printf("%.8f %.0f %.0f %.0f ",myu_array[index].x, myu_array[index].y, myu_array[index].z, myu_array[index].w); // } // printf("\n\n"); //} //printf("Myu_min_all\n\n"); //as(myu,myu_min); //myu_min_all(myu,myu_min);//untuk dimensi besar myu_min_all_small(streamSize[0],myu,myu_min);//untuk dimensi kecil //Sleep(10); //myu_min.write(min_of_cluster_array); //printf("Isi min_of_cluster\n"); //for(unsigned int i = 0; i < streamSizeMinOfVecCluster[1]; i++)//reading from file //{ // printf("Row array ke-%d ",i); // for(unsigned int j = 0; j < streamSizeMinOfVecCluster[0]; j++) // { // unsigned int index = i * streamSizeMinOfVecCluster[0] + j; // printf("%.8f %.0f %.0f %.0f ",min_of_cluster_array[index].x, min_of_cluster_array[index].y, min_of_cluster_array[index].z, min_of_cluster_array[index].w); // } // printf("\n\n"); //} //printf("Winner\n\n"); //myu_max_min(myu_min,winner); myu_max_min_small(jumlahOutput,myu_min,winner); } delete fuzzy_number; delete fuzzy_number_test; delete[] temporary_input_container; delete[] temporary_input_container_test; delete[] vec_ref_array; delete[] min_of_cluster_array; delete[] myu_array; delete[] winner_array; delete[] fuzzy_number_array; return 0; } kernel void max_min_mean(float2 input[][], out float4 output<>) { int2 index = instance().xy; int i0 = 5*index.y; int i1 = i0+1; int i2 = i1+1; int i3 = i2+1; int i4 = i3+1; float mean; float temp0 = input[i0][index.x].x; float temp1 = input[i1][index.x].x; float temp2 = input[i2][index.x].x; float temp3 = input[i3][index.x].x; float temp4 = input[i4][index.x].x; float temp_max = temp0; float temp_min = temp0; temp_max = (temp_max>temp1)?temp_max:temp1; temp_max = (temp_max>temp2)?temp_max:temp2; temp_max = (temp_max>temp3)?temp_max:temp3; temp_max = (temp_max>temp4)?temp_max:temp4; temp_min = (temp_min<temp1)?temp_min:temp1; temp_min = (temp_min<temp2)?temp_min:temp2; temp_min = (temp_min<temp3)?temp_min:temp3; temp_min = (temp_min<temp4)?temp_min:temp4; mean = 0.2f*(temp0+temp1+temp2+temp3+temp4); output = float4(mean,temp_max,temp_min,input[i0][index.x].y); } kernel void var_max_min_mean(int group_size, float2 input[][], out float4 output<>) { int2 index = instance().xy; int count; int i0 = group_size*index.y; float mean; float temp0 = input[i0][index.x].x; float temp_max = temp0; float temp_min = temp0; float sum = temp0; for(count = 1; count < group_size; count++) { temp0 = input[++i0][index.x].x; temp_max = (temp_max>temp0)?temp_max:temp0; temp_min = (temp_min<temp0)?temp_min:temp0; sum += temp0; } mean = sum / (float) group_size; output = float4(mean,temp_max,temp_min,input[group_size*index.y][index.x].y); } kernel void max_min_median(float2 input[][], out float4 output<>) { int2 index = instance().xy; int i0 = 5*index.y; int i1 = i0+1; int i2 = i1+1; int i3 = i2+1; int i4 = i3+1; float mid; float temp0 = input[i0][index.x].x; float temp1 = input[i1][index.x].x; float temp2 = input[i2][index.x].x; float temp3 = input[i3][index.x].x; float temp4 = input[i4][index.x].x; float temp_max = temp0; float temp_min = temp0; temp_max = (temp_max>temp1)?temp_max:temp1; temp_max = (temp_max>temp2)?temp_max:temp2; temp_max = (temp_max>temp3)?temp_max:temp3; temp_max = (temp_max>temp4)?temp_max:temp4; temp_min = (temp_min<temp1)?temp_min:temp1; temp_min = (temp_min<temp2)?temp_min:temp2; temp_min = (temp_min<temp3)?temp_min:temp3; temp_min = (temp_min<temp4)?temp_min:temp4; mid = 0.5f*(temp_max+temp_min); output = float4(mid,temp_max,temp_min,input[i0][index.x].y); } kernel void var_max_min_median(int group_size,float2 input[][], out float4 output<>) { int2 index = instance().xy; int count; int i0 = group_size*index.y; float mid; float temp0 = input[i0][index.x].x; float temp_max = temp0; float temp_min = temp0; for(count = 1; count < group_size; count++) { temp0 = input[++i0][index.x].x; temp_max = (temp_max>temp0)?temp_max:temp0; temp_min = (temp_min<temp0)?temp_min:temp0; } mid = 0.5f* (temp_max + temp_min); output = float4(mid,temp_max,temp_min,input[group_size*index.y][index.x].y); } kernel void copy4(float4 input<>, out float4 output<>) { output = input; } kernel void copy4_gather(int offset, float4 input[][], out float4 output<>) { int y = offset * instance().y; output = input[y][instance().x]; } kernel void myufy( int row, float a, float4 input_fuzzy_numbers[][], float4 vec_ref<>, out float4 myu<>) { int column = instance().x; float4 fuzz1 = input_fuzzy_numbers[row][column]; float4 fuzz2 = vec_ref; if(fuzz1.x <= fuzz2.x) { myu = float4(clamp((fuzz1.y - fuzz2.z) / (fuzz2.x - fuzz2.z + fuzz1.y - fuzz1.x),0.0f,1.0f),fuzz1.w,fuzz2.w,0.0f); } else { myu = float4(clamp((fuzz2.y - fuzz1.z) / (fuzz1.x - fuzz1.z + fuzz2.y - fuzz2.x),0.0f,1.0f),fuzz1.w,fuzz2.w,0.0f); } } reduce void myu_min_all(float4 myu<>, reduce float4 myu_min<>) { if(myu.x < myu_min.x) myu_min = myu; } kernel void myu_min_all_small(unsigned int width, float4 myu[][], out float4 myu_min<>) { float4 temp = myu[instance().y][0]; uint i; for(i = 1; i < width; i++) { if(myu[instance().y][i].x<temp.x) temp=myu[instance().y][i]; } myu_min = temp; } reduce void myu_max_min(float4 myu_min<>, reduce float4 winner<>) { if(myu_min.x > winner.x) winner = myu_min; } kernel void myu_max_min_small(unsigned int num_of_rows, float4 myu_min[][], out float4 winner<>) { float4 temp = myu_min[0][0]; uint i; for(i=1;i<num_of_rows;i++) if(myu_min[i][1].x > temp.x) temp=myu_min[i][1]; winner = temp; } kernel void calc_vec_ref_next( int row, float a, float kappa, float4 winner[][], float4 input_fuzzy_numbers[][], float4 vec_ref[][], out float4 vec_ref_next<>) { float4 temp0 = winner[1][1]; float4 fuzz1 = input_fuzzy_numbers[row][instance().x]; float4 fuzz2 = vec_ref[instance().y][instance().x]; if(temp0.z != fuzz2.w) { vec_ref_next = fuzz2; } else { float lRange = fuzz2.x - fuzz2.z; float rRange = fuzz2.y - fuzz2.x; vec_ref_next.w = fuzz2.w; if(temp0.x == 0.0f) { vec_ref_next.x = fuzz2.x; vec_ref_next.z = fuzz2.x - 1.1f * lRange; vec_ref_next.y = fuzz2.x + 1.1f * rRange; } else { float diff_mean = (1.0f - temp0.x)*(fuzz1.x - fuzz2.x)*a; if(fuzz1.w != fuzz2.w) { vec_ref_next.x = fuzz2.x - diff_mean; fuzz2.z = fuzz2.z - diff_mean; fuzz2.y = fuzz2.y - diff_mean; vec_ref_next.z = fuzz2.z + ( 1.0f - temp0.x )*( 1.0f - kappa )*lRange ; vec_ref_next.y = fuzz2.y - ( 1.0f - temp0.x )*( 1.0f - kappa )*rRange; } else { vec_ref_next.x = fuzz2.x + diff_mean; fuzz2.z = fuzz2.z + diff_mean; fuzz2.y = fuzz2.y + diff_mean; vec_ref_next.z = fuzz2.z - ( 1.0f - temp0.x )*( 1.0f - kappa )*lRange ; vec_ref_next.y = fuzz2.y + ( 1.0f - temp0.x )*( 1.0f - kappa )*rRange; } } } } Attribute[GroupSize(64, 1, 1)] kernel void calc_vec_ref_nexta( int row, float a, float kappa, float4 winner[][], float4 input_fuzzy_numbers[][], float4 vec_ref[][], out float4 vec_ref_next[][]) { float4 temp0 = winner[1][1]; float4 fuzz1 = input_fuzzy_numbers[row][instance().x]; int y = (int) temp0.z; float4 fuzz2 = vec_ref[y][instance().x]; float lRange = fuzz2.x - fuzz2.z; float rRange = fuzz2.y - fuzz2.x; vec_ref_next[y][instance().x].w = fuzz2.w; if(temp0.x == 0.0f) { vec_ref_next[y][instance().x].x = fuzz2.x; vec_ref_next[y][instance().x].z = fuzz2.x - 1.1f * lRange; vec_ref_next[y][instance().x].y = fuzz2.x + 1.1f * rRange; } else { float diff_mean = (1.0f - temp0.x)*(fuzz1.x - fuzz2.x)*a; if(fuzz1.w != fuzz2.w) { vec_ref_next[y][instance().x].x = fuzz2.x - diff_mean; fuzz2.z = fuzz2.z - diff_mean; fuzz2.y = fuzz2.y - diff_mean; vec_ref_next[y][instance().x].z = fuzz2.z + ( 1.0f - temp0.x )*( 1.0f - kappa )*lRange ; vec_ref_next[y][instance().x].y = fuzz2.y - ( 1.0f - temp0.x )*( 1.0f - kappa )*rRange; } else { vec_ref_next[y][instance().x].x = fuzz2.x + diff_mean; fuzz2.z = fuzz2.z + diff_mean; fuzz2.y = fuzz2.y + diff_mean; vec_ref_next[y][instance().x].z = fuzz2.z - ( 1.0f - temp0.x )*( 1.0f - kappa )*lRange ; vec_ref_next[y][instance().x].y = fuzz2.y + ( 1.0f - temp0.x )*( 1.0f - kappa )*rRange; } } } kernel void myufy_opt( int row, float a, float4 input_fuzzy_numbers[][], float4 vec_ref[][], out float4 myu<>) { int column = instance().x; float4 fuzz1 = input_fuzzy_numbers[row][column]; float4 fuzz2 = vec_ref[instance().y][column]; float diffx = fuzz2.x - fuzz1.x; float diffyz = diffx > 0.0f?fuzz1.y-fuzz2.z:fuzz2.y-fuzz1.z; myu = float4(clamp((diffyz)/(abs(diffx)+diffyz),0.0f,1.0f),fuzz1.w,fuzz2.w,0.0f); }`