#include "sum.cuh"
#include <cstdio>
#include <iostream>

const float COEFFICIENT = 1389.38757;

int get_max_cols(Matrix A) {
    int globalsum = 0;
    int n = A.height;

    for (size_t i = 0; i < n; i++) {
        int localsum = 0;
        for (size_t j = 0; j < n; j++) {
            if (A.elements[i * n + j] > 0) {
                localsum++;
            }
        }
        if (localsum > globalsum) {
            globalsum = localsum;
        }
    }
    return globalsum;
}

void fill_ell_matrix(ELL_Matrix ell, Matrix A, int nrows, int ncols, int ncols_per_row) {



    for (size_t i = 0; i < nrows; i++) {
        int colidx = 0;
        for (size_t j = 0; j < ncols; j++) {
            if (A.elements[i * nrows + j] != 0) {
                ell.data[colidx * nrows + i] = A.elements[i * nrows + j];
                ell.col_indices[colidx * nrows + i] = j;
                colidx++;
            }
        }
    }
}

void ell_mallocHost(){

}

void ell_freeHost() {

}

__device__ float sign(float x) {
    float t = x < 0 ? -1.0 : 0.0;
    return x > 0 ? 1.0 : t;
}

__device__ float atom_dist (atom a1, atom a2) {
    float sum =  (a1.x - a2.x) * (a1.x - a2.x) +
            (a1.y - a2.y) * (a1.y - a2.y) +
            (a1.z - a2.z) * (a1.z - a2.z);
    return sqrtf(sum);
}

