#include <cuda.h>
#include <cuda_runtime.h>
#include <curand.h>
#include <curand_kernel.h>
#include <device_launch_parameters.h>
#include <device_functions.h>
#include <time.h>
#include "curisk.cuh"

__global__ void generate_vector_sample_kernel();
__global__ void setup_gamma_generator(long seed);
__device__ __forceinline__ float generate_gamma_1_1(curandState *state);

#define CUDA_CALL(x) do { if((x)!=cudaSuccess) { \
    printf("\nError \"%s\" at %s:%d\n", cudaGetErrorString(x), __FILE__, __LINE__);\
    exit(EXIT_FAILURE);}} while(0)

#define check_error() do { if(cudaGetLastError()!=cudaSuccess) { \
    printf("\nError \"%s\" at %s:%d\n", cudaGetErrorString(cudaGetLastError()), __FILE__, __LINE__);\
    exit(EXIT_FAILURE);}} while(0)

#define ESTIMATED_MAX_DIMENSION 32

__constant__ int c_dimension;
__constant__ int c_vector_scheme[ESTIMATED_MAX_DIMENSION];
__constant__ bound_t c_vector_bounds[ESTIMATED_MAX_DIMENSION];
__constant__ ordinal_t c_vector_ordinal[ESTIMATED_MAX_DIMENSION];
__constant__ int c_sample_size;

__device__ float *d_vector_sample;
__device__ int d_round_sample_size;
__device__ float *d_round_vector_sample;
__device__ curandState *d_curand_states;
__device__ int d_vectors_ready;

void generate_vector_sample(sampling_cofiguration_t& conf, sampling_result_t& result, int timeout_rounds)
{
    int start_time_point = clock();

    /* Скопируем некоторые поля из conf в константную память. */
    conf.log() << "Preparing constant variables." << std::endl;
    cudaMemcpyToSymbol(c_dimension, &conf.dimension, sizeof(int)); check_error();
    cudaMemcpyToSymbol(c_sample_size, &conf.sample_size, sizeof(int)); check_error();
    cudaMemcpyToSymbol(c_vector_scheme, conf.vector_scheme, conf.dimension*sizeof(int)); check_error();
    cudaMemcpyToSymbol(c_vector_bounds, conf.vector_bounds, conf.dimension*sizeof(bound_t)); check_error();
    cudaMemcpyToSymbol(c_vector_ordinal, conf.vector_ordinal, conf.dimension*sizeof(ordinal_t)); check_error();

    /* Выделим память для выборки. */
    conf.log() << "Allocate memory for vector sample." << std::endl;
    float *dh_vector_sample;
    cudaMalloc(&dh_vector_sample, conf.sample_size*conf.dimension*sizeof(float)); check_error();
    cudaMemcpyToSymbol(d_vector_sample, &dh_vector_sample, sizeof(dh_vector_sample)); check_error();

    /* Выделим память для выборки раунда. */
    conf.log() << "Allocate memory for round vector sample." << std::endl;
    int blocks_per_round = conf.grid_dimension.x;
    int vectors_per_block = conf.block_dimension.x;
    int round_sample_size = blocks_per_round*vectors_per_block;
    cudaMemcpyToSymbol(d_round_sample_size, &round_sample_size, sizeof(int)); check_error();

    float *dh_round_vector_sample;
    cudaMalloc(&dh_round_vector_sample, round_sample_size*conf.dimension*sizeof(float)); check_error();
    cudaMemcpyToSymbol(d_round_vector_sample, &dh_round_vector_sample, sizeof(dh_round_vector_sample)); check_error();

    /* Настроим генератор случайных чисел. */
    conf.log() << "Setup CUDA random numbers generator." << std::endl;
    curandState *dh_curand_states;
    cudaMalloc(&dh_curand_states, round_sample_size*sizeof(curandState)); check_error();
    cudaMemcpyToSymbol(d_curand_states, &dh_curand_states, sizeof(dh_curand_states)); check_error();

    setup_gamma_generator<<<blocks_per_round, vectors_per_block>>>(clock()); check_error();
    cudaDeviceSynchronize(); check_error();

    /* Число готовых элементов выборки. */
    int vectors_ready = 0;
    cudaMemcpyToSymbol(d_vectors_ready, &vectors_ready, sizeof(vectors_ready)); check_error();

    conf.log() << "Start round cycle." << std::endl;
    int rounds = 0;
    while (vectors_ready < conf.sample_size)
    {
        generate_vector_sample_kernel<<<blocks_per_round, vectors_per_block>>>();
        CUDA_CALL(cudaDeviceSynchronize());
        cudaMemcpyFromSymbol(&vectors_ready, d_vectors_ready, sizeof(vectors_ready)); check_error();
        rounds++;
        if (rounds > timeout_rounds)
        {
            conf.log() << "Round cycle is terminated (timeout)." << std::endl;
            result.generated_vectors_number = vectors_ready;
            result.error = SAMPLING_TIMEOUT;
            break;
        }
    }

    conf.log() << "Stop round cycle." << std::endl;
    conf.log() << "Vectors generated: " << vectors_ready << "/" << conf.sample_size << "." << std::endl;

    if (vectors_ready < conf.sample_size)
    {
        cudaMemcpy(result.vector_sample, dh_vector_sample, vectors_ready*conf.dimension*sizeof(float), cudaMemcpyDeviceToHost); check_error();
    }
    else
    {
        cudaMemcpy(result.vector_sample, dh_vector_sample, conf.sample_size*conf.dimension*sizeof(float), cudaMemcpyDeviceToHost); check_error();
    }
    
    cudaFree(dh_vector_sample);
    cudaFree(dh_round_vector_sample);
    cudaFree(dh_curand_states);

    int end_time_point = clock();
    float elapsed_time = ((float) (end_time_point - start_time_point))/CLOCKS_PER_SEC;
    conf.log() << "Elapsed time: " << elapsed_time << " s." << std::endl;
    result.elapsed_time = elapsed_time;
}

