#include "device_launch_parameters.h"
#include <cuda_runtime_api.h>
#include "cuda_runtime.h"
#include <iostream>
#include <stdlib.h>
#include <random>
#include <chrono>
#include <math.h>
using namespace std;

// Define error values
#define MEMORY_ERROR        -2
#define INPUT_ERROR         -1

// Define Constant values
#define MIN_VALUE          -100.0
#define MAX_VALUE           100.0

#define WARP_SIZE           32
#define MAX_BLOCK_THREADS   512
#define MAX_WARPS_BLOCK_Y   16
#define MIN_WARPS_BLOCK_Y   1

//#define VERBOSE


#define ERROR_THRESHOLD     500

const char Result[2][10] = {"SUCCEDED", "FAILED"};

typedef struct{
    dim3 block;
    dim3 grid;
    int s_mem;
}BestSplit;



BestSplit findBestSplit(int n, int d);

void printData(float *dataset, int n, int d);
void calculateDistances(float *distances, float *dataset, float *point, int n, int d);
void parallelDistance(float *distances, float *data, int n, int d);

__global__ void cudaReduce(float *temp, float *distances, int n, int d, int r);
__global__ void cudaDotProduct(float *dataset, float *point, float *product, int n, int d, int r);
// void serialReduce(float *sum, float *data, int n, int d);

// __global__ void deviceCalculatedDistances(float *dist, float *data, float *point, int n, int d);