void calculate(float* bonds, size_t n, atom* atom_coords, float* charges) {
    //TODO hard-coded value! fix it
    size_t ncols_per_row = 4;

    Matrix A;
    A.elements = bonds;
    A.height = n;
    A.width = n;

    size_t size = A.width * A.height * sizeof(float);

    ELL_Matrix ell_A;

    size_t sizefloat = n * ncols_per_row * sizeof(float);
    size_t sizeint = n * ncols_per_row * sizeof(int);

    cudaMallocHost((void**)&ell_A.data, sizefloat);
    cudaMallocHost((void**)&ell_A.col_indices, sizeint);

    ell_A.ncols = n;
    ell_A.nrows = n;
    ell_A.ncols_per_row = ncols_per_row;

    fill_ell_matrix(ell_A, A, n, n, 4);

    ELL_Matrix d_ell_A;
    d_ell_A.ncols_per_row = ell_A.ncols_per_row;
    d_ell_A.ncols = ell_A.ncols;
    d_ell_A.nrows = ell_A.nrows;

    cudaMalloc((void**)&d_ell_A.data, sizefloat);
    cudaMalloc((void**)&d_ell_A.col_indices, sizeint);

    cudaMemcpy(d_ell_A.data, ell_A.data, sizefloat, cudaMemcpyHostToDevice);
    cudaMemcpy(d_ell_A.col_indices, ell_A.col_indices, sizeint, cudaMemcpyHostToDevice);

    Matrix Asquared;
    Asquared.width = n;
    Asquared.height = n;
    cudaMallocHost((void**)&Asquared.elements, size);

    /*Matrix Acubed;
    cudaMallocHost((void**)&Acubed.elements, size);
    Acubed.height = n;
    Acubed.width = n;*/

    Matrix d_A;
    d_A.width = A.width;
    d_A.height = A.height;
    cudaMalloc((void**)&d_A.elements, size);
    cudaMemcpy(d_A.elements, A.elements, size, cudaMemcpyHostToDevice);

    Matrix d_B;
    d_B.width = A.width;
    d_B.height = A.height;
    cudaMalloc((void**)&d_B.elements, size);
    cudaMemcpy(d_B.elements, A.elements, size, cudaMemcpyHostToDevice);

    Matrix d_Asquared;
    d_Asquared.width = A.width;
    d_Asquared.height = A.height;
    cudaMalloc((void**)&d_Asquared.elements, size);



    dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);

    dim3 dimGrid(A.width / dimBlock.x + 1, A.height / dimBlock.y + 1);

    dim3 dimBlock1(BLOCK_SIZE);

    dim3 dimGrid1(n / dimBlock1.x + 1);
    //std::cout << "Launching kernel for multiply" << std::endl;

    //matrix_mult<<<dimGrid, dimBlock>>>(d_A, d_B, d_Asquared);
    //cudaDeviceSynchronize();
    //std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;


    for (int i = 0; i < n; i++) {
        ell_mult<<<dimGrid1, dimBlock1>>>(d_ell_A, d_A, d_Asquared, i);
        //cudaDeviceSynchronize();
        //std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;
    }
    cudaDeviceSynchronize();
    cudaMemcpy(Asquared.elements, d_Asquared.elements, size, cudaMemcpyDeviceToHost);

    int ncols_per_row2 = get_max_cols(Asquared);

    ELL_Matrix ell_Asq;

    size_t sizefloat2 = n * ncols_per_row2 * sizeof(float);
    size_t sizeint2 = n * ncols_per_row2 * sizeof(int);

    cudaMallocHost((void**)&ell_Asq.data, sizefloat2);
    cudaMallocHost((void**)&ell_Asq.col_indices, sizeint2);

    ell_Asq.ncols = n;
    ell_Asq.nrows = n;
    ell_Asq.ncols_per_row = ncols_per_row2;

    fill_ell_matrix(ell_Asq, Asquared, n, n, ncols_per_row2);

    ELL_Matrix d_ell_Asq;
    d_ell_Asq.ncols_per_row = ell_Asq.ncols_per_row;
    d_ell_Asq.ncols = ell_Asq.ncols;
    d_ell_Asq.nrows = ell_Asq.nrows;

    cudaMalloc((void**)&d_ell_Asq.data, sizefloat2);
    cudaMalloc((void**)&d_ell_Asq.col_indices, sizeint2);

    cudaMemcpy(d_ell_Asq.data, ell_Asq.data, sizefloat2, cudaMemcpyHostToDevice);
    cudaMemcpy(d_ell_Asq.col_indices, ell_Asq.col_indices, sizeint2, cudaMemcpyHostToDevice);

    Matrix d_Acubed;
    d_Acubed.width = A.width;
    d_Acubed.height = A.height;
    cudaMalloc((void**)&d_Acubed.elements, size);

    atom* d_atoms;
    cudaMalloc((void**)&d_atoms, n * sizeof(atom));
    cudaMemcpy(d_atoms, atom_coords, n * sizeof(atom), cudaMemcpyHostToDevice);

    for (int i = 0; i < n; i++) {
        ell_mult<<<dimGrid1, dimBlock1>>>(d_ell_Asq, d_A, d_Acubed, i);
        //cudaDeviceSynchronize();
        //std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;
    }

    //matrix_mult<<<dimGrid, dimBlock>>>(d_A, d_Asquared, d_Acubed);
    cudaDeviceSynchronize();
    std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;

    cudaDeviceSynchronize();
    std::cout << "Finished multiplication" << std::endl;
    //cudaMemcpy(Acubed.elements, d_Acubed.elements, size, cudaMemcpyDeviceToHost);

    Matrix F;
    F.width = n;
    F.height = n;

    cudaMalloc((void**)&F.elements, size);

    get_matrix_F<<<dimGrid, dimBlock>>>(d_Acubed, d_Asquared, d_A, d_atoms, F);
    cudaDeviceSynchronize();
    std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;