__global__
void generate_vector_sample_kernel()
{
    int idx = blockIdx.x*blockDim.x + threadIdx.x;
    int dimension = c_dimension;
    int i;
    float value;
    float than_value;
    float sum = 0;
    int last_vectors_ready;
    ordinal_t ordinal;
    bound_t bound;
    bool eliminate = false;

    for (i = 0; i < dimension; i++)
    {
        if (c_vector_scheme[i] == 0)
            value = 0;
        else
            value = generate_gamma_1_1(d_curand_states + idx);

        sum += value;
        d_round_vector_sample[dimension*idx + i] = value;
    }

    if (sum != 0)
    {
        for (i = 0; i < dimension; i++)
        {
            value = d_round_vector_sample[dimension*idx + i];
            value /= sum;
            d_round_vector_sample[dimension*idx + i] = value;
            bound = c_vector_bounds[i];
            eliminate = eliminate || value < bound.left || value > bound.right;
        }

        for (i = 0; i < dimension; i++)
        {
            value = d_round_vector_sample[dimension*idx + i];
            ordinal = c_vector_ordinal[i];
            than_value = d_round_vector_sample[dimension*idx + ordinal.than_index];
            eliminate = eliminate ||
                (ordinal.ordinal == ORDINAL_LESS && value >= than_value) ||
                (ordinal.ordinal == ORDINAL_MORE && value <= than_value);
        }
    }

    if (!eliminate)
    {
        last_vectors_ready = atomicAdd(&d_vectors_ready, 1);
        if (last_vectors_ready < c_sample_size)
        {
            for (i = 0; i < dimension; i++)
                d_vector_sample[dimension*last_vectors_ready + i] = d_round_vector_sample[dimension*idx + i];
        }
    }
}

__global__
void setup_gamma_generator(long seed)
{
    int tid = threadIdx.x + blockIdx.x*blockDim.x;
    if (tid < d_round_sample_size)
        curand_init(seed, tid, 0, &d_curand_states[tid]);
}

/*
 * Функция генерирует случайную величину с распределением Gamma(1,1).
 */
__device__ __forceinline__
float generate_gamma_1_1(curandState *state)
{
    curandState localState = *state;
    float c, z, u, v, result;

    c = 1/sqrtf(9*2/3.);

    do {
        z = curand_normal(&localState);
        u = curand_uniform(&localState);
        v = powf(1 + c*z, 3);
    } while (z <= (-1/c) || logf(u) >= (0.5*z*z + 2/3. - (2/3.)*v + (2/3.)*logf(v)));

    result = (2/3.)*v;

    *state = localState;

    return result;
}
	.file	"tmpxft_002ddf28_00000000-6_curisk.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3866:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3866:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4532:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4532:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z48__device_stub__Z29generate_vector_sample_kernelvv
	.type	_Z48__device_stub__Z29generate_vector_sample_kernelvv, @function