int main(int argc, char *argv[]){
    // show cuda gpu details
    

    int d;      // number of dimensions
    int n;      // number of points

    // host variables
    float *h_dataset = NULL;
    float *h_distances = NULL;
    float *h_test_distances = NULL;

    // device variables
    float *d_point = NULL;
    float *d_dataset = NULL;
    float *d_distances = NULL;


    if(argc != 3){
        cout << "Wrong number of arguments. Aborting ..." << endl;
        return INPUT_ERROR;
    }else{
        // assign values
        n = atoi(argv[1]);
        d = atoi(argv[2]);

        cout << "Initializing " << n << " random data points of " << d << " dimensions" << endl;
    }


    // creating the Random dataset
    h_dataset = (float *)malloc(n * d * sizeof(float));
    


    if(h_dataset == NULL){
        cout << "Not enough memory. Aborting ..." << endl;
        free(h_dataset);
        return MEMORY_ERROR;
    }else{
        // initialize random generator engine
        unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
        default_random_engine generator(seed);
        uniform_real_distribution<float> distribution(MIN_VALUE, MAX_VALUE);

        int length = n * d;

        for(int i = 0; i < length; i++){
            h_dataset[i] = distribution(generator);
        }
    }

    // serial stuff
    h_test_distances = (float *)malloc(n * sizeof(float));
    h_distances = (float *)malloc(n * sizeof(float));

    auto start = std::chrono::high_resolution_clock::now();

    calculateDistances(h_test_distances, h_dataset, &h_dataset[0], n, d);

    auto finish = std::chrono::high_resolution_clock::now();
    auto cpu_time = std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count();

    // cuda stuff
    cudaMalloc(&d_dataset, n * d * sizeof(float)); 
    cudaMalloc(&d_point, d * sizeof(float)); 
    cudaMalloc(&d_distances, n * sizeof(float)); 

    // copy the dataset to the device
    cudaMemcpy(d_dataset, h_dataset, n * d * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(d_point, &d_dataset[0], d * sizeof(float), cudaMemcpyHostToDevice);


    start = std::chrono::high_resolution_clock::now();
    parallelDistance(d_distances ,d_dataset, n , d);
    finish = std::chrono::high_resolution_clock::now();
    auto gpu_time = std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count();


    // copy the calculated distances back to the host
    cudaMemcpy(h_distances, d_distances, n * sizeof(float), cudaMemcpyDeviceToHost);

    

    #ifdef VERBOSE
    cout << "CPU Time: " << cpu_time << endl;
    cout << "GPU Time: " << gpu_time << endl;
    
    #endif
    cout << "Total Speed up: " << (float)cpu_time / gpu_time << endl;


    // validation
    bool fail = 0;
    for(int i = 0; i < n; i++){
        float error = abs(pow(h_test_distances[i],2) - h_distances[i]);
        if(error > ERROR_THRESHOLD){
            cout << "Error exeeded threshold("<< ERROR_THRESHOLD << "): " << error << endl;
            fail = 1;
            break;
        }
    }

    cout << "Program: " << Result[fail] << endl;

    cudaFree(d_dataset);
    cudaFree(d_distances);

    free(h_distances);
    free(h_dataset);

    return 0;
}



/*
 *  Function that reduces a sum in parallel efficiently by managing kernel assignments
*/

BestSplit findBestSplit(int n, int d){
    BestSplit split;

    int req_warps_y = d / WARP_SIZE  + (d % WARP_SIZE != 0);

    float min_error = 100000.0;
    int best_dividor = -1;
    int num_of_warps = -1;

    for(int split = 1; split < 1000; split++){
        float warps_in_block_y = (float)req_warps_y / split;
        
        if(MIN_WARPS_BLOCK_Y <= warps_in_block_y && warps_in_block_y <= MAX_WARPS_BLOCK_Y){
            float split_error = warps_in_block_y - (int)(req_warps_y / split);
            
            if(min_error > split_error){
                min_error = split_error;
                best_dividor = split;     
                num_of_warps = warps_in_block_y;
            }
        }else if(warps_in_block_y < 1){
            break;
        }
    }

    
    split.block.y = num_of_warps * WARP_SIZE;
    split.block.x = MAX_BLOCK_THREADS / split.block.y;
    split.grid.x = n / split.block.x + (n % split.block.x != 0);
    split.grid.y = best_dividor + (min_error > 0);

    split.s_mem = (split.block.x + 1) * split.block.y * sizeof(float);


    #ifdef VERBOSE
    cout << "Block: " << split.block.x << ", " << split.block.y << ", " << (split.block.x + 1) * split.block.y << endl;
    cout << "Grid: " << split.grid.x << ", " << split.grid.y << endl;
    cout << "Occupancy: in x: " << (float)n / (split.block.x * split.grid.x) << ", in y: " << (float)d / (split.block.y * split.grid.y) << endl;
    #endif
    
    return split;
}





void parallelDistance(float *distances, float *data, int n, int d){
    float *d_product_temp = NULL;

    BestSplit b_split = findBestSplit(n, d);
    

    
    // calculate temp block & grid sizes
    dim3 temp_block;
    dim3 temp_grid;

    int temp_size_x = b_split.block.x * b_split.grid.x;
    int temp_size_y = b_split.grid.y;
    

    temp_block.y = (temp_size_y / 8 + (temp_size_y % 8 != 0)) * 8; 
    temp_block.x = MAX_BLOCK_THREADS / temp_block.y;
    temp_grid.x = n / temp_block.x + (n % temp_block.x != 0);
    temp_grid.y = 1;

    int shared_mem = temp_block.x * temp_block.y * sizeof(float);


    #ifdef VERBOSE
    cout << "Temp Block: " << temp_block.x << ", " << temp_block.y << endl;
    cout << "Temp Grid: " << temp_grid.x << ", " << temp_grid.y << endl;
    #endif
    
    
    int temp_product_size = temp_size_x * temp_size_y * sizeof(float);
    cudaMalloc(&d_product_temp, temp_product_size); 

   
    int r = pow(2,ceil(log2(b_split.block.y)));
    
    cudaDotProduct<<<b_split.grid, b_split.block, b_split.s_mem>>>(data, &data[0], d_product_temp, n, d, r);

    r = pow(2,ceil(log2(temp_block.y)));
    // cout << r << endl;
    cudaReduce<<<temp_grid, temp_block, shared_mem>>>(d_product_temp, distances, n, b_split.grid.y, r);
    

    cudaError_t errSync = cudaGetLastError();
    cudaError_t errAsync = cudaDeviceSynchronize();

    auto stop = std::chrono::high_resolution_clock::now();


    #ifdef VERBOSE
    if (errSync != cudaSuccess)
		printf("Sync kernel error: %s\n", cudaGetErrorString(errSync));
	if (errAsync != cudaSuccess)
        printf("Async kernel error: %s\n", cudaGetErrorString(errAsync));
    if (errSync == cudaSuccess && errAsync == cudaSuccess)
        printf("Kernals succesfully finished without any errors!\n");
    #endif
}


__global__ void cudaDotProduct(float *data, float *point, float *product, int n, int d, int r){
    // copy dataset and point to shared memory
    extern __shared__ float s_mem[];

    int thread_id = threadIdx.x * blockDim.y + threadIdx.y;
    int point_offset = blockDim.x * blockDim.y;

    float *s_point = &s_mem[point_offset];
    float *s_data = &s_mem[0];

    int pos_x = blockIdx.x * blockDim.x + threadIdx.x;
    int pos_y = blockIdx.y * blockDim.y + threadIdx.y;

    // IF the thread belongs to the first row and is inside the block dimensions copy the data else if it outfside just zero initialize the array
    if(thread_id < blockDim.y && pos_y < d){
        s_point[threadIdx.y] = point[pos_y]; 
    }else if(thread_id < blockDim.y){
        s_point[threadIdx.y] = 0.0;
    }

    // copy data
    if(pos_x < n && pos_y < d){
        s_data[thread_id] = data[pos_x * d + pos_y];
    }else{
        s_data[thread_id] = 0.0;
    }
    
    __syncthreads();

    // calculate dot product
    s_data[thread_id] = s_data[thread_id] * s_data[thread_id] - 2 * s_data[thread_id] * s_point[threadIdx.y] + s_point[threadIdx.y] * s_point[threadIdx.y];
    
    __syncthreads();

    //reduce sum in parallel
    for(int s = r / 2; s > 0; s >>= 1){
        if(threadIdx.y < s && (threadIdx.y + s) < d){
            s_data[thread_id] += s_data[thread_id + s];
        }else{
            s_data[thread_id] += 0.0;
        }
        __syncthreads();
    }

    // copy data back
    pos_x = blockIdx.x * (blockDim.x * gridDim.y);
    pos_y = blockIdx.y;
    if(threadIdx.y == 0){
        product[pos_x + pos_y + threadIdx.x * gridDim.y] = s_data[thread_id];
    }
}


// complete unroll these iterations
__global__ void cudaReduce(float *temp, float *distances, int n, int d, int r){
    extern __shared__ float s_data[];

    int thread_id = threadIdx.x * blockDim.y + threadIdx.y;
    
    int pos_x = blockIdx.x * blockDim.x + threadIdx.x;
    int pos_y = threadIdx.y;

    // copy data to shared memory
    if(pos_x < n && pos_y < d){
        s_data[thread_id] = temp[pos_x * d + pos_y];
    }else{
        s_data[thread_id] = 0.0;
    }

    __syncthreads();

    for(int s = r / 2; s > 0; s >>= 1){
        if(threadIdx.y < s && (threadIdx.y + s) < d){
            s_data[thread_id] += s_data[thread_id + s];
        }
        __syncthreads();
    }

    // copy back the data
    if(threadIdx.y == 0 && pos_x < n){
        distances[pos_x] = s_data[thread_id];
    }
}


void calculateDistances(float *distances, float *dataset, float *point, int n, int d){
    float temp;

    for(int i = 0; i < n; i++){
        temp = 0.0;

        for(int j = 0; j < d; j++){
            temp += pow(dataset[i * d + j] - point[j], 2);
        }
        distances[i] = pow(temp, 0.5);
    }
}


void printData(float *dataset, int n, int d){
    cout << "============ Dataset ============" << endl;

    for(int i = 0; i < n; i++){
        cout << i + 1 << ") ";
        for(int j = 0; j < d - 1; j++){
            cout << dataset[i * d + j] << ", ";
        }
        cout << dataset[(i + 1) * d - 1] << endl;
    }
}
	.file	"tmpxft_0025079a_00000000-6_distance_test.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4830:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4830:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5602:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5602:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z13findBestSplitii
	.type	_Z13findBestSplitii, @function
_Z13findBestSplitii:
.LFB4821:
	.cfi_startproc
	endbr64
	movl	%edx, %eax
	xorl	%r9d, %r9d
	testb	$31, %dl
	movl	$32, %ecx
	setne	%r9b
	cltd
	movl	$1, 8(%rdi)
	movss	.LC0(%rip), %xmm1
	movl	$1, 20(%rdi)
	orl	$-1, %r8d
	orl	$-1, %r10d
	movss	.LC1(%rip), %xmm2
	idivl	%ecx
	movss	.LC2(%rip), %xmm5
	movl	$1, %ecx
	addl	%eax, %r9d
	cvtsi2ssl	%r9d, %xmm4
.L10:
	cvtsi2ssl	%ecx, %xmm3
	movaps	%xmm4, %xmm0
	divss	%xmm3, %xmm0
	comiss	%xmm2, %xmm0
	jb	.L15
	comiss	%xmm0, %xmm5
	jb	.L6
	movl	%r9d, %eax
	movaps	%xmm0, %xmm3
	cltd
	idivl	%ecx
	cvtsi2ssl	%eax, %xmm6
	subss	%xmm6, %xmm3
	comiss	%xmm3, %xmm1
	jbe	.L6
	cvttss2sil	%xmm0, %r8d
	movl	%ecx, %r10d
	movaps	%xmm3, %xmm1
	jmp	.L6
.L15:
	comiss	%xmm0, %xmm2
	ja	.L9
.L6:
	incl	%ecx
	cmpl	$1000, %ecx
	jne	.L10
.L9:
	sall	$5, %r8d
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
	movl	$512, %eax
	divl	%r8d
	movl	%r8d, 4(%rdi)
	xorl	%edx, %edx
	movl	%eax, %ecx
	movl	%eax, (%rdi)
	movl	%esi, %eax
	divl	%ecx
	cmpl	$1, %edx
	sbbl	$-1, %eax
	movl	%eax, 12(%rdi)
	xorl	%eax, %eax
	comiss	%xmm0, %xmm1
	seta	%al
	incl	%ecx
	imull	%r8d, %ecx
	addl	%r10d, %eax
	movl	%eax, 16(%rdi)
	movq	%rdi, %rax
	sall	$2, %ecx
	movl	%ecx, 24(%rdi)
	ret
	.cfi_endproc
.LFE4821:
	.size	_Z13findBestSplitii, .-_Z13findBestSplitii
	.globl	_Z18calculateDistancesPfS_S_ii
	.type	_Z18calculateDistancesPfS_S_ii, @function
_Z18calculateDistancesPfS_S_ii:
.LFB4826:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%r8d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L18:
	cmpl	%ebx, %ebp
	jle	.L17
	movslq	%r14d, %rax
	xorps	%xmm0, %xmm0
	leaq	0(%r13,%rax,4), %rcx
	xorl	%eax, %eax
.L21:
	cvtss2sd	%xmm0, %xmm0
	cmpl	%eax, %r12d
	jle	.L23
	movss	(%rcx,%rax,4), %xmm2
	subss	(%rdx,%rax,4), %xmm2
	incq	%rax
	cvtss2sd	%xmm2, %xmm1
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	jmp	.L21
.L23:
	movsd	.LC4(%rip), %xmm1
	movq	%rdx, 8(%rsp)
	addl	%r12d, %r14d
	call	pow@PLT
	movq	8(%rsp), %rdx
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r15,%rbx,4)
	incq	%rbx
	jmp	.L18
.L17:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4826:
	.size	_Z18calculateDistancesPfS_S_ii, .-_Z18calculateDistancesPfS_S_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"============ Dataset ============"
.LC6:
	.string	") "
.LC7:
	.string	", "
	.text
	.globl	_Z9printDataPfii
	.type	_Z9printDataPfii, @function