/*    Matrix F_host;
    F_host.width = F.width;
    F_host.height = F.width;
    cudaMallocHost((void**)&F_host.elements, size);
    cudaMemcpy(F_host.elements, F.elements, size, cudaMemcpyDeviceToHost);

    for (size_t i = 0; i < n * n; i++) {
        if (F_host.elements[i] != 0) {
            std::cout << F_host.elements[i] << std::endl;
        }
    }*/

    float* res;
    float* d_res;
    float* d_charges;



    cudaMallocHost((void**)&res, n * sizeof(float));
    cudaMalloc((void**)&d_res, n * sizeof(float));

    cudaMalloc((void**)&d_charges, n * sizeof(float));
    cudaMemcpy(d_charges, charges, n * sizeof(float), cudaMemcpyHostToDevice);


  /*  dim3 dimBlock1(BLOCK_SIZE);

    dim3 dimGrid1(n / dimBlock1.x + 1);*/

    get_vector_to_sum<<<dimGrid1, dimBlock1>>>(F, d_charges, d_res);
    cudaDeviceSynchronize();
    std::cout << cudaGetErrorString(cudaGetLastError()) << std::endl;



    cudaMemcpy(res, d_res, n * sizeof(float), cudaMemcpyDeviceToHost);

    float ans = 0;


    for (size_t i = 0; i < n; i++) {
        ans += res[i];
    }

    std::cout << "Answer is " << (COEFFICIENT * ans) / 2 << std::endl;

    cudaFree(d_A.elements);
    cudaFree(d_Asquared.elements);
    cudaFree(d_Acubed.elements);
    cudaFree(d_atoms);
    cudaFree(d_res);
    cudaFree(d_charges);
}




__global__ void matrix_mult(Matrix A, Matrix B, Matrix C){
    float Cvalue = 0;
    if (blockIdx.y * blockDim.y + threadIdx.y < A.width && blockIdx.x * blockDim.x + threadIdx.x < A.width){
        int row = blockIdx.y * blockDim.y + threadIdx.y;
        int col = blockIdx.x * blockDim.x + threadIdx.x;
        for (int e = 0; e < A.width; ++e) {
            Cvalue += A.elements[row * A.width + e] * B.elements[e * B.width + col];
        }
    C.elements[row * C.width + col] = Cvalue;
    }
}

__global__ void get_matrix_F(Matrix ACube, Matrix ASquare, Matrix A, atom* atoms, Matrix F) {
    float value = 0;
    float cube = 0;
    float square = 0;
    float a = 0;
    if (blockIdx.y * blockDim.y + threadIdx.y < A.width && blockIdx.x * blockDim.x + threadIdx.x < A.width){
        int row = blockIdx.y * blockDim.y + threadIdx.y;
        int col = blockIdx.x * blockDim.x + threadIdx.x;
        int idx = row * A.width + col;
        if (row != col) {
            value = 1 - 0.5 * sign(ACube.elements[idx] + ASquare.elements[idx] + A.elements[idx]) -
                              0.5 * sign(ASquare.elements[idx] + A.elements[idx]);
            value /= atom_dist(atoms[row], atoms[col]);
            F.elements[idx] = value;
        }
        else {
            F.elements[idx] = 0.0;
        }
    }
}

__global__ void get_vector_to_sum(Matrix F, float* q, float* res) {
    float value = 0;
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < F.width) {
        for (int j = 0; j < F.height; j++) { //TODO maybe permute indices order
            value += F.elements[j * F.height + i] * q[j];
        }
        value *= q[i];
        res[i] = value;
    }
}

/**
 * kernel for ELL matrix-vector multiplication
 *
 */

__global__ void ell_mult(ELL_Matrix A, Matrix B, Matrix C, int i){
    int row = blockDim.x * blockIdx.x + threadIdx.x;

    if (row < A.nrows) {
        float dot = 0;

        for (int idx = 0; idx < A.ncols_per_row; idx++) {
            int col = A.col_indices[A.nrows * idx + row];
            float val = A.data[A.nrows * idx + row];

            if (val != 0) {
                dot += val * B.elements[i * B.height + col];
            }
            C.elements[i * C.height + row] = dot;
        }
    }
}






	.file	"tmpxft_0032699f_00000000-6_sum.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3644:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3644:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4309:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4309:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z12get_max_cols6Matrix
	.type	_Z12get_max_cols6Matrix, @function
_Z12get_max_cols6Matrix:
.LFB3635:
	.cfi_startproc
	endbr64
	sarq	$32, %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L4:
	cmpq	%rdi, %r8
	jnb	.L12
	leaq	(%rsi,%r9,4), %r10
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.L7:
	movss	(%r10,%rcx,4), %xmm1
	comiss	%xmm0, %xmm1
	jbe	.L5
	incl	%edx
.L5:
	incq	%rcx
	cmpq	%rdi, %rcx
	jb	.L7
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	incq	%r8
	addq	%rdi, %r9
	jmp	.L4