_Z48__device_stub__Z29generate_vector_sample_kernelvv:
.LFB3888:
	.cfi_startproc
	endbr64
	subq	$88, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	movabsq	$4294967297, %rax
	leaq	8(%rsp), %rcx
	movq	%rsp, %rdx
	leaq	28(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$1, 24(%rsp)
	movl	$1, 36(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 28(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L3
	pushq	8(%rsp)
	.cfi_def_cfa_offset 104
	leaq	_Z29generate_vector_sample_kernelv(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 112
	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 104
	popq	%rdx
	.cfi_def_cfa_offset 96
.L3:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$88, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3888:
	.size	_Z48__device_stub__Z29generate_vector_sample_kernelvv, .-_Z48__device_stub__Z29generate_vector_sample_kernelvv
	.globl	_Z29generate_vector_sample_kernelv
	.type	_Z29generate_vector_sample_kernelv, @function
_Z29generate_vector_sample_kernelv:
.LFB3889:
	.cfi_startproc
	endbr64
	jmp	_Z48__device_stub__Z29generate_vector_sample_kernelvv
	.cfi_endproc
.LFE3889:
	.size	_Z29generate_vector_sample_kernelv, .-_Z29generate_vector_sample_kernelv
	.globl	_Z40__device_stub__Z21setup_gamma_generatorll
	.type	_Z40__device_stub__Z21setup_gamma_generatorll, @function
_Z40__device_stub__Z21setup_gamma_generatorll:
.LFB3890:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L9
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z21setup_gamma_generatorl(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	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 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L9:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3890:
	.size	_Z40__device_stub__Z21setup_gamma_generatorll, .-_Z40__device_stub__Z21setup_gamma_generatorll
	.globl	_Z21setup_gamma_generatorl
	.type	_Z21setup_gamma_generatorl, @function
_Z21setup_gamma_generatorl:
.LFB3891:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z21setup_gamma_generatorll
	.cfi_endproc
.LFE3891:
	.size	_Z21setup_gamma_generatorl, .-_Z21setup_gamma_generatorl
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Preparing constant variables."
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/zikovam/curisk-c/master/curisk.cu"
.LC2:
	.string	"\nError \"%s\" at %s:%d\n"
.LC3:
	.string	"Allocate memory for vector sample."
.LC4:
	.string	"Allocate memory for round vector sample."
.LC5:
	.string	"Setup CUDA random numbers generator."
.LC6:
	.string	"Start round cycle."
.LC7:
	.string	"Round cycle is terminated (timeout)."
.LC8:
	.string	"Stop round cycle."
.LC9:
	.string	"Vectors generated: "
.LC10:
	.string	"/"
.LC11:
	.string	"."
.LC13:
	.string	"Elapsed time: "
.LC14:
	.string	" s."
	.text
	.globl	_Z22generate_vector_sampleR23sampling_cofiguration_tR17sampling_result_ti
	.type	_Z22generate_vector_sampleR23sampling_cofiguration_tR17sampling_result_ti, @function
_Z22generate_vector_sampleR23sampling_cofiguration_tR17sampling_result_ti:
.LFB3862:
	.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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movl	%edx, 28(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	clock@PLT
	movq	64(%rbx), %rdi
	leaq	.LC0(%rip), %rsi
	movq	%rax, 16(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movq	%rbx, %rsi
	movl	$4, %edx
	leaq	_ZL11c_dimension(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L15
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$42, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L15:
	xorl	%ecx, %ecx
	leaq	32(%rbx), %rsi
	movl	$1, %r8d
	movl	$4, %edx
	leaq	_ZL13c_sample_size(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L16
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$43, %r8d
	movq	%rax, %rdx
.L48:
	movl	$2, %edi
	leaq	.LC1(%rip), %rcx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L16:
	movslq	(%rbx), %rdx
	movq	8(%rbx), %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	leaq	_ZL15c_vector_scheme(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L17
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$44, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L17:
	movslq	(%rbx), %rdx
	movq	16(%rbx), %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	leaq	_ZL15c_vector_bounds(%rip), %rdi
	salq	$3, %rdx
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L18
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$45, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L18:
	movslq	(%rbx), %rdx
	movq	24(%rbx), %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	leaq	_ZL16c_vector_ordinal(%rip), %rdi
	salq	$3, %rdx
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L19
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$46, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L19:
	movq	64(%rbx), %rdi
	leaq	.LC3(%rip), %rsi
	leaq	40(%rsp), %r12
	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	32(%rbx), %esi
	imull	(%rbx), %esi
	movq	%r12, %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L20
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$51, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L20:
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movl	$8, %edx
	movq	%r12, %rsi
	leaq	_ZL15d_vector_sample(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L21
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$52, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L21:
	movq	64(%rbx), %rdi
	leaq	.LC4(%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
	movl	36(%rbx), %r12d
	movl	48(%rbx), %r13d
	xorl	%ecx, %ecx
	leaq	32(%rsp), %rsi
	movl	$1, %r8d
	movl	$4, %edx
	movl	%r12d, %eax
	leaq	_ZL19d_round_sample_size(%rip), %rdi
	imull	%r13d, %eax
	movl	%eax, 32(%rsp)
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L22
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$59, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L22:
	movl	(%rbx), %esi
	imull	32(%rsp), %esi
	leaq	48(%rsp), %r14
	movq	%r14, %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L23
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$62, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L23:
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movl	$8, %edx
	movq	%r14, %rsi
	leaq	_ZL21d_round_vector_sample(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L24
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$63, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L24:
	movq	64(%rbx), %rdi
	leaq	.LC5(%rip), %rsi
	leaq	56(%rsp), %r14
	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	32(%rsp), %rsi
	movq	%r14, %rdi
	imulq	$48, %rsi, %rsi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L25
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$68, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L25:
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movl	$8, %edx
	movq	%r14, %rsi
	leaq	_ZL15d_curand_states(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L26
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$69, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L26:
	movabsq	$4294967297, %rax
	movl	%r13d, 76(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movq	%rax, 68(%rsp)
	movq	76(%rsp), %rdx
	movl	%r12d, 64(%rsp)
	movl	72(%rsp), %esi
	movq	64(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	call	clock@PLT
	movq	%rax, %rdi
	call	_Z40__device_stub__Z21setup_gamma_generatorll
.L27:
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L28
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$71, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L28:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L29
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$72, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L29:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movl	$4, %edx
	movl	%eax, 36(%rsp)
	leaq	36(%rsp), %rax
	leaq	_ZL15d_vectors_ready(%rip), %rdi
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L30
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$76, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L30:
	movq	64(%rbx), %rdi
	xorl	%r14d, %r14d
	leaq	.LC6(%rip), %rsi
	movabsq	$4294967297, %r15
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L31:
	movl	36(%rsp), %eax
	cmpl	%eax, 32(%rbx)
	jle	.L35
	movq	%r15, 80(%rsp)
	movl	84(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 68(%rsp)
	movl	72(%rsp), %esi
	movl	%r13d, 76(%rsp)
	movq	76(%rsp), %rdx
	movl	%r12d, 64(%rsp)
	movq	64(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	call	_Z48__device_stub__Z29generate_vector_sample_kernelvv
.L32:
	call	cudaDeviceSynchronize@PLT
	testl	%eax, %eax
	je	.L33
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$83, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L33:
	movq	8(%rsp), %rdi
	xorl	%ecx, %ecx
	movl	$2, %r8d
	movl	$4, %edx
	leaq	_ZL15d_vectors_ready(%rip), %rsi
	call	cudaMemcpyFromSymbol@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L34
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$84, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L34:
	movl	28(%rsp), %eax
	incl	%r14d
	cmpl	%eax, %r14d
	jle	.L31
	movq	64(%rbx), %rdi
	leaq	.LC7(%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
	movl	36(%rsp), %eax
	movl	$1, 4(%rbp)
	movl	%eax, 12(%rbp)
.L35:
	movq	64(%rbx), %rdi
	leaq	.LC8(%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
	movq	64(%rbx), %rdi
	leaq	.LC9(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	36(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	32(%rbx), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC11(%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
	movl	32(%rbx), %eax
	movl	36(%rsp), %edx
	movq	40(%rsp), %rsi
	movq	16(%rbp), %rdi
	cmpl	%edx, %eax
	jle	.L37
	imull	(%rbx), %edx
	movl	$2, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L38
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$100, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L37:
	imull	(%rbx), %eax
	movl	$2, %ecx
	movslq	%eax, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L38
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$104, %r8d
	movq	%rax, %rdx
	jmp	.L48
.L38:
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	call	clock@PLT
	movl	16(%rsp), %ecx
	movq	64(%rbx), %rdi
	leaq	.LC13(%rip), %rsi
	subl	%ecx, %eax
	cvtsi2ssl	%eax, %xmm0
	divss	.LC12(%rip), %xmm0
	movd	%xmm0, %r12d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r12d, %xmm1
	movq	%rax, %rdi
	cvtss2sd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC14(%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
	movl	%r12d, 0(%rbp)
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$104, %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
.LFE3862:
	.size	_Z22generate_vector_sampleR23sampling_cofiguration_tR17sampling_result_ti, .-_Z22generate_vector_sampleR23sampling_cofiguration_tR17sampling_result_ti
	.section	.rodata.str1.1
.LC15:
	.string	"_Z21setup_gamma_generatorl"
.LC16:
	.string	"_Z29generate_vector_sample_kernelv"
.LC17:
	.string	"precalc_xorwow_matrix"
.LC18:
	.string	"precalc_xorwow_offset_matrix"
.LC19:
	.string	"mrg32k3aM1"
.LC20:
	.string	"mrg32k3aM2"
.LC21:
	.string	"mrg32k3aM1SubSeq"
.LC22:
	.string	"mrg32k3aM2SubSeq"
.LC23:
	.string	"mrg32k3aM1Seq"
.LC24:
	.string	"mrg32k3aM2Seq"
.LC25:
	.string	"__cr_lgamma_table"
.LC26:
	.string	"c_dimension"
.LC27:
	.string	"c_vector_scheme"
.LC28:
	.string	"c_vector_bounds"
.LC29:
	.string	"c_vector_ordinal"
.LC30:
	.string	"c_sample_size"
.LC31:
	.string	"d_vector_sample"
.LC32:
	.string	"d_round_sample_size"
.LC33:
	.string	"d_round_vector_sample"
.LC34:
	.string	"d_curand_states"
.LC35:
	.string	"d_vectors_ready"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3893:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z21setup_gamma_generatorl(%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
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	movq	%rbx, %rdi
	leaq	_Z29generate_vector_sample_kernelv(%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
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC17(%rip), %rdx
	movl	$102400, %r9d
	leaq	_ZL21precalc_xorwow_matrix(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$102400, %r9d
	leaq	_ZL28precalc_xorwow_offset_matrix(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC19(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM1(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC20(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC21(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM1SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC22(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM2SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC23(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM1Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC24(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM2Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC25(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$72, %r9d
	leaq	_ZL17__cr_lgamma_table(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC26(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL11c_dimension(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC27(%rip), %rdx
	xorl	%r8d, %r8d
	movq	%rbx, %rdi
	movq	%rdx, %rcx
	movl	$128, %r9d
	leaq	_ZL15c_vector_scheme(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC28(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$256, %r9d
	leaq	_ZL15c_vector_bounds(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC29(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$256, %r9d
	leaq	_ZL16c_vector_ordinal(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC30(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL13c_sample_size(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC31(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$8, %r9d
	leaq	_ZL15d_vector_sample(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC32(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL19d_round_sample_size(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC33(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$8, %r9d
	leaq	_ZL21d_round_vector_sample(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC34(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$8, %r9d
	leaq	_ZL15d_curand_states(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC35(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$4, %r9d
	movq	%rdx, %rcx
	leaq	_ZL15d_vectors_ready(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.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
.LFE3893:
	.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
	.local	_ZL15d_vectors_ready
	.comm	_ZL15d_vectors_ready,4,4
	.local	_ZL15d_curand_states
	.comm	_ZL15d_curand_states,8,8
	.local	_ZL21d_round_vector_sample
	.comm	_ZL21d_round_vector_sample,8,8
	.local	_ZL19d_round_sample_size
	.comm	_ZL19d_round_sample_size,4,4
	.local	_ZL15d_vector_sample
	.comm	_ZL15d_vector_sample,8,8
	.local	_ZL13c_sample_size
	.comm	_ZL13c_sample_size,4,4
	.local	_ZL16c_vector_ordinal
	.comm	_ZL16c_vector_ordinal,256,32
	.local	_ZL15c_vector_bounds
	.comm	_ZL15c_vector_bounds,256,32
	.local	_ZL15c_vector_scheme
	.comm	_ZL15c_vector_scheme,128,32
	.local	_ZL11c_dimension
	.comm	_ZL11c_dimension,4,4
	.local	_ZL17__cr_lgamma_table
	.comm	_ZL17__cr_lgamma_table,72,32
	.local	_ZL13mrg32k3aM2Seq
	.comm	_ZL13mrg32k3aM2Seq,2304,32
	.local	_ZL13mrg32k3aM1Seq
	.comm	_ZL13mrg32k3aM1Seq,2304,32
	.local	_ZL16mrg32k3aM2SubSeq
	.comm	_ZL16mrg32k3aM2SubSeq,2016,32
	.local	_ZL16mrg32k3aM1SubSeq
	.comm	_ZL16mrg32k3aM1SubSeq,2016,32
	.local	_ZL10mrg32k3aM2
	.comm	_ZL10mrg32k3aM2,2304,32
	.local	_ZL10mrg32k3aM1
	.comm	_ZL10mrg32k3aM1,2304,32
	.local	_ZL28precalc_xorwow_offset_matrix
	.comm	_ZL28precalc_xorwow_offset_matrix,102400,32
	.local	_ZL21precalc_xorwow_matrix
	.comm	_ZL21precalc_xorwow_matrix,102400,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC12:
	.long	1232348160
	.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 CURISK_H
#define CURISK_H

#include <hip/hip_runtime.h>
#include <hiprand/hiprand_kernel.h>
#include <iostream>

/*
 * Структура определяет границы элемента случайного вектора.
 */
struct bound_t
{
    float left;
    float right;
};

#define BOUND_INIT {0, 1}

enum ordinal_e
{
    ORDINAL_LESS,
    ORDINAL_MORE,
    ORDINAL_NEVER_MIND
};

/*
 * Ординальное ограничение вектора. В поле than_index указывается индекс элемента,
 * относительного которого данный элемент (к которому относится структура) больше или
 * меньше.
 * 
 * Если на элемент не накладываются ординальные ограничения, то than_index == 0 и
 * ordinal == ORDINAL_NEVER_MIND.
 */
struct ordinal_t
{
    int than_index;
    ordinal_e ordinal;
};

#define ORDINAL_INIT {0, ORDINAL_NEVER_MIND}

/*
 * Конфигурация генератора выборки, которая передается ему до его запуска. В ней
 * содержатся параметры отбора и конфигурация ядра CUDA (размерность сетки и блока).
 */
struct sampling_cofiguration_t
{
    sampling_cofiguration_t(int dimension, int sample_size, dim3 grid_dimension,
        dim3 block_dimension, std::ostream& log = std::cout)
    {
        this->dimension = dimension;
        this->sample_size = sample_size;
        this->grid_dimension = grid_dimension;
        this->block_dimension = block_dimension;
        this->_log = &log;
        vector_scheme = new int[dimension];
        vector_bounds = new bound_t[dimension];
        vector_ordinal = new ordinal_t[dimension];
    }

    ~sampling_cofiguration_t()
    {
        delete [] vector_scheme;
        delete [] vector_bounds;
        delete [] vector_ordinal;
    }

    int dimension; // Размер веткора W.
    int *vector_scheme; // Схема вектора W вида (0, 1, 1, 0 ...).
    bound_t *vector_bounds;
    ordinal_t *vector_ordinal;
    int sample_size; // Количество векторов в желаемой выборке векторов.
    dim3 grid_dimension;
    dim3 block_dimension;
    std::ostream& log() { return *_log; }

private:
    std::ostream *_log;
};

/*
 * Тип ошибки, возвращаемый функцией генерации векторов
 * в структуре sampling_result_t.
 */
enum sampling_error_code_e
{
    SAMPLING_SUCCESS,
    SAMPLING_TIMEOUT,
    SAMPLING_CUDA_ERROR,
    SAMPLING_UNKNOWN_ERROR
};

/*
 * Структура результата генерации векторов. Заполняется функцией
 * генерации векторов.
 *
 * В поле generated_vectors_number хранится число сгенерированных векторов
 * выборки. Даже при неудачной генерации, оно может быть отлично от
 * нуля, поэтому неплохо бы знать об этом.
 */
struct sampling_result_t
{
    sampling_result_t(sampling_cofiguration_t *conf)
    {
        size_t size = conf->dimension*conf->sample_size;
        vector_sample = new float[size];
        memset(vector_sample, 0, size*sizeof(float));
        error = SAMPLING_SUCCESS;
        cuda_error = hipSuccess;
        generated_vectors_number = 0;
    }

    ~sampling_result_t()
    {
        delete [] vector_sample;
    }

    float elapsed_time;
    sampling_error_code_e error;
    hipError_t cuda_error;
    int generated_vectors_number;
    float *vector_sample;
};

/*
 * Функция генерации векторов. Значение timeout_rounds указывает порогове число раундов (число
 * запусков ядра CUDA), после которого генерация завершается с ошибкой. Ошибка фиксируется в
 * структуре result как SAMPLING_TIMEOUT.
 */
void generate_vector_sample(sampling_cofiguration_t& conf, sampling_result_t& result, int timeout_rounds);

#endif
	.text
	.file	"curisk.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.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