_Z9printDataPfii:
.LFB4827:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	leaq	_ZSt4cout(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movslq	%edx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r12, %rbx
	salq	$2, %r12
	leaq	0(%r13,%r12), %r14
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	%esi, 12(%rsp)
	leaq	.LC5(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L25:
	movl	12(%rsp), %eax
	cmpl	%eax, %ebp
	jge	.L30
	incl	%ebp
	leaq	_ZSt4cout(%rip), %rdi
	movl	%ebp, %esi
	call	_ZNSolsEi@PLT
	leaq	.LC6(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movslq	%r15d, %rax
	xorl	%edx, %edx
	leaq	0(%r13,%rax,4), %rcx
.L26:
	leal	-1(%rbx), %eax
	cmpl	%edx, %eax
	jle	.L31
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	(%rcx,%rdx,4), %xmm0
	movq	%rcx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rcx
	incq	%rdx
	jmp	.L26
.L31:
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	-4(%r14), %xmm0
	addl	%ebx, %r15d
	addq	%r12, %r14
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L25
.L30:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4827:
	.size	_Z9printDataPfii, .-_Z9printDataPfii
	.globl	_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii
	.type	_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii, @function
_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii:
.LFB4852:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z14cudaDotProductPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L32:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4852:
	.size	_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii, .-_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii
	.globl	_Z14cudaDotProductPfS_S_iii
	.type	_Z14cudaDotProductPfS_S_iii, @function
_Z14cudaDotProductPfS_S_iii:
.LFB4853:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE4853:
	.size	_Z14cudaDotProductPfS_S_iii, .-_Z14cudaDotProductPfS_S_iii
	.globl	_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii
	.type	_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii, @function
_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii:
.LFB4854:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10cudaReducePfS_iii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L37:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4854:
	.size	_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii, .-_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii
	.globl	_Z10cudaReducePfS_iii
	.type	_Z10cudaReducePfS_iii, @function
_Z10cudaReducePfS_iii:
.LFB4855:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii
	.cfi_endproc
.LFE4855:
	.size	_Z10cudaReducePfS_iii, .-_Z10cudaReducePfS_iii
	.globl	_Z16parallelDistancePfS_ii
	.type	_Z16parallelDistancePfS_ii, @function
_Z16parallelDistancePfS_ii:
.LFB4825:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%ecx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movl	%edx, 12(%rsp)
	movl	12(%rsp), %esi
	movl	%ecx, %edx
	movq	%rdi, 16(%rsp)
	leaq	76(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	movq	%rax, 40(%rsp)
	call	_Z13findBestSplitii
	movl	92(%rsp), %r12d
	movl	76(%rsp), %esi
	movabsq	$4294967297, %rax
	imull	88(%rsp), %esi
	movq	%rax, 68(%rsp)
	movl	$8, %ecx
	leaq	40(%rsp), %rdi
	testl	$7, %r12d
	movl	%r12d, %eax
	movl	$1, 60(%rsp)
	setne	%bl
	cltd
	idivl	%ecx
	xorl	%edx, %edx
	addl	%eax, %ebx
	movl	$512, %eax
	sall	$3, %ebx
	divl	%ebx
	xorl	%edx, %edx
	movl	%ebx, %r15d
	movl	%eax, %ebp
	movl	12(%rsp), %eax
	divl	%ebp
	cmpl	$1, %edx
	sbbl	$-1, %eax
	imull	%r12d, %esi
	movl	%eax, 64(%rsp)
	imull	%ebp, %r15d
	sall	$2, %esi
	movslq	%esi, %rsi
	sall	$2, %r15d
	call	cudaMalloc@PLT
	movl	80(%rsp), %eax
	cvtsi2sdq	%rax, %xmm0
	call	log2@PLT
	call	ceil@PLT
	movaps	%xmm0, %xmm1
	movsd	.LC8(%rip), %xmm0
	call	pow@PLT
	movl	84(%rsp), %ecx
	movl	96(%rsp), %esi
	xorl	%r9d, %r9d
	movslq	100(%rsp), %r8
	movq	76(%rsp), %rdx
	movsd	%xmm0, 24(%rsp)
	movq	88(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	movsd	24(%rsp), %xmm0
	testl	%eax, %eax
	jne	.L45
	cvttsd2sil	%xmm0, %r9d
	movl	12(%rsp), %ecx
	movl	%r14d, %r8d
	movq	%r13, %rsi
	movq	40(%rsp), %rdx
	movq	%r13, %rdi
	call	_Z41__device_stub__Z14cudaDotProductPfS_S_iiiPfS_S_iii
.L45:
	movl	%ebx, %eax
	cvtsi2sdq	%rax, %xmm0
	call	log2@PLT
	call	ceil@PLT
	movaps	%xmm0, %xmm1
	movsd	.LC8(%rip), %xmm0
	call	pow@PLT
	movl	%ebp, 52(%rsp)
	movl	60(%rsp), %ecx
	xorl	%r9d, %r9d
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	movl	%ebx, 56(%rsp)
	movslq	%r15d, %r8
	movq	52(%rsp), %rdx
	movsd	%xmm0, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	movsd	24(%rsp), %xmm0
	testl	%eax, %eax
	jne	.L48
	cvttsd2sil	%xmm0, %r8d
	movl	12(%rsp), %edx
	movq	16(%rsp), %rsi
	movl	%r12d, %ecx
	movq	40(%rsp), %rdi
	call	_Z35__device_stub__Z10cudaReducePfS_iiiPfS_iii
.L48:
	call	cudaGetLastError@PLT
	call	cudaDeviceSynchronize@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4825:
	.size	_Z16parallelDistancePfS_ii, .-_Z16parallelDistancePfS_ii
	.section	.rodata.str1.1
.LC10:
	.string	"Wrong number of arguments. Aborting ..."
.LC11:
	.string	"Initializing "
.LC12:
	.string	" random data points of "
.LC13:
	.string	" dimensions"
.LC14:
	.string	"Not enough memory. Aborting ..."
.LC18:
	.string	"Total Speed up: "
.LC21:
	.string	"Error exeeded threshold("
.LC22:
	.string	"): "
.LC23:
	.string	"Program: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4818:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	movq	%rax, 32(%rsp)
	movq	%rax, 40(%rsp)
	movq	%rax, 48(%rsp)
	cmpl	$3, %edi
	je	.L52
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	orl	$-1, %eax
	jmp	.L51
.L52:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%ebp, %r13d
	movl	%eax, %r12d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	imull	%r12d, %r13d
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movslq	%r13d, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L54
	leaq	.LC14(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$-2, %eax
	jmp	.L51
.L54:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$2147483647, %ecx
	xorl	%edx, %edx
	xorps	%xmm1, %xmm1
	movl	%eax, %eax
	movss	.LC15(%rip), %xmm2
	movss	.LC1(%rip), %xmm3
	movl	$2147483647, %esi
	divq	%rcx
	movss	.LC16(%rip), %xmm4
	movss	.LC17(%rip), %xmm5
	movl	$1, %eax
	testq	%rdx, %rdx
	cmove	%rax, %rdx
	xorl	%ecx, %ecx
.L55:
	cmpl	%ecx, %r13d
	jle	.L68
	imulq	$16807, %rdx, %rax
	xorl	%edx, %edx
	divq	%rsi
	movq	%rdx, %rax
	decq	%rax
	js	.L56
	cvtsi2ssq	%rax, %xmm0
	jmp	.L57
.L56:
	movq	%rax, %rdi
	andl	$1, %eax
	shrq	%rdi
	orq	%rax, %rdi
	cvtsi2ssq	%rdi, %xmm0
	addss	%xmm0, %xmm0
.L57:
	addss	%xmm1, %xmm0
	mulss	%xmm2, %xmm0
	comiss	%xmm3, %xmm0
	jb	.L58
	movss	.LC9(%rip), %xmm0
.L58:
	mulss	%xmm4, %xmm0
	subss	%xmm5, %xmm0
	movss	%xmm0, (%rbx,%rcx,4)
	incq	%rcx
	jmp	.L55
.L68:
	movslq	%ebp, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movq	%rax, %r13
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	%r12d, %r8d
	movl	%ebp, %ecx
	movq	%rbx, %rdx
	movq	%rbx, %rsi
	movq	%r14, %rdi
	movq	%rax, %r15
	call	_Z18calculateDistancesPfS_S_ii
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	16(%rsp), %rsi
	leaq	40(%rsp), %rdi
	subq	%r15, %rax
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	movslq	%r12d, %rax
	leaq	32(%rsp), %rdi
	leaq	0(,%rax,4), %r15
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdx
	movq	40(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	movq	%r15, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	40(%rsp), %rsi
	movl	%r12d, %ecx
	movl	%ebp, %edx
	movq	48(%rsp), %rdi
	movq	%rax, %r15
	call	_Z16parallelDistancePfS_ii
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%r13, %rdi
	movl	$2, %ecx
	subq	%r15, %rax
	movq	%rax, %r12
	call	cudaMemcpy@PLT
	leaq	.LC18(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtsi2ssq	%r12, %xmm1
	cvtsi2ssq	24(%rsp), %xmm0
	movq	%rax, %rdi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	.LC19(%rip), %xmm1
	xorl	%eax, %eax
.L60:
	cmpl	%eax, %ebp
	jle	.L69
	cvtss2sd	(%r14,%rax,4), %xmm0
	mulsd	%xmm0, %xmm0
	cvtss2sd	0(%r13,%rax,4), %xmm2
	incq	%rax
	subsd	%xmm2, %xmm0
	andps	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	comiss	.LC20(%rip), %xmm0
	jbe	.L60
	leaq	.LC21(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movss	%xmm0, 8(%rsp)
	movb	$1, %bpl
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$500, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC22(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	8(%rsp), %xmm0
	movq	%rax, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L62
.L69:
	xorl	%ebp, %ebp
.L62:
	leaq	.LC23(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movzbl	%bpl, %esi
	negq	%rsi
	movq	%rax, %rdi
	leaq	_ZL6Result(%rip), %rax
	andl	$10, %esi
	addq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L51:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L64
	call	__stack_chk_fail@PLT
.L64:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4818:
	.size	main, .-main
	.section	.rodata.str1.1
.LC24:
	.string	"_Z10cudaReducePfS_iii"
.LC25:
	.string	"_Z14cudaDotProductPfS_S_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4857:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC24(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10cudaReducePfS_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC25(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z14cudaDotProductPfS_S_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4857:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata
	.align 16
	.type	_ZL6Result, @object
	.size	_ZL6Result, 20
_ZL6Result:
	.string	"SUCCEDED"
	.zero	1
	.string	"FAILED"
	.zero	3
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1203982336
	.align 4
.LC1:
	.long	1065353216
	.align 4
.LC2:
	.long	1098907648
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1071644672
	.align 8
.LC8:
	.long	0
	.long	1073741824
	.section	.rodata.cst4
	.align 4
.LC9:
	.long	1065353215
	.align 4
.LC15:
	.long	805306368
	.align 4
.LC16:
	.long	1128792064
	.align 4
.LC17:
	.long	1120403456
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC19:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst4
	.align 4
.LC20:
	.long	1140457472
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime_api.h>
#include "hip/hip_runtime.h"
#include <iostream>
#include <stdlib.h>
#include <random>
#include <chrono>
#include <math.h>
using namespace std;

// Define error values
#define MEMORY_ERROR        -2
#define INPUT_ERROR         -1

// Define Constant values
#define MIN_VALUE          -100.0
#define MAX_VALUE           100.0

#define WARP_SIZE           32
#define MAX_BLOCK_THREADS   512
#define MAX_WARPS_BLOCK_Y   16
#define MIN_WARPS_BLOCK_Y   1

//#define VERBOSE


#define ERROR_THRESHOLD     500

const char Result[2][10] = {"SUCCEDED", "FAILED"};

typedef struct{
    dim3 block;
    dim3 grid;
    int s_mem;
}BestSplit;



BestSplit findBestSplit(int n, int d);

void printData(float *dataset, int n, int d);
void calculateDistances(float *distances, float *dataset, float *point, int n, int d);
void parallelDistance(float *distances, float *data, int n, int d);

__global__ void cudaReduce(float *temp, float *distances, int n, int d, int r);
__global__ void cudaDotProduct(float *dataset, float *point, float *product, int n, int d, int r);
// void serialReduce(float *sum, float *data, int n, int d);

// __global__ void deviceCalculatedDistances(float *dist, float *data, float *point, int n, int d);





int main(int argc, char *argv[]){
    // show cuda gpu details
    

    int d;      // number of dimensions
    int n;      // number of points

    // host variables
    float *h_dataset = NULL;
    float *h_distances = NULL;
    float *h_test_distances = NULL;

    // device variables
    float *d_point = NULL;
    float *d_dataset = NULL;
    float *d_distances = NULL;


    if(argc != 3){
        cout << "Wrong number of arguments. Aborting ..." << endl;
        return INPUT_ERROR;
    }else{
        // assign values
        n = atoi(argv[1]);
        d = atoi(argv[2]);

        cout << "Initializing " << n << " random data points of " << d << " dimensions" << endl;
    }


    // creating the Random dataset
    h_dataset = (float *)malloc(n * d * sizeof(float));
    


    if(h_dataset == NULL){
        cout << "Not enough memory. Aborting ..." << endl;
        free(h_dataset);
        return MEMORY_ERROR;
    }else{
        // initialize random generator engine
        unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
        default_random_engine generator(seed);
        uniform_real_distribution<float> distribution(MIN_VALUE, MAX_VALUE);

        int length = n * d;

        for(int i = 0; i < length; i++){
            h_dataset[i] = distribution(generator);
        }
    }

    // serial stuff
    h_test_distances = (float *)malloc(n * sizeof(float));
    h_distances = (float *)malloc(n * sizeof(float));

    auto start = std::chrono::high_resolution_clock::now();

    calculateDistances(h_test_distances, h_dataset, &h_dataset[0], n, d);

    auto finish = std::chrono::high_resolution_clock::now();
    auto cpu_time = std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count();

    // cuda stuff
    hipMalloc(&d_dataset, n * d * sizeof(float)); 
    hipMalloc(&d_point, d * sizeof(float)); 
    hipMalloc(&d_distances, n * sizeof(float)); 

    // copy the dataset to the device
    hipMemcpy(d_dataset, h_dataset, n * d * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(d_point, &d_dataset[0], d * sizeof(float), hipMemcpyHostToDevice);


    start = std::chrono::high_resolution_clock::now();
    parallelDistance(d_distances ,d_dataset, n , d);
    finish = std::chrono::high_resolution_clock::now();
    auto gpu_time = std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count();


    // copy the calculated distances back to the host
    hipMemcpy(h_distances, d_distances, n * sizeof(float), hipMemcpyDeviceToHost);

    

    #ifdef VERBOSE
    cout << "CPU Time: " << cpu_time << endl;
    cout << "GPU Time: " << gpu_time << endl;
    
    #endif
    cout << "Total Speed up: " << (float)cpu_time / gpu_time << endl;


    // validation
    bool fail = 0;
    for(int i = 0; i < n; i++){
        float error = abs(pow(h_test_distances[i],2) - h_distances[i]);
        if(error > ERROR_THRESHOLD){
            cout << "Error exeeded threshold("<< ERROR_THRESHOLD << "): " << error << endl;
            fail = 1;
            break;
        }
    }

    cout << "Program: " << Result[fail] << endl;

    hipFree(d_dataset);
    hipFree(d_distances);

    free(h_distances);
    free(h_dataset);

    return 0;
}



/*
 *  Function that reduces a sum in parallel efficiently by managing kernel assignments
*/

BestSplit findBestSplit(int n, int d){
    BestSplit split;

    int req_warps_y = d / WARP_SIZE  + (d % WARP_SIZE != 0);

    float min_error = 100000.0;
    int best_dividor = -1;
    int num_of_warps = -1;

    for(int split = 1; split < 1000; split++){
        float warps_in_block_y = (float)req_warps_y / split;
        
        if(MIN_WARPS_BLOCK_Y <= warps_in_block_y && warps_in_block_y <= MAX_WARPS_BLOCK_Y){
            float split_error = warps_in_block_y - (int)(req_warps_y / split);
            
            if(min_error > split_error){
                min_error = split_error;
                best_dividor = split;     
                num_of_warps = warps_in_block_y;
            }
        }else if(warps_in_block_y < 1){
            break;
        }
    }

    
    split.block.y = num_of_warps * WARP_SIZE;
    split.block.x = MAX_BLOCK_THREADS / split.block.y;
    split.grid.x = n / split.block.x + (n % split.block.x != 0);
    split.grid.y = best_dividor + (min_error > 0);

    split.s_mem = (split.block.x + 1) * split.block.y * sizeof(float);


    #ifdef VERBOSE
    cout << "Block: " << split.block.x << ", " << split.block.y << ", " << (split.block.x + 1) * split.block.y << endl;
    cout << "Grid: " << split.grid.x << ", " << split.grid.y << endl;
    cout << "Occupancy: in x: " << (float)n / (split.block.x * split.grid.x) << ", in y: " << (float)d / (split.block.y * split.grid.y) << endl;
    #endif
    
    return split;
}





void parallelDistance(float *distances, float *data, int n, int d){
    float *d_product_temp = NULL;

    BestSplit b_split = findBestSplit(n, d);
    

    
    // calculate temp block & grid sizes
    dim3 temp_block;
    dim3 temp_grid;

    int temp_size_x = b_split.block.x * b_split.grid.x;
    int temp_size_y = b_split.grid.y;
    

    temp_block.y = (temp_size_y / 8 + (temp_size_y % 8 != 0)) * 8; 
    temp_block.x = MAX_BLOCK_THREADS / temp_block.y;
    temp_grid.x = n / temp_block.x + (n % temp_block.x != 0);
    temp_grid.y = 1;

    int shared_mem = temp_block.x * temp_block.y * sizeof(float);


    #ifdef VERBOSE
    cout << "Temp Block: " << temp_block.x << ", " << temp_block.y << endl;
    cout << "Temp Grid: " << temp_grid.x << ", " << temp_grid.y << endl;
    #endif
    
    
    int temp_product_size = temp_size_x * temp_size_y * sizeof(float);
    hipMalloc(&d_product_temp, temp_product_size); 

   
    int r = pow(2,ceil(log2(b_split.block.y)));
    
    cudaDotProduct<<<b_split.grid, b_split.block, b_split.s_mem>>>(data, &data[0], d_product_temp, n, d, r);

    r = pow(2,ceil(log2(temp_block.y)));
    // cout << r << endl;
    cudaReduce<<<temp_grid, temp_block, shared_mem>>>(d_product_temp, distances, n, b_split.grid.y, r);
    

    hipError_t errSync = hipGetLastError();
    hipError_t errAsync = hipDeviceSynchronize();

    auto stop = std::chrono::high_resolution_clock::now();


    #ifdef VERBOSE
    if (errSync != hipSuccess)
		printf("Sync kernel error: %s\n", hipGetErrorString(errSync));
	if (errAsync != hipSuccess)
        printf("Async kernel error: %s\n", hipGetErrorString(errAsync));
    if (errSync == hipSuccess && errAsync == hipSuccess)
        printf("Kernals succesfully finished without any errors!\n");
    #endif
}


__global__ void cudaDotProduct(float *data, float *point, float *product, int n, int d, int r){
    // copy dataset and point to shared memory
    extern __shared__ float s_mem[];

    int thread_id = threadIdx.x * blockDim.y + threadIdx.y;
    int point_offset = blockDim.x * blockDim.y;

    float *s_point = &s_mem[point_offset];
    float *s_data = &s_mem[0];

    int pos_x = blockIdx.x * blockDim.x + threadIdx.x;
    int pos_y = blockIdx.y * blockDim.y + threadIdx.y;

    // IF the thread belongs to the first row and is inside the block dimensions copy the data else if it outfside just zero initialize the array
    if(thread_id < blockDim.y && pos_y < d){
        s_point[threadIdx.y] = point[pos_y]; 
    }else if(thread_id < blockDim.y){
        s_point[threadIdx.y] = 0.0;
    }

    // copy data
    if(pos_x < n && pos_y < d){
        s_data[thread_id] = data[pos_x * d + pos_y];
    }else{
        s_data[thread_id] = 0.0;
    }
    
    __syncthreads();

    // calculate dot product
    s_data[thread_id] = s_data[thread_id] * s_data[thread_id] - 2 * s_data[thread_id] * s_point[threadIdx.y] + s_point[threadIdx.y] * s_point[threadIdx.y];
    
    __syncthreads();

    //reduce sum in parallel
    for(int s = r / 2; s > 0; s >>= 1){
        if(threadIdx.y < s && (threadIdx.y + s) < d){
            s_data[thread_id] += s_data[thread_id + s];
        }else{
            s_data[thread_id] += 0.0;
        }
        __syncthreads();
    }

    // copy data back
    pos_x = blockIdx.x * (blockDim.x * gridDim.y);
    pos_y = blockIdx.y;
    if(threadIdx.y == 0){
        product[pos_x + pos_y + threadIdx.x * gridDim.y] = s_data[thread_id];
    }
}


// complete unroll these iterations
__global__ void cudaReduce(float *temp, float *distances, int n, int d, int r){
    extern __shared__ float s_data[];

    int thread_id = threadIdx.x * blockDim.y + threadIdx.y;
    
    int pos_x = blockIdx.x * blockDim.x + threadIdx.x;
    int pos_y = threadIdx.y;

    // copy data to shared memory
    if(pos_x < n && pos_y < d){
        s_data[thread_id] = temp[pos_x * d + pos_y];
    }else{
        s_data[thread_id] = 0.0;
    }

    __syncthreads();

    for(int s = r / 2; s > 0; s >>= 1){
        if(threadIdx.y < s && (threadIdx.y + s) < d){
            s_data[thread_id] += s_data[thread_id + s];
        }
        __syncthreads();
    }

    // copy back the data
    if(threadIdx.y == 0 && pos_x < n){
        distances[pos_x] = s_data[thread_id];
    }
}


void calculateDistances(float *distances, float *dataset, float *point, int n, int d){
    float temp;

    for(int i = 0; i < n; i++){
        temp = 0.0;

        for(int j = 0; j < d; j++){
            temp += pow(dataset[i * d + j] - point[j], 2);
        }
        distances[i] = pow(temp, 0.5);
    }
}


void printData(float *dataset, int n, int d){
    cout << "============ Dataset ============" << endl;

    for(int i = 0; i < n; i++){
        cout << i + 1 << ") ";
        for(int j = 0; j < d - 1; j++){
            cout << dataset[i * d + j] << ", ";
        }
        cout << dataset[(i + 1) * d - 1] << endl;
    }
}
	.text
	.file	"distance_test.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x43480000                      # float 200
.LCPI0_1:
	.long	0xc2c80000                      # float -100
.LCPI0_3:
	.long	0x43fa0000                      # float 500
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_2:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%eax, %eax
	movq	%rax, 24(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	cmpl	$3, %edi
	jne	.LBB0_1
# %bb.2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r12d
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r15d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str.2, %esi
	movl	$23, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%rbx, %rdi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$11, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	%r12d, %ebp
	movl	%r15d, 32(%rsp)                 # 4-byte Spill
	imull	%r15d, %ebp
	movslq	%ebp, %r13
	shlq	$2, %r13
	movq	%r13, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB0_3
# %bb.4:
	movq	%rax, %rbx
	movl	%r12d, 4(%rsp)                  # 4-byte Spill
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movl	%eax, %ecx
	leaq	(%rcx,%rcx,2), %rcx
	shrq	$32, %rcx
	movl	%eax, %edx
	subl	%ecx, %edx
	shrl	%edx
	addl	%ecx, %edx
	shrl	$30, %edx
	movl	%edx, %ecx
	shll	$31, %ecx
	orl	%edx, %ecx
	leal	(%rax,%rcx), %edx
	cmpl	$1, %edx
	adcl	%eax, %ecx
	movq	%rcx, 80(%rsp)
	testl	%ebp, %ebp
	jle	.LBB0_7
# %bb.5:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
	leaq	80(%rsp), %r14
.LBB0_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	mulss	.LCPI0_0(%rip), %xmm0
	addss	.LCPI0_1(%rip), %xmm0
	movss	%xmm0, (%rbx,%r12,4)
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB0_6
.LBB0_7:                                # %._crit_edge
	movl	32(%rsp), %r14d                 # 4-byte Reload
	movslq	%r14d, %rbp
	shlq	$2, %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r15
	movq	%r12, %rdi
	movq	%rbx, %rsi
	movq	%rbx, %rdx
	movl	%r14d, %ecx
	movl	4(%rsp), %r8d                   # 4-byte Reload
	movl	%r8d, %r14d
	callq	_Z18calculateDistancesPfS_S_ii
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r15, %rax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movslq	%r14d, %r15
	shlq	$2, %r15
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %r14
	movq	(%r14), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movq	(%r14), %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movq	(%r14), %rsi
	movl	32(%rsp), %r15d                 # 4-byte Reload
	movl	%r15d, %edx
	movl	4(%rsp), %ecx                   # 4-byte Reload
	movq	64(%rsp), %r14                  # 8-byte Reload
	callq	_Z16parallelDistancePfS_ii
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r13
	subq	56(%rsp), %r13                  # 8-byte Folded Reload
	leaq	8(%rsp), %rax
	movq	(%rax), %rsi
	movq	%r14, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$_ZSt4cout, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtsi2ssq	72(%rsp), %xmm0         # 8-byte Folded Reload
	cvtsi2ss	%r13, %xmm1
	movl	%r15d, %r13d
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%r15d, %r15d
	testl	%r13d, %r13d
	jle	.LBB0_8
# %bb.10:                               # %.lr.ph78.preheader
	movl	%r13d, %eax
	xorl	%r13d, %r13d
	movaps	.LCPI0_2(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI0_3(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorl	%ecx, %ecx
.LBB0_11:                               # %.lr.ph78
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm2, %xmm2
	cvtss2sd	(%r12,%rcx,4), %xmm2
	xorps	%xmm3, %xmm3
	cvtss2sd	(%r14,%rcx,4), %xmm3
	mulsd	%xmm2, %xmm2
	subsd	%xmm3, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB0_12
# %bb.9:                                #   in Loop: Header=BB0_11 Depth=1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB0_11
	jmp	.LBB0_13
.LBB0_1:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$39, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$-1, %r15d
	jmp	.LBB0_14
.LBB0_3:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$31, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$-2, %r15d
	jmp	.LBB0_14
.LBB0_8:
	xorl	%r13d, %r13d
	jmp	.LBB0_13
.LBB0_12:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$24, %edx
	movaps	%xmm2, 32(%rsp)                 # 16-byte Spill
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$500, %esi                      # imm = 0x1F4
	callq	_ZNSolsEi
	movq	%rax, %r12
	movl	$.L.str.7, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	32(%rsp), %xmm0                 # 16-byte Folded Reload
	movq	%r12, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$1, %r13d
.LBB0_13:                               # %.loopexit
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	(,%r13,4), %rax
	addq	%r13, %rax
	leaq	_ZL6Result(,%rax,2), %r12
	movq	%r12, %rdi
	callq	strlen
	movl	$_ZSt4cout, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
.LBB0_14:
	movl	%r15d, %eax
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z18calculateDistancesPfS_S_ii
.LCPI1_0:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z18calculateDistancesPfS_S_ii
	.type	_Z18calculateDistancesPfS_S_ii,@function
_Z18calculateDistancesPfS_S_ii:         # @_Z18calculateDistancesPfS_S_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB1_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%r8d, %ebx
	movq	%rdx, %r14
	movl	%ecx, %r13d
	movl	%r8d, %ebp
	xorl	%r15d, %r15d
	xorl	%r12d, %r12d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_7 Depth 2
	testl	%ebx, %ebx
	jle	.LBB1_3
# %bb.6:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	%r15d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %rax
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB1_7:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rax,%rcx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	subss	(%r14,%rcx,4), %xmm1
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	incq	%rcx
	cmpq	%rcx, %rbp
	jne	.LBB1_7
	jmp	.LBB1_4
.LBB1_3:                                #   in Loop: Header=BB1_2 Depth=1
	xorps	%xmm0, %xmm0
.LBB1_4:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	callq	pow
	cvtsd2ss	%xmm0, %xmm0
	movq	16(%rsp), %rax                  # 8-byte Reload
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	addl	%ebx, %r15d
	cmpq	%r13, %r12
	jne	.LBB1_2
.LBB1_5:                                # %._crit_edge21
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z18calculateDistancesPfS_S_ii, .Lfunc_end1-_Z18calculateDistancesPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z16parallelDistancePfS_ii      # -- Begin function _Z16parallelDistancePfS_ii
	.type	_Z16parallelDistancePfS_ii,@function
_Z16parallelDistancePfS_ii:             # @_Z16parallelDistancePfS_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movq	%rsi, 32(%rsp)                  # 8-byte Spill
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %rax
	movq	$0, (%rax)
	leaq	56(%rsp), %r12
	movq	%r12, %rdi
	movl	%edx, %esi
	movl	%ecx, 8(%rsp)                   # 4-byte Spill
	movl	%ecx, %edx
	callq	_Z13findBestSplitii
	movl	(%r12), %ecx
	movl	16(%r12), %r15d
	leal	7(%r15), %esi
	testl	%r15d, %r15d
	cmovnsl	%r15d, %esi
	sarl	$3, %esi
	movl	%r15d, %eax
	andl	$7, %eax
	cmpl	$1, %eax
	sbbl	$-1, %esi
	movl	%esi, %ebp
	shll	$3, %ebp
	movl	$512, %eax                      # imm = 0x200
	xorl	%edx, %edx
	divl	%ebp
	movl	%eax, %r13d
	movl	%ebx, %eax
	xorl	%edx, %edx
	divl	%r13d
	movl	%eax, %r14d
	shlq	$35, %rsi
	leaq	(%rsi,%r13), %rax
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	cmpl	$1, %edx
	sbbl	$-1, %r14d
	btsq	$32, %r14
	imull	%ebp, %r13d
	imull	12(%r12), %ecx
	shll	$2, %r13d
	imull	%r15d, %ecx
	shll	$2, %ecx
	movslq	%ecx, %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	4(%r12), %eax
	cvtsi2sd	%rax, %xmm0
	callq	log2
	callq	ceil@PLT
	callq	exp2@PLT
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movq	12(%r12), %rdi
	movl	20(%r12), %esi
	movq	(%r12), %rdx
	movl	8(%r12), %ecx
	movslq	24(%r12), %r8
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	cvttsd2si	24(%rsp), %r9d          # 8-byte Folded Reload
	movq	16(%rsp), %rdx
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movq	%rdi, %rsi
	movl	%ebx, %ecx
	movl	8(%rsp), %r8d                   # 4-byte Reload
	callq	_Z29__device_stub__cudaDotProductPfS_S_iii
.LBB2_2:
	movl	%ebp, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	callq	log2
	callq	ceil@PLT
	callq	exp2@PLT
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movslq	%r13d, %r8
	movq	%r14, %rdi
	movl	$1, %esi
	movq	48(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.3:
	cvttsd2si	8(%rsp), %r8d           # 8-byte Folded Reload
	movq	16(%rsp), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movl	%ebx, %edx
	movl	%r15d, %ecx
	callq	_Z25__device_stub__cudaReducePfS_iii
.LBB2_4:
	callq	hipGetLastError
	callq	hipDeviceSynchronize
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z16parallelDistancePfS_ii, .Lfunc_end2-_Z16parallelDistancePfS_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13findBestSplitii
.LCPI3_0:
	.long	0x47c35000                      # float 1.0E+5
.LCPI3_1:
	.long	0x3f800000                      # float 1
.LCPI3_2:
	.long	0x41800000                      # float 16
	.text
	.globl	_Z13findBestSplitii
	.type	_Z13findBestSplitii,@function
_Z13findBestSplitii:                    # @_Z13findBestSplitii
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	movl	$1, %r10d
	movl	%r10d, 8(%rdi)
	movl	%r10d, 20(%rdi)
	leal	31(%rdx), %ecx
	testl	%edx, %edx
	cmovnsl	%edx, %ecx
	sarl	$5, %ecx
	andl	$31, %edx
	cmpl	%r10d, %edx
	sbbl	$-1, %ecx
	cvtsi2ss	%ecx, %xmm1
	movl	$-1, %r8d
	movss	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI3_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movss	.LCPI3_2(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movl	$-1, %r9d
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm5, %xmm5
	cvtsi2ss	%r10d, %xmm5
	movaps	%xmm1, %xmm4
	divss	%xmm5, %xmm4
	ucomiss	%xmm2, %xmm4
	jb	.LBB3_4
# %bb.2:                                #   in Loop: Header=BB3_1 Depth=1
	ucomiss	%xmm4, %xmm3
	jb	.LBB3_4
# %bb.3:                                #   in Loop: Header=BB3_1 Depth=1
	movl	%ecx, %eax
	cltd
	idivl	%r10d
	xorps	%xmm5, %xmm5
	cvtsi2ss	%eax, %xmm5
	cvttss2si	%xmm4, %eax
	subss	%xmm5, %xmm4
	ucomiss	%xmm4, %xmm0
	cmoval	%eax, %r9d
	cmoval	%r10d, %r8d
	minss	%xmm0, %xmm4
	movaps	%xmm4, %xmm0
	jmp	.LBB3_5
.LBB3_4:                                #   in Loop: Header=BB3_1 Depth=1
	ucomiss	%xmm4, %xmm2
	ja	.LBB3_6
.LBB3_5:                                #   in Loop: Header=BB3_1 Depth=1
	incl	%r10d
	cmpl	$1000, %r10d                    # imm = 0x3E8
	jne	.LBB3_1
.LBB3_6:
	movl	%r9d, %ecx
	shll	$5, %ecx
	movl	%ecx, 4(%rdi)
	movl	$512, %eax                      # imm = 0x200
	xorl	%edx, %edx
	divl	%ecx
	movl	%eax, %ecx
	movl	%eax, (%rdi)
	movl	%esi, %eax
	xorl	%edx, %edx
	divl	%ecx
	cmpl	$1, %edx
	sbbl	$-1, %eax
	xorps	%xmm1, %xmm1
	xorl	%edx, %edx
	ucomiss	%xmm1, %xmm0
	seta	%dl
	movl	%eax, 12(%rdi)
	addl	%r8d, %edx
	movl	%edx, 16(%rdi)
	incl	%ecx
	imull	%r9d, %ecx
	shll	$7, %ecx
	movl	%ecx, 24(%rdi)
	movq	%rdi, %rax
	retq
.Lfunc_end3:
	.size	_Z13findBestSplitii, .Lfunc_end3-_Z13findBestSplitii
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__cudaDotProductPfS_S_iii # -- Begin function _Z29__device_stub__cudaDotProductPfS_S_iii
	.type	_Z29__device_stub__cudaDotProductPfS_S_iii,@function
_Z29__device_stub__cudaDotProductPfS_S_iii: # @_Z29__device_stub__cudaDotProductPfS_S_iii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14cudaDotProductPfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z29__device_stub__cudaDotProductPfS_S_iii, .Lfunc_end4-_Z29__device_stub__cudaDotProductPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__cudaReducePfS_iii # -- Begin function _Z25__device_stub__cudaReducePfS_iii
	.type	_Z25__device_stub__cudaReducePfS_iii,@function
_Z25__device_stub__cudaReducePfS_iii:   # @_Z25__device_stub__cudaReducePfS_iii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10cudaReducePfS_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z25__device_stub__cudaReducePfS_iii, .Lfunc_end5-_Z25__device_stub__cudaReducePfS_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9printDataPfii                # -- Begin function _Z9printDataPfii
	.type	_Z9printDataPfii,@function
_Z9printDataPfii:                       # @_Z9printDataPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %r15d
	movq	%rdi, (%rsp)                    # 8-byte Spill
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$33, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	testl	%r15d, %r15d
	jle	.LBB6_6
# %bb.1:                                # %.lr.ph17
	leal	-1(%rbx), %r13d
	movslq	%ebx, %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%r15d, %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	xorl	%ebp, %ebp
	xorl	%r15d, %r15d
.LBB6_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
	incq	%r15
	movl	$_ZSt4cout, %edi
	movl	%r15d, %esi
	callq	_ZNSolsEi
	movl	$.L.str.10, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cmpl	$2, %ebx
	jl	.LBB6_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	%ebp, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,4), %r12
	xorl	%r14d, %r14d
.LBB6_4:                                #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12,%r14,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.11, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r14
	cmpq	%r14, %r13
	jne	.LBB6_4
.LBB6_5:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	movq	%r15, %rax
	imulq	16(%rsp), %rax                  # 8-byte Folded Reload
	movq	(%rsp), %rcx                    # 8-byte Reload
	xorps	%xmm0, %xmm0
	cvtss2sd	-4(%rcx,%rax,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	addl	%ebx, %ebp
	cmpq	8(%rsp), %r15                   # 8-byte Folded Reload
	jne	.LBB6_2
.LBB6_6:                                # %._crit_edge18
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z9printDataPfii, .Lfunc_end6-_Z9printDataPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
.LCPI7_0:
	.quad	0x41dfffffff800000              # double 2147483646
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI7_1:
	.long	0x40000000                      # float 2
.LCPI7_2:
	.long	0x5f000000                      # float 9.22337203E+18
.LCPI7_3:
	.long	0x3f800000                      # float 1
	.section	.text._ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,"axG",@progbits,_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,comdat
	.weak	_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.type	_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,@function
_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_: # @_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$64, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	fldl	.LCPI7_0(%rip)
	fstpt	(%rsp)
	callq	logl
	fstpt	52(%rsp)                        # 10-byte Folded Spill
	flds	.LCPI7_1(%rip)
	fstpt	(%rsp)
	callq	logl
	fldt	52(%rsp)                        # 10-byte Folded Reload
	fdivp	%st, %st(1)
	flds	.LCPI7_2(%rip)
	xorl	%ecx, %ecx
	fxch	%st(1)
	fucomi	%st(1), %st
	fldz
	fcmovnb	%st(2), %st
	fstp	%st(2)
	fsubp	%st, %st(1)
	setae	%cl
	fnstcw	28(%rsp)
	movzwl	28(%rsp), %eax
	orl	$3072, %eax                     # imm = 0xC00
	movw	%ax, 30(%rsp)
	fldcw	30(%rsp)
	fistpll	40(%rsp)
	fldcw	28(%rsp)
	shlq	$63, %rcx
	xorq	40(%rsp), %rcx
	leaq	23(%rcx), %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rax, %rcx
	cmpq	$1, %rax
	adcq	$0, %rcx
	movq	(%rbx), %rsi
	xorps	%xmm0, %xmm0
	movss	.LCPI7_3(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movabsq	$8589934597, %rdi               # imm = 0x200000005
.LBB7_1:                                # %select.unfold
                                        # =>This Inner Loop Header: Depth=1
	imulq	$16807, %rsi, %rsi              # imm = 0x41A7
	movq	%rsi, %rax
	mulq	%rdi
	movq	%rsi, %rax
	subq	%rdx, %rax
	shrq	%rax
	addq	%rdx, %rax
	shrq	$30, %rax
	movq	%rax, %rdx
	shlq	$31, %rdx
	subq	%rdx, %rax
	leaq	(%rsi,%rax), %rdx
	decq	%rdx
	testq	%rdx, %rdx
	js	.LBB7_2
# %bb.3:                                # %select.unfold
                                        #   in Loop: Header=BB7_1 Depth=1
	xorps	%xmm2, %xmm2
	cvtsi2ss	%rdx, %xmm2
	jmp	.LBB7_4
.LBB7_2:                                #   in Loop: Header=BB7_1 Depth=1
	movq	%rdx, %r8
	shrq	%r8
	andl	$1, %edx
	orq	%r8, %rdx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%rdx, %xmm2
	addss	%xmm2, %xmm2
.LBB7_4:                                # %select.unfold
                                        #   in Loop: Header=BB7_1 Depth=1
	addq	%rax, %rsi
	mulss	%xmm1, %xmm2
	movss	%xmm1, 36(%rsp)
	flds	36(%rsp)
	fmull	.LCPI7_0(%rip)
	addss	%xmm2, %xmm0
	fstps	32(%rsp)
	movss	32(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	decq	%rcx
	jne	.LBB7_1
# %bb.5:
	movq	%rsi, (%rbx)
	divss	%xmm1, %xmm0
	ucomiss	.LCPI7_3(%rip), %xmm0
	jae	.LBB7_7
# %bb.6:
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB7_7:
	.cfi_def_cfa_offset 80
	movss	.LCPI7_3(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	nextafterf                      # TAILCALL
.Lfunc_end7:
	.size	_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_, .Lfunc_end7-_ZSt18generate_canonicalIfLm24ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14cudaDotProductPfS_S_iii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10cudaReducePfS_iii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB9_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Wrong number of arguments. Aborting ..."
	.size	.L.str, 40

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Initializing "
	.size	.L.str.1, 14

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" random data points of "
	.size	.L.str.2, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	" dimensions"
	.size	.L.str.3, 12

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Not enough memory. Aborting ..."
	.size	.L.str.4, 32

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Total Speed up: "
	.size	.L.str.5, 17

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error exeeded threshold("
	.size	.L.str.6, 25

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"): "
	.size	.L.str.7, 4

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Program: "
	.size	.L.str.8, 10

	.type	_ZL6Result,@object              # @_ZL6Result
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
_ZL6Result:
	.asciz	"SUCCEDED\000"
	.asciz	"FAILED\000\000\000"
	.size	_ZL6Result, 20

	.type	_Z14cudaDotProductPfS_S_iii,@object # @_Z14cudaDotProductPfS_S_iii
	.globl	_Z14cudaDotProductPfS_S_iii
	.p2align	3, 0x0
_Z14cudaDotProductPfS_S_iii:
	.quad	_Z29__device_stub__cudaDotProductPfS_S_iii
	.size	_Z14cudaDotProductPfS_S_iii, 8

	.type	_Z10cudaReducePfS_iii,@object   # @_Z10cudaReducePfS_iii
	.globl	_Z10cudaReducePfS_iii
	.p2align	3, 0x0
_Z10cudaReducePfS_iii:
	.quad	_Z25__device_stub__cudaReducePfS_iii
	.size	_Z10cudaReducePfS_iii, 8

	.type	.L.str.9,@object                # @.str.9
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.9:
	.asciz	"============ Dataset ============"
	.size	.L.str.9, 34

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	") "
	.size	.L.str.10, 3

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	", "
	.size	.L.str.11, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14cudaDotProductPfS_S_iii"
	.size	.L__unnamed_1, 28

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10cudaReducePfS_iii"
	.size	.L__unnamed_2, 22

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z29__device_stub__cudaDotProductPfS_S_iii
	.addrsig_sym _Z25__device_stub__cudaReducePfS_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZL6Result
	.addrsig_sym _Z14cudaDotProductPfS_S_iii
	.addrsig_sym _Z10cudaReducePfS_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14cudaDotProductPfS_S_iii ; -- Begin function _Z14cudaDotProductPfS_S_iii
	.globl	_Z14cudaDotProductPfS_S_iii
	.p2align	8
	.type	_Z14cudaDotProductPfS_S_iii,@function
_Z14cudaDotProductPfS_S_iii:            ; @_Z14cudaDotProductPfS_S_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[16:17], s[0:1], 0x10
	s_mov_b32 s12, s15
	v_and_b32_e32 v0, 0x3ff, v0
                                        ; implicit-def: $sgpr18
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s7, s3, 16
	s_and_b32 s3, s3, 0xffff
	v_mad_u64_u32 v[4:5], null, s12, s7, v[1:2]
	v_mad_u32_u24 v6, v0, s7, v1
	s_mul_i32 s15, s3, s7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_u32_e64 s2, s7, v6
	v_cmp_gt_i32_e32 vcc_lo, s5, v4
	s_mov_b32 s7, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s13, s2, vcc_lo
	s_xor_b32 s13, s13, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s19, s13
	s_xor_b32 s13, exec_lo, s19
; %bb.1:
	s_mov_b32 s18, 0
	s_and_b32 s7, s2, exec_lo
; %bb.2:                                ; %Flow90
	s_or_saveexec_b32 s13, s13
	v_mov_b32_e32 v2, s18
	s_lshl_b32 s15, s15, 2
	s_xor_b32 exec_lo, exec_lo, s13
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_ashrrev_i32_e32 v5, 31, v4
	s_or_b32 s7, s7, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[4:5]
	v_add_co_u32 v2, s2, s10, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s2, s11, v3, s2
	global_load_b32 v2, v[2:3], off
.LBB0_4:                                ; %Flow91
	s_or_b32 exec_lo, exec_lo, s13
	s_add_i32 s2, s15, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	v_lshl_add_u32 v5, v1, 2, s2
	s_and_saveexec_b32 s2, s7
	s_cbranch_execz .LBB0_6
; %bb.5:                                ; %.sink.split
	s_waitcnt vmcnt(0)
	ds_store_b32 v5, v2
.LBB0_6:
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[2:3], null, s14, s3, v[0:1]
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s4, v2
	s_and_b32 s3, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s2, s3
	s_cbranch_execz .LBB0_8
; %bb.7:
	v_mad_u64_u32 v[7:8], null, v2, s5, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v8, 31, v7
	v_lshlrev_b64 v[3:4], 2, v[7:8]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v4, vcc_lo
	global_load_b32 v3, v[3:4], off
.LBB0_8:
	s_or_b32 exec_lo, exec_lo, s2
	v_lshl_add_u32 v0, v6, 2, 0
	s_load_b32 s1, s[0:1], 0x2c
	s_cmp_lt_i32 s6, 2
	s_waitcnt vmcnt(0)
	ds_store_b32 v0, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v3, v0
	ds_load_b32 v4, v5
	s_waitcnt lgkmcnt(1)
	v_add_f32_e32 v5, v3, v3
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, v5, v4
	v_fma_f32 v3, v3, v3, -v5
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v3, v4, v4
.LBB0_9:                                ; =>This Inner Loop Header: Depth=1
	ds_store_b32 v0, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_13
; %bb.10:                               ; %.lr.ph
                                        ;   in Loop: Header=BB0_9 Depth=1
	s_lshr_b32 s2, s6, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v4, v0 :: v_dual_add_nc_u32 v3, s2, v1
	v_cmp_gt_u32_e32 vcc_lo, s2, v1
	v_cmp_gt_u32_e64 s0, s5, v3
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, vcc_lo, s0
	s_and_saveexec_b32 s0, s3
	s_cbranch_execz .LBB0_12
; %bb.11:                               ;   in Loop: Header=BB0_9 Depth=1
	ds_load_b32 v3, v0
	v_lshl_add_u32 v4, s2, 2, v0
.LBB0_12:                               ;   in Loop: Header=BB0_9 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	ds_load_b32 v4, v4
	s_cmp_lt_u32 s6, 4
	s_mov_b32 s6, s2
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v3, v4, v3
	s_branch .LBB0_9
.LBB0_13:                               ; %._crit_edge
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v1
	s_cbranch_execz .LBB0_15
; %bb.14:
	v_mad_u64_u32 v[3:4], null, v2, s1, s[12:13]
	ds_load_b32 v2, v0
	v_mov_b32_e32 v4, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[3:4]
	v_add_co_u32 v0, vcc_lo, s16, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s17, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v2, off
.LBB0_15:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14cudaDotProductPfS_S_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 9
		.amdhsa_next_free_sgpr 20
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z14cudaDotProductPfS_S_iii, .Lfunc_end0-_Z14cudaDotProductPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 664
; NumSgprs: 22
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z10cudaReducePfS_iii   ; -- Begin function _Z10cudaReducePfS_iii
	.globl	_Z10cudaReducePfS_iii
	.p2align	8
	.type	_Z10cudaReducePfS_iii,@function
_Z10cudaReducePfS_iii:                  ; @_Z10cudaReducePfS_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b256 s[4:11], s[0:1], 0x0
	v_and_b32_e32 v3, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s0, v[3:4]
	v_mov_b32_e32 v4, 0
	v_cmp_gt_i32_e64 s0, s9, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s8, v1
	s_and_b32 s0, s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB1_2
; %bb.1:
	v_mad_u64_u32 v[4:5], null, v1, s9, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s0, s4, v4
	v_add_co_ci_u32_e64 v5, s0, s5, v5, s0
	global_load_b32 v4, v[4:5], off
.LBB1_2:
	s_or_b32 exec_lo, exec_lo, s1
	s_lshr_b32 s0, s2, 16
	s_cmp_lt_i32 s10, 2
	v_mad_u32_u24 v2, v3, s0, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v2, v2, 2, 0
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB1_3:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_7
; %bb.4:                                ; %.lr.ph
                                        ;   in Loop: Header=BB1_3 Depth=1
	s_lshr_b32 s2, s10, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v3, s2, v0
	v_cmp_gt_u32_e64 s0, s2, v0
	v_cmp_gt_u32_e64 s1, s9, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s1, s0, s1
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_3 Depth=1
	v_lshl_add_u32 v3, s2, 2, v2
	ds_load_b32 v3, v3
	ds_load_b32 v4, v2
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v3, v3, v4
	ds_store_b32 v2, v3
.LBB1_6:                                ;   in Loop: Header=BB1_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s10, 4
	s_mov_b32 s10, s2
	s_branch .LBB1_3
.LBB1_7:                                ; %._crit_edge
	v_cmp_eq_u32_e64 s0, 0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, vcc_lo
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB1_9
; %bb.8:
	ds_load_b32 v3, v2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s6, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v3, off
.LBB1_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10cudaReducePfS_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z10cudaReducePfS_iii, .Lfunc_end1-_Z10cudaReducePfS_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 408
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         160
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14cudaDotProductPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z14cudaDotProductPfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         152
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10cudaReducePfS_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10cudaReducePfS_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