.L12:
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z12get_max_cols6Matrix, .-_Z12get_max_cols6Matrix
	.globl	_Z15fill_ell_matrix10ELL_Matrix6Matrixiii
	.type	_Z15fill_ell_matrix10ELL_Matrix6Matrixiii, @function
_Z15fill_ell_matrix10ELL_Matrix6Matrixiii:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%edx, %r11
	movq	%rsi, %r9
	xorl	%r10d, %r10d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r11, %rdi
	xorl	%esi, %esi
	movslq	%ecx, %rcx
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	56(%rsp), %rbx
	xorps	%xmm1, %xmm1
	movq	48(%rsp), %rbp
.L14:
	cmpq	%r11, %rsi
	jnb	.L13
	leaq	(%r9,%r10,4), %r12
	xorl	%edx, %edx
	xorl	%r8d, %r8d
.L19:
	cmpq	%rcx, %rdx
	jnb	.L22
	movss	(%r12,%rdx,4), %xmm0
	ucomiss	%xmm1, %xmm0
	jp	.L20
	je	.L15
.L20:
	movl	%r8d, %eax
	incl	%r8d
	imull	%edi, %eax
	cltq
	addq	%rsi, %rax
	movss	%xmm0, (%rbx,%rax,4)
	movl	%edx, 0(%rbp,%rax,4)
.L15:
	incq	%rdx
	jmp	.L19
.L22:
	incq	%rsi
	addq	%r11, %r10
	jmp	.L14
.L13:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z15fill_ell_matrix10ELL_Matrix6Matrixiii, .-_Z15fill_ell_matrix10ELL_Matrix6Matrixiii
	.globl	_Z14ell_mallocHostv
	.type	_Z14ell_mallocHostv, @function
_Z14ell_mallocHostv:
.LFB3637:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z14ell_mallocHostv, .-_Z14ell_mallocHostv
	.globl	_Z12ell_freeHostv
	.type	_Z12ell_freeHostv, @function
_Z12ell_freeHostv:
.LFB4308:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE4308:
	.size	_Z12ell_freeHostv, .-_Z12ell_freeHostv
	.globl	_Z4signf
	.type	_Z4signf, @function
_Z4signf:
.LFB3639:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3639:
	.size	_Z4signf, .-_Z4signf
	.globl	_Z9atom_dist4atomS_
	.type	_Z9atom_dist4atomS_, @function
_Z9atom_dist4atomS_:
.LFB3640:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movl	$1, 44(%rsp)
	movl	44(%rsp), %edi
	movq	%xmm0, 16(%rsp)
	movss	%xmm1, 24(%rsp)
	movq	%xmm2, (%rsp)
	movss	%xmm3, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE3640:
	.size	_Z9atom_dist4atomS_, .-_Z9atom_dist4atomS_
	.globl	_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_
	.type	_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_, @function
_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_:
.LFB3666:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rcx
	movq	%rdi, 64(%rsp)
	movabsq	$4294967297, %rax
	movq	%rsi, 72(%rsp)
	leaq	16(%rsp), %rdi
	leaq	28(%rsp), %rsi
	movq	%rdx, 80(%rsp)
	movq	%rsp, %rdx
	movq	%rax, 16(%rsp)
	movl	$1, 24(%rsp)
	movq	%rax, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	8(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z11matrix_mult6MatrixS_S_(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 128
	movq	44(%rsp), %rcx
	movl	52(%rsp), %r8d
	movq	32(%rsp), %rsi
	movl	40(%rsp), %edx
	leaq	80(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L29:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3666:
	.size	_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_, .-_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_
	.globl	_Z11matrix_mult6MatrixS_S_
	.type	_Z11matrix_mult6MatrixS_S_, @function
_Z11matrix_mult6MatrixS_S_:
.LFB3667:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movq	%rdi, 32(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rsi, 40(%rsp)
	leaq	16(%rsp), %rsi
	movq	%rdx, 16(%rsp)
	movq	%rsp, %rdx
	movq	%rcx, 24(%rsp)
	movq	%r8, (%rsp)
	movq	%r9, 8(%rsp)
	call	_Z40__device_stub__Z11matrix_mult6MatrixS_S_R6MatrixS0_S0_
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3667:
	.size	_Z11matrix_mult6MatrixS_S_, .-_Z11matrix_mult6MatrixS_S_
	.globl	_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_
	.type	_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_, @function
_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_:
.LFB3668:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rcx, 8(%rsp)
	leaq	24(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movq	%rdi, 80(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rsi, 88(%rsp)
	leaq	44(%rsp), %rsi
	movq	%rdx, 96(%rsp)
	leaq	16(%rsp), %rdx
	movq	%rax, 104(%rsp)
	movabsq	$4294967297, %rax
	movq	%r8, 112(%rsp)
	movq	%rax, 32(%rsp)
	movl	$1, 40(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L35
	pushq	24(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z12get_matrix_F6MatrixS_S_P4atomS_(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 160
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L35:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3668:
	.size	_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_, .-_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_
	.globl	_Z12get_matrix_F6MatrixS_S_P4atomS_
	.type	_Z12get_matrix_F6MatrixS_S_P4atomS_, @function
_Z12get_matrix_F6MatrixS_S_P4atomS_:
.LFB3669:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movq	%rcx, 24(%rsp)
	movq	64(%rsp), %rcx
	movq	%rdi, 32(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rsi, 40(%rsp)
	leaq	16(%rsp), %rsi
	movq	%rdx, 16(%rsp)
	movq	%rsp, %rdx
	movq	%r8, (%rsp)
	leaq	72(%rsp), %r8
	movq	%r9, 8(%rsp)
	call	_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3669:
	.size	_Z12get_matrix_F6MatrixS_S_P4atomS_, .-_Z12get_matrix_F6MatrixS_S_P4atomS_
	.globl	_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_
	.type	_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_, @function
_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_:
.LFB3670:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rsi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	44(%rsp), %rsi
	movq	%rdx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movq	%rdi, 80(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movl	$1, 40(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z17get_vector_to_sum6MatrixPfS0_(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L41:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3670:
	.size	_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_, .-_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_
	.globl	_Z17get_vector_to_sum6MatrixPfS0_
	.type	_Z17get_vector_to_sum6MatrixPfS0_, @function
_Z17get_vector_to_sum6MatrixPfS0_:
.LFB3671:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rdi, (%rsp)
	movq	%rsp, %rdi
	movq	%rsi, 8(%rsp)
	movq	%rdx, %rsi
	movq	%rcx, %rdx
	call	_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3671:
	.size	_Z17get_vector_to_sum6MatrixPfS0_, .-_Z17get_vector_to_sum6MatrixPfS0_
	.globl	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i
	.type	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i, @function
_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i:
.LFB3672:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movl	%ecx, 12(%rsp)
	leaq	32(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movq	%rdi, 88(%rsp)
	leaq	40(%rsp), %rdi
	movq	%rsi, 96(%rsp)
	leaq	52(%rsp), %rsi
	movq	%rdx, 104(%rsp)
	leaq	24(%rsp), %rdx
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movl	$1, 48(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L47
	pushq	32(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z8ell_mult10ELL_Matrix6MatrixS0_i(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 160
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L47:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3672:
	.size	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i, .-_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i
	.globl	_Z8ell_mult10ELL_Matrix6MatrixS0_i
	.type	_Z8ell_mult10ELL_Matrix6MatrixS0_i, @function
_Z8ell_mult10ELL_Matrix6MatrixS0_i:
.LFB3673:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	%rdi, 16(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 24(%rsp)
	leaq	16(%rsp), %rsi
	movq	%rdx, (%rsp)
	movq	%rsp, %rdx
	movq	%rcx, 8(%rsp)
	movl	%r8d, %ecx
	call	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3673:
	.size	_Z8ell_mult10ELL_Matrix6MatrixS0_i, .-_Z8ell_mult10ELL_Matrix6MatrixS0_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Finished multiplication"
.LC2:
	.string	"Answer is "
	.text
	.globl	_Z9calculatePfmP4atomS_
	.type	_Z9calculatePfmP4atomS_, @function
_Z9calculatePfmP4atomS_:
.LFB3641:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	salq	$4, %rbp
	movq	%rsi, %rbx
	subq	$392, %rsp
	.cfi_def_cfa_offset 448
	movq	%fs:40, %rax
	movq	%rax, 376(%rsp)
	xorl	%eax, %eax
	movl	%esi, %eax
	leaq	240(%rsp), %rdi
	imull	%esi, %eax
	movq	%rbp, %rsi
	cltq
	salq	$2, %rax
	movq	%rax, (%rsp)
	call	cudaMallocHost@PLT
	leaq	232(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMallocHost@PLT
	movl	%ebx, 220(%rsp)
	movl	%ebx, %edi
	movl	%ebx, %ecx
	movl	%ebx, 216(%rsp)
	movq	%rbx, %rax
	subq	$32, %rsp
	.cfi_def_cfa_offset 480
	movl	%ebx, %edx
	salq	$32, %rax
	movl	$4, %r8d
	movq	%r13, %rsi
	movl	$4, 256(%rsp)
	movups	248(%rsp), %xmm1
	movups	264(%rsp), %xmm2
	orq	%rax, %rdi
	movups	%xmm1, (%rsp)
	movups	%xmm2, 16(%rsp)
	call	_Z15fill_ell_matrix10ELL_Matrix6Matrixiii
	movq	248(%rsp), %rax
	movq	%rbp, %rsi
	movq	%rax, 280(%rsp)
	movl	256(%rsp), %eax
	movl	%eax, 288(%rsp)
	addq	$32, %rsp
	.cfi_def_cfa_offset 448
	leaq	272(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	%rbp, %rsi
	leaq	264(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	240(%rsp), %rsi
	movq	%rbp, %rdx
	movq	272(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	232(%rsp), %rsi
	movq	%rbp, %rdx
	movq	264(%rsp), %rdi
	movl	$1, %ecx
	xorl	%ebp, %ebp
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	80(%rsp), %rdi
	movl	%ebx, 72(%rsp)
	movl	%ebx, 76(%rsp)
	call	cudaMallocHost@PLT
	movq	(%rsp), %rsi
	leaq	96(%rsp), %rdi
	movl	%ebx, 88(%rsp)
	movl	%ebx, 92(%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	96(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	112(%rsp), %rdi
	movl	%ebx, 104(%rsp)
	movl	%ebx, 108(%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	112(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	leaq	312(%rsp), %r13
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	movl	%ebx, 120(%rsp)
	leaq	128(%rsp), %rdi
	movl	%ebx, 124(%rsp)
	call	cudaMalloc@PLT
	movl	%ebx, %eax
	movabsq	$4294967297, %rdx
	movl	$1, 32(%rsp)
	shrl	$5, %eax
	movl	$1, 44(%rsp)
	incl	%eax
	movq	%rdx, 52(%rsp)
	movl	%eax, 36(%rsp)
	movl	%eax, 40(%rsp)
	movq	%rbx, %rax
	shrq	$5, %rax
	movq	%rdx, 64(%rsp)
	incl	%eax
	movl	%eax, 60(%rsp)
.L54:
	cmpq	%rbp, %rbx
	je	.L66
	movl	56(%rsp), %ecx
	movq	60(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$32, 48(%rsp)
	movl	68(%rsp), %esi
	movq	48(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	movups	88(%rsp), %xmm5
	movups	120(%rsp), %xmm6
	movl	%ebp, %ecx
	movq	%r13, %rdx
	movups	248(%rsp), %xmm3
	movups	264(%rsp), %xmm4
	leaq	280(%rsp), %rsi
	leaq	344(%rsp), %rdi
	movups	%xmm5, 280(%rsp)
	movups	%xmm3, 344(%rsp)
	movups	%xmm4, 360(%rsp)
	movups	%xmm6, 312(%rsp)
	call	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i
.L55:
	incq	%rbp
	jmp	.L54
.L66:
	call	cudaDeviceSynchronize@PLT
	movq	(%rsp), %rdx
	movq	80(%rsp), %rdi
	movl	$2, %ecx
	movq	128(%rsp), %rsi
	leaq	0(,%rbx,4), %rbp
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdi
	movq	80(%rsp), %rsi
	call	_Z12get_max_cols6Matrix
	leaq	304(%rsp), %rdi
	movslq	%eax, %r13
	movl	%r13d, 12(%rsp)
	imulq	%rbp, %r13
	movq	%r13, %rsi
	call	cudaMallocHost@PLT
	leaq	296(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMallocHost@PLT
	movl	12(%rsp), %r8d
	movl	%r14d, %ecx
	movl	%r14d, %edx
	movl	%ebx, 284(%rsp)
	subq	$32, %rsp
	.cfi_def_cfa_offset 480
	movl	%r8d, 320(%rsp)
	movl	%ebx, 312(%rsp)
	movups	312(%rsp), %xmm7
	movups	328(%rsp), %xmm1
	movq	104(%rsp), %rdi
	movq	112(%rsp), %rsi
	movups	%xmm7, (%rsp)
	movups	%xmm1, 16(%rsp)
	call	_Z15fill_ell_matrix10ELL_Matrix6Matrixiii
	movq	312(%rsp), %rax
	movq	%r13, %rsi
	movq	%rax, 344(%rsp)
	movl	320(%rsp), %eax
	movl	%eax, 352(%rsp)
	addq	$32, %rsp
	.cfi_def_cfa_offset 448
	leaq	336(%rsp), %rdi
	leaq	200(%rsp), %r14
	call	cudaMalloc@PLT
	movq	%r13, %rsi
	leaq	328(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	304(%rsp), %rsi
	movq	%r13, %rdx
	movq	336(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	296(%rsp), %rsi
	movq	%r13, %rdx
	movq	328(%rsp), %rdi
	movl	$1, %ecx
	imulq	$12, %rbx, %r13
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	144(%rsp), %rdi
	movl	%ebx, 136(%rsp)
	movl	%ebx, 140(%rsp)
	call	cudaMalloc@PLT
	movq	%r13, %rsi
	leaq	16(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	xorl	%r13d, %r13d
	call	cudaMemcpy@PLT
.L57:
	cmpq	%r13, %rbx
	je	.L67
	movl	56(%rsp), %ecx
	movq	60(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$32, 48(%rsp)
	movl	68(%rsp), %esi
	movq	48(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L58
	movups	312(%rsp), %xmm2
	movups	88(%rsp), %xmm4
	leaq	184(%rsp), %rsi
	leaq	344(%rsp), %rdi
	movups	328(%rsp), %xmm3
	movups	136(%rsp), %xmm5
	movl	%r13d, %ecx
	movq	%r14, %rdx
	movups	%xmm2, 344(%rsp)
	movups	%xmm3, 360(%rsp)
	movups	%xmm4, 184(%rsp)
	movups	%xmm5, 200(%rsp)
	call	_Z48__device_stub__Z8ell_mult10ELL_Matrix6MatrixS0_iR10ELL_MatrixR6MatrixS2_i
.L58:
	incq	%r13
	jmp	.L57
.L67:
	call	cudaDeviceSynchronize@PLT
	leaq	200(%rsp), %r13
	leaq	184(%rsp), %r14
	call	cudaGetLastError@PLT
	leaq	168(%rsp), %r15
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	_ZSt4cout(%rip), %rdi
	movq	%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
	call	cudaDeviceSynchronize@PLT
	leaq	.LC1(%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
	movq	(%rsp), %rsi
	leaq	160(%rsp), %rdi
	movl	%ebx, 152(%rsp)
	movl	%ebx, 156(%rsp)
	call	cudaMalloc@PLT
	movl	32(%rsp), %ecx
	movl	44(%rsp), %esi
	xorl	%r9d, %r9d
	movq	36(%rsp), %rdi
	xorl	%r8d, %r8d
	movabsq	$137438953504, %rdx
	movq	%rdx, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L60
	movups	120(%rsp), %xmm7
	movups	88(%rsp), %xmm1
	movq	%r13, %rdx
	movq	%r14, %rsi
	movups	136(%rsp), %xmm6
	movq	16(%rsp), %rcx
	movq	%r15, %rdi
	leaq	344(%rsp), %r8
	movups	152(%rsp), %xmm2
	movups	%xmm7, 184(%rsp)
	movups	%xmm6, 168(%rsp)
	movups	%xmm1, 200(%rsp)
	movups	%xmm2, 344(%rsp)
	call	_Z49__device_stub__Z12get_matrix_F6MatrixS_S_P4atomS_R6MatrixS0_S0_P4atomS0_
.L60:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	_ZSt4cout(%rip), %rdi
	movq	%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	%rbp, %rsi
	movq	%r15, %rdi
	call	cudaMallocHost@PLT
	movq	%rbp, %rsi
	movq	%r14, %rdi
	call	cudaMalloc@PLT
	movq	%rbp, %rsi
	movq	%r13, %rdi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movq	200(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movl	$32, 48(%rsp)
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	movq	48(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L61
	movups	152(%rsp), %xmm3
	movq	184(%rsp), %rdx
	leaq	344(%rsp), %rdi
	movq	200(%rsp), %rsi
	movups	%xmm3, 344(%rsp)
	call	_Z47__device_stub__Z17get_vector_to_sum6MatrixPfS0_R6MatrixPfS1_
.L61:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	_ZSt4cout(%rip), %rdi
	movq	%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	184(%rsp), %rsi
	movq	%rbp, %rdx
	movq	168(%rsp), %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	168(%rsp), %rdx
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L62:
	cmpq	%rbx, %rax
	je	.L68
	addss	(%rdx,%rax,4), %xmm0
	incq	%rax
	jmp	.L62
.L68:
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movss	%xmm0, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	(%rsp), %xmm0
	mulss	.LC3(%rip), %xmm0
	mulss	.LC4(%rip), %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
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	144(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	184(%rsp), %rdi
	call	cudaFree@PLT
	movq	200(%rsp), %rdi
	call	cudaFree@PLT
	movq	376(%rsp), %rax
	subq	%fs:40, %rax
	je	.L64
	call	__stack_chk_fail@PLT
.L64:
	addq	$392, %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
.LFE3641:
	.size	_Z9calculatePfmP4atomS_, .-_Z9calculatePfmP4atomS_
	.section	.rodata.str1.1
.LC5:
	.string	"_Z8ell_mult10ELL_Matrix6MatrixS0_i"
.LC6:
	.string	"_Z17get_vector_to_sum6MatrixPfS0_"
.LC7:
	.string	"_Z12get_matrix_F6MatrixS_S_P4atomS_"
.LC8:
	.string	"_Z11matrix_mult6MatrixS_S_"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3675:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z8ell_mult10ELL_Matrix6MatrixS0_i(%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	.LC6(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z17get_vector_to_sum6MatrixPfS0_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC7(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z12get_matrix_F6MatrixS_S_P4atomS_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC8(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11matrix_mult6MatrixS_S_(%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
.LFE3675:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1152232551
	.align 4
.LC4:
	.long	1056964608
	.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:

#ifndef SUM_CUH
#define SUM_CUH

#include <cstdint>
#include <cmath>
#include <hip/hip_runtime.h>

#define BLOCK_SIZE 32
#define BLOCK_SIZE_128 128

struct atom {
    float x;
    float y;
    float z;
};

struct Matrix {
    int width;
    int height;
    float* elements;
};

/**
 * ELLPACK Sparse matrix storage format, described in this paper: https://www.nvidia.com/docs/IO/66889/nvr-2008-004.pdf
 *
 * data and indices are stored in col-major format, for coalesced memory access in kernel
 */

struct ELL_Matrix {
    int nrows;
    int ncols;
    int ncols_per_row;
    int* col_indices;
    float* data;
};

__global__ void matrix_mult(Matrix A, Matrix B, Matrix C);

__global__ void ell_mult(ELL_Matrix A, Matrix B, Matrix C, int i);

__global__ void get_matrix_F(Matrix ACube, Matrix ASquare, Matrix A, atom* atoms, Matrix F);

__global__ void get_vector_to_sum(Matrix F, float* q, float* res);


void calculate(float* bonds, size_t n, atom* atom_coords, float* charges);

#endif //SUM_CUH
	.text
	.file	"sum.hip"
	.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 __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
