// compile with -std=c++11 -O3 -lcurand
#include <iostream>
#include <cstdio>
#include <curand.h>

using std::cout;
using std::endl;

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
   if (code != cudaSuccess) 
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

// Utility class used to avoid linker errors with extern
// unsized shared memory arrays with templated type
template <class T>
struct SharedMemory {
	__device__ inline operator T*() {
		extern __shared__ int __smem[];
		return (T*) __smem;
	}

	__device__ inline operator const T*() const {
		extern __shared__ int __smem[];
		return (T*) __smem;
	}
};

// specialize for double to avoid unaligned memory
// access compile errors
template <>
struct SharedMemory<double> {
	__device__ inline operator double*() {
		extern __shared__ double __smem_d[];
		return (double*) __smem_d;
	}

	__device__ inline operator const double*() const {
		extern __shared__ double __smem_d[];
		return (double*) __smem_d;
	}
};

template <class T>
__device__ void reduce(T* g_idata, T* sdata) {

	// load shared mem
	unsigned int tid = threadIdx.x;

	sdata[tid] = g_idata[tid];

	__syncthreads();

	// do reduction in shared mem
	for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1) {
		if (tid < s) {
			sdata[tid] += sdata[tid + s];
		}

		__syncthreads();
	}
	// result is now in sdata[0]
}

// This kernel requires blockDim * sizeof(T) Bytes of shared memory.
// Each block processes `c * blockDim` elements.
// The buffers, which should be affected by the call to `__threadfence_system`
// must be volatile, as it is described in the CUDA C programming guide.
template <class T, bool COMMUNICATION_ON>
__global__ void producer_kernel(T* data, volatile T* partial_data, volatile unsigned* counter,
                                const unsigned c) {

	const unsigned global_start = blockIdx.x * blockDim.x * c;
	T* sdata = SharedMemory<T>();
	for (unsigned i = 0; i < c; ++i) {
		const unsigned offset = i * blockDim.x;
		const auto curr_start = data + global_start + offset;
		reduce(curr_start, sdata);
		// now we have the sum of blockDim elements in sdata[0]
		if (threadIdx.x == 0) {
			// save the mean of recently processed elements
			partial_data[blockIdx.x * c + i] = sdata[0] / (T) blockDim.x;
			if (COMMUNICATION_ON) {
				__threadfence_system();
				++counter[blockIdx.x]; // mark this block as processed
			}
		}
	}
}

template<class T, bool COMMUNICATION_ON>
__global__ void consumer_kernel(T* data, const volatile T* partial_data,
                                const volatile unsigned* counter,
                                const unsigned c) {
	__shared__ T mean;
	const unsigned global_start = blockIdx.x * blockDim.x * c;
	for (unsigned i = 0; i < c; ++i) {
		const unsigned offset = i * blockDim.x;
		if (COMMUNICATION_ON) {
			if (threadIdx.x == 0) {
				while (counter[blockIdx.x] < blockDim.x) {}
				mean = partial_data[blockIdx.x * c + i];
			}
			__syncthreads();
			data[offset + global_start + threadIdx.x] = mean;
		}
		else { // no communication
			data[offset + global_start + threadIdx.x] = threadIdx.x;
		}
	}

}


int runMeasurement(
	const unsigned num_threads,
	const unsigned num_blocks,
	const unsigned c)
{
	curandGenerator_t gen;
	curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
	using DataT = float;

	//const unsigned num_threads = 32;
	//const unsigned num_blocks = 2;
	const size_t sh_mem_size = num_threads * sizeof(DataT);
	//const unsigned c = 2; // number of results per block
	//const size_t N = num_threads * num_blocks * c; // total number of elements
	const size_t size = c * num_threads * num_blocks * sizeof(DataT); // total size in Bytes

	//cout << "  - size = " << size / 1e9 << " GB" << endl;
	//cout << "  - num_threads = " << num_threads << endl;
	//cout << "  - num_blocks = " << num_blocks << endl;
	//cout << "  - sh_mem_size = " << sh_mem_size << endl;
	//cout << "  - N = " << N << endl;
	//cout << "  - c = " << c << endl;

	DataT* in_data;
	DataT* out_data;
	DataT* partial_data;
	unsigned* counter;

	cudaSetDevice(0);
	cudaMalloc(&in_data, size);
	cudaMallocManaged(&partial_data, num_blocks * c * sizeof(DataT));
	curandGenerateUniform(gen, (float*) in_data, size / sizeof(float)); // fill with random bits
	cudaDeviceSynchronize();
	cudaSetDevice(1);
	cudaMallocManaged(&counter, num_blocks * sizeof(unsigned));
	cudaMemAdvise(counter, num_blocks * sizeof(unsigned),
	              cudaMemAdviseSetPreferredLocation, cudaCpuDeviceId);
	cudaMalloc(&out_data, size);
	cudaMemset(out_data, 0, size);
	cudaSetDevice(0);

//	cout << "  - Going to start the kernel" << endl;

	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	cudaEventRecord(start, 0);
	producer_kernel<DataT, false><<<num_blocks, num_threads, sh_mem_size>>>(in_data, partial_data, counter, c);
	cudaSetDevice(1);
	consumer_kernel<DataT, false><<<num_blocks, num_threads>>>(out_data, partial_data, counter, c);
	cudaSetDevice(0);
	gpuErrchk(cudaEventRecord(stop, 0));
	gpuErrchk(cudaEventSynchronize(stop));
	float time_in_ms;
	gpuErrchk(cudaEventElapsedTime(&time_in_ms, start, stop));
	gpuErrchk(cudaSetDevice(0));
	gpuErrchk(cudaDeviceSynchronize());

	cudaEventDestroy(start);
	cudaEventDestroy(stop);
	cudaFree(in_data);
	cudaFree(partial_data);
	cudaFree(counter);
	curandDestroyGenerator(gen);
	
	//cout << "time:" << time_in_ms << endl;
	cout << time_in_ms;
	return 0;
}

int main()
{	cout << "np.array(";
	int tArray[] = {32,256,512,1024};
	int tLength = 4;
	
	int bArray[] = {1,2,4,8};
	int bLength = 4;

	int cArray[] = {256, 1024, 4096, 16384, 65536};
	int cLength = 5;
		
	cout << "(";
	for (int t = 0; t < tLength; t++)
	{
	
		cout << "(";
		for (int b = 0; b < bLength; b++)
		{	
			cout << "(";
			for (int c = 0; c < cLength; c++)
			{
				//run kernel
				runMeasurement(tArray[t], bArray[b], cArray[c]);	
				if(c < cLength - 1)
				{
					cout << ",";
				}
			}
			cout << ")";
	
			if(b < bLength - 1)
			{
				cout << ",";
			}
		}
		cout << ")";
		

		if(t < tLength - 1)
		{
			cout << ",";
		}
	}
	cout << ")";

//	runMeasurement(512,4,4096); //b, t, c
	cout << ")" << std::endl;
}

	.file	"tmpxft_002dc3ff_00000000-6_idealruntime.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3649:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3649:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj, @function
_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj:
.LFB3671:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%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, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3671:
	.size	_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj, .-_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj
	.type	_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj, @function
_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj:
.LFB3673:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%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, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L7
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L7:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3673:
	.size	_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj, .-_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj
	.section	.text._Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,"axG",@progbits,_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,comdat
	.weak	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.type	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, @function
_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj:
.LFB3979:
	.cfi_startproc
	endbr64
	jmp	_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj
	.cfi_endproc
.LFE3979:
	.size	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, .-_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.section	.text._Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,"axG",@progbits,_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,comdat
	.weak	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.type	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, @function
_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj:
.LFB3980:
	.cfi_startproc
	endbr64
	jmp	_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj
	.cfi_endproc
.LFE3980:
	.size	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, .-_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB3635:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L19
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L13
	movl	%ebx, %edi
	call	exit@PLT
.L13:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L19:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/HarthTuwist/GPUPraktikumCUDA/master/Sheet4/idealruntime.cu"
	.text
	.globl	_Z14runMeasurementjjj
	.type	_Z14runMeasurementjjj, @function
_Z14runMeasurementjjj:
.LFB3645:
	.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
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%r13d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	movl	%ebp, %r15d
	movl	$100, %esi
	imull	%ebx, %r12d
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	imull	%r12d, %r15d
	leaq	8(%rsp), %rdi
	call	curandCreateGenerator@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	16(%rsp), %rdi
	leaq	0(,%r15,4), %r14
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movl	%r12d, %esi
	leaq	32(%rsp), %rdi
	movl	%ebx, %r12d
	salq	$2, %rsi
	movl	$1, %edx
	salq	$2, %r12
	call	cudaMallocManaged@PLT
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	call	curandGenerateUniform@PLT
	call	cudaDeviceSynchronize@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
	leaq	40(%rsp), %rdi
	movl	$1, %edx
	movq	%r12, %rsi
	call	cudaMallocManaged@PLT
	movq	40(%rsp), %rdi
	orl	$-1, %ecx
	movq	%r12, %rsi
	movl	$3, %edx
	call	cudaMemAdvise@PLT
	leaq	24(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%r14, %rdx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebp, 76(%rsp)
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movq	%rax, 68(%rsp)
	movq	76(%rsp), %rdx
	movl	%ebp, %eax
	movl	%ebx, 64(%rsp)
	movl	72(%rsp), %esi
	leaq	0(,%rax,4), %r8
	movq	64(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	%r13d, %ecx
	movq	16(%rsp), %rdi
	call	_ZL53__device_stub__Z15producer_kernelIfLb0EEvPT_PVS0_PVjjPfPVfPVjj
.L23:
	movl	$1, %edi
	call	cudaSetDevice@PLT
	movl	%ebp, 76(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%ebx, 64(%rsp)
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movq	%rax, 68(%rsp)
	movq	76(%rsp), %rdx
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	%r13d, %ecx
	movq	24(%rsp), %rdi
	call	_ZL55__device_stub__Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjjPfPVKfPVKjj
.L24:
	xorl	%edi, %edi
	leaq	.LC1(%rip), %rbx
	call	cudaSetDevice@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$1, %ecx
	movl	$171, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	$1, %ecx
	movl	$172, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	76(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	$1, %ecx
	movl	$174, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	$1, %ecx
	movl	$175, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceSynchronize@PLT
	movl	$1, %ecx
	movl	$176, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	curandDestroyGenerator@PLT
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	76(%rsp), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3645:
	.size	_Z14runMeasurementjjj, .-_Z14runMeasurementjjj
	.section	.rodata.str1.1
.LC2:
	.string	"np.array("
.LC3:
	.string	"("
.LC4:
	.string	")"
.LC5:
	.string	","
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3646:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rsi
	leaq	.LC3(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC5(%rip), %r14
	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
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	_ZSt4cout(%rip), %rbx
	movq	%rbx, %rdi
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r15, %rsi
	movq	%rbx, %rdi
	movabsq	$1099511627808, %rax
	movq	%rax, 4(%rsp)
	movabsq	$4398046511616, %rax
	movq	%rax, 12(%rsp)
	movabsq	$8589934593, %rax
	movq	%rax, 20(%rsp)
	movabsq	$34359738372, %rax
	movq	%rax, 28(%rsp)
	movabsq	$4398046511360, %rax
	movq	%rax, 36(%rsp)
	movabsq	$70368744181760, %rax
	movq	%rax, 44(%rsp)
	movl	$65536, 52(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L35:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%r13d, %r13d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L34:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L31:
	movl	36(%rsp,%r12,4), %edx
	movl	20(%rsp,%r13,4), %esi
	incq	%r12
	movl	4(%rsp,%rbp,4), %edi
	call	_Z14runMeasurementjjj
	cmpq	$5, %r12
	jne	.L28
	leaq	.LC4(%rip), %r12
	movq	%rbx, %rdi
	incq	%r13
	movq	%r12, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cmpq	$4, %r13
	jne	.L29
	jmp	.L41
.L28:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L31
.L41:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	incq	%rbp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cmpq	$4, %rbp
	jne	.L32
	jmp	.L42
.L29:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L34
.L42:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %rdi
	movq	%r12, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L32:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L35
.L36:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3646:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj"
.LC7:
	.string	"_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3676:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj(%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	.LC7(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj(%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
.LFE3676:
	.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
	.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:

// compile with -std=c++11 -O3 -lcurand

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

using std::cout;
using std::endl;

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
   if (code != hipSuccess) 
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

// Utility class used to avoid linker errors with extern
// unsized shared memory arrays with templated type
template <class T>
struct SharedMemory {
	__device__ inline operator T*() {
		extern __shared__ int __smem[];
		return (T*) __smem;
	}

	__device__ inline operator const T*() const {
		extern __shared__ int __smem[];
		return (T*) __smem;
	}
};

// specialize for double to avoid unaligned memory
// access compile errors
template <>
struct SharedMemory<double> {
	__device__ inline operator double*() {
		extern __shared__ double __smem_d[];
		return (double*) __smem_d;
	}

	__device__ inline operator const double*() const {
		extern __shared__ double __smem_d[];
		return (double*) __smem_d;
	}
};

template <class T>
__device__ void reduce(T* g_idata, T* sdata) {

	// load shared mem
	unsigned int tid = threadIdx.x;

	sdata[tid] = g_idata[tid];

	__syncthreads();

	// do reduction in shared mem
	for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1) {
		if (tid < s) {
			sdata[tid] += sdata[tid + s];
		}

		__syncthreads();
	}
	// result is now in sdata[0]
}

// This kernel requires blockDim * sizeof(T) Bytes of shared memory.
// Each block processes `c * blockDim` elements.
// The buffers, which should be affected by the call to `__threadfence_system`
// must be volatile, as it is described in the CUDA C programming guide.
template <class T, bool COMMUNICATION_ON>
__global__ void producer_kernel(T* data, volatile T* partial_data, volatile unsigned* counter,
                                const unsigned c) {

	const unsigned global_start = blockIdx.x * blockDim.x * c;
	T* sdata = SharedMemory<T>();
	for (unsigned i = 0; i < c; ++i) {
		const unsigned offset = i * blockDim.x;
		const auto curr_start = data + global_start + offset;
		reduce(curr_start, sdata);
		// now we have the sum of blockDim elements in sdata[0]
		if (threadIdx.x == 0) {
			// save the mean of recently processed elements
			partial_data[blockIdx.x * c + i] = sdata[0] / (T) blockDim.x;
			if (COMMUNICATION_ON) {
				__threadfence_system();
				++counter[blockIdx.x]; // mark this block as processed
			}
		}
	}
}

template<class T, bool COMMUNICATION_ON>
__global__ void consumer_kernel(T* data, const volatile T* partial_data,
                                const volatile unsigned* counter,
                                const unsigned c) {
	__shared__ T mean;
	const unsigned global_start = blockIdx.x * blockDim.x * c;
	for (unsigned i = 0; i < c; ++i) {
		const unsigned offset = i * blockDim.x;
		if (COMMUNICATION_ON) {
			if (threadIdx.x == 0) {
				while (counter[blockIdx.x] < blockDim.x) {}
				mean = partial_data[blockIdx.x * c + i];
			}
			__syncthreads();
			data[offset + global_start + threadIdx.x] = mean;
		}
		else { // no communication
			data[offset + global_start + threadIdx.x] = threadIdx.x;
		}
	}

}


int runMeasurement(
	const unsigned num_threads,
	const unsigned num_blocks,
	const unsigned c)
{
	hiprandGenerator_t gen;
	hiprandCreateGenerator(&gen, HIPRAND_RNG_PSEUDO_DEFAULT);
	using DataT = float;

	//const unsigned num_threads = 32;
	//const unsigned num_blocks = 2;
	const size_t sh_mem_size = num_threads * sizeof(DataT);
	//const unsigned c = 2; // number of results per block
	//const size_t N = num_threads * num_blocks * c; // total number of elements
	const size_t size = c * num_threads * num_blocks * sizeof(DataT); // total size in Bytes

	//cout << "  - size = " << size / 1e9 << " GB" << endl;
	//cout << "  - num_threads = " << num_threads << endl;
	//cout << "  - num_blocks = " << num_blocks << endl;
	//cout << "  - sh_mem_size = " << sh_mem_size << endl;
	//cout << "  - N = " << N << endl;
	//cout << "  - c = " << c << endl;

	DataT* in_data;
	DataT* out_data;
	DataT* partial_data;
	unsigned* counter;

	hipSetDevice(0);
	hipMalloc(&in_data, size);
	hipMallocManaged(&partial_data, num_blocks * c * sizeof(DataT));
	hiprandGenerateUniform(gen, (float*) in_data, size / sizeof(float)); // fill with random bits
	hipDeviceSynchronize();
	hipSetDevice(1);
	hipMallocManaged(&counter, num_blocks * sizeof(unsigned));
	hipMemAdvise(counter, num_blocks * sizeof(unsigned),
	              hipMemAdviseSetPreferredLocation, hipCpuDeviceId);
	hipMalloc(&out_data, size);
	hipMemset(out_data, 0, size);
	hipSetDevice(0);

//	cout << "  - Going to start the kernel" << endl;

	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	hipEventRecord(start, 0);
	producer_kernel<DataT, false><<<num_blocks, num_threads, sh_mem_size>>>(in_data, partial_data, counter, c);
	hipSetDevice(1);
	consumer_kernel<DataT, false><<<num_blocks, num_threads>>>(out_data, partial_data, counter, c);
	hipSetDevice(0);
	gpuErrchk(hipEventRecord(stop, 0));
	gpuErrchk(hipEventSynchronize(stop));
	float time_in_ms;
	gpuErrchk(hipEventElapsedTime(&time_in_ms, start, stop));
	gpuErrchk(hipSetDevice(0));
	gpuErrchk(hipDeviceSynchronize());

	hipEventDestroy(start);
	hipEventDestroy(stop);
	hipFree(in_data);
	hipFree(partial_data);
	hipFree(counter);
	hiprandDestroyGenerator(gen);
	
	//cout << "time:" << time_in_ms << endl;
	cout << time_in_ms;
	return 0;
}

int main()
{	cout << "np.array(";
	int tArray[] = {32,256,512,1024};
	int tLength = 4;
	
	int bArray[] = {1,2,4,8};
	int bLength = 4;

	int cArray[] = {256, 1024, 4096, 16384, 65536};
	int cLength = 5;
		
	cout << "(";
	for (int t = 0; t < tLength; t++)
	{
	
		cout << "(";
		for (int b = 0; b < bLength; b++)
		{	
			cout << "(";
			for (int c = 0; c < cLength; c++)
			{
				//run kernel
				runMeasurement(tArray[t], bArray[b], cArray[c]);	
				if(c < cLength - 1)
				{
					cout << ",";
				}
			}
			cout << ")";
	
			if(b < bLength - 1)
			{
				cout << ",";
			}
		}
		cout << ")";
		

		if(t < tLength - 1)
		{
			cout << ",";
		}
	}
	cout << ")";

//	runMeasurement(512,4,4096); //b, t, c
	cout << ")" << std::endl;
}

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

                                        # End of file scope inline assembly
	.globl	_Z14runMeasurementjjj           # -- Begin function _Z14runMeasurementjjj
	.type	_Z14runMeasurementjjj,@function
_Z14runMeasurementjjj:                  # @_Z14runMeasurementjjj
	.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
	movl	%esi, %ebp
	movl	%edi, %r12d
	leaq	64(%rsp), %rdi
	movl	$400, %esi                      # imm = 0x190
	callq	hiprandCreateGenerator
	movl	%r12d, %r14d
	leaq	(,%r14,4), %rax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movl	%ebx, 12(%rsp)                  # 4-byte Spill
	movl	%ebx, %r15d
	imull	%ebp, %r15d
	imull	%r15d, %r12d
	leaq	(,%r12,4), %r13
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	shlq	$2, %r15
	leaq	32(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	64(%rsp), %rax
	movq	(%rax), %rdi
	movq	(%rbx), %rsi
	movq	%r12, %rdx
	callq	hiprandGenerateUniform
	callq	hipDeviceSynchronize
	movl	$1, %edi
	callq	hipSetDevice
	movl	%ebp, %r12d
	leaq	(,%r12,4), %rbx
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbx, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r15), %rdi
	movq	%rbx, %rsi
	movl	$3, %edx
	movl	$-1, %ecx
	callq	hipMemAdvise
	leaq	80(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	movq	%r13, %rdx
	callq	hipMemset
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	48(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	btsq	$32, %r12
	btsq	$32, %r14
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	movq	72(%rsp), %r8                   # 8-byte Reload
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_2
# %bb.1:
	movq	56(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	callq	_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
.LBB0_2:
	movl	$1, %edi
	callq	hipSetDevice
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_4
# %bb.3:
	movq	80(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	callq	_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
.LBB0_4:
	xorl	%edi, %edi
	callq	hipSetDevice
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.7:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.9:                                # %_Z9gpuAssert10hipError_tPKcib.exit27
	movq	48(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB0_10
# %bb.11:                               # %_Z9gpuAssert10hipError_tPKcib.exit29
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_12
# %bb.13:                               # %_Z9gpuAssert10hipError_tPKcib.exit31
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_14
# %bb.15:                               # %_Z9gpuAssert10hipError_tPKcib.exit33
	movq	48(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hiprandDestroyGenerator
	cvtss2sd	44(%rsp), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	xorl	%eax, %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
.LBB0_5:
	.cfi_def_cfa_offset 144
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$173, %r8d
	jmp	.LBB0_6
.LBB0_8:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$174, %r8d
	jmp	.LBB0_6
.LBB0_10:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$176, %r8d
	jmp	.LBB0_6
.LBB0_12:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$177, %r8d
	jmp	.LBB0_6
.LBB0_14:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$178, %r8d
.LBB0_6:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z14runMeasurementjjj, .Lfunc_end0-_Z14runMeasurementjjj
	.cfi_endproc
                                        # -- End function
	.section	.text._Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj,"axG",@progbits,_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj,comdat
	.weak	_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj # -- Begin function _Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
	.type	_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj,@function
_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj: # @_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end1:
	.size	_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj, .Lfunc_end1-_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
	.cfi_endproc
                                        # -- End function
	.section	.text._Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,"axG",@progbits,_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,comdat
	.weak	_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj # -- Begin function _Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.type	_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,@function
_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj: # @_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end2:
	.size	_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, .Lfunc_end2-_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	32                              # 0x20
	.long	256                             # 0x100
	.long	512                             # 0x200
	.long	1024                            # 0x400
.LCPI3_1:
	.long	1                               # 0x1
	.long	2                               # 0x2
	.long	4                               # 0x4
	.long	8                               # 0x8
.LCPI3_2:
	.long	256                             # 0x100
	.long	1024                            # 0x400
	.long	4096                            # 0x1000
	.long	16384                           # 0x4000
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movaps	.LCPI3_0(%rip), %xmm0           # xmm0 = [32,256,512,1024]
	movaps	%xmm0, 48(%rsp)
	movaps	.LCPI3_1(%rip), %xmm0           # xmm0 = [1,2,4,8]
	movaps	%xmm0, 32(%rsp)
	movaps	.LCPI3_2(%rip), %xmm0           # xmm0 = [256,1024,4096,16384]
	movaps	%xmm0, (%rsp)
	movl	$65536, 16(%rsp)                # imm = 0x10000
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%r15d, %r15d
	movl	(%rsp), %ebx
.LBB3_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
                                        #       Child Loop BB3_3 Depth 3
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%r12d, %r12d
.LBB3_2:                                #   Parent Loop BB3_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_3 Depth 3
	movl	$1, %r13d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	48(%rsp,%r15,4), %ebp
	movl	32(%rsp,%r12,4), %r14d
	movl	%ebp, %edi
	movl	%r14d, %esi
	movl	%ebx, %edx
	callq	_Z14runMeasurementjjj
.LBB3_3:                                #   Parent Loop BB3_1 Depth=1
                                        #     Parent Loop BB3_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rsp,%r13,4), %edx
	movl	%ebp, %edi
	movl	%r14d, %esi
	callq	_Z14runMeasurementjjj
	incq	%r13
	cmpq	$5, %r13
	jne	.LBB3_3
# %bb.4:                                #   in Loop: Header=BB3_2 Depth=2
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	cmpq	$3, %r12
	je	.LBB3_5
# %bb.7:                                #   in Loop: Header=BB3_2 Depth=2
	movl	$.L.str.3, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r12
	jmp	.LBB3_2
.LBB3_5:                                #   in Loop: Header=BB3_1 Depth=1
	movl	$.L.str.4, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cmpq	$3, %r15
	je	.LBB3_6
# %bb.8:                                #   in Loop: Header=BB3_1 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r15
	jmp	.LBB3_1
.LBB3_6:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$1, %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
	xorl	%eax, %eax
	addq	$72, %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_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, %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	$_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,@object # @_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.section	.rodata._Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,"aG",@progbits,_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,comdat
	.weak	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.p2align	3, 0x0
_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj:
	.quad	_Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
	.size	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, 8

	.type	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,@object # @_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.section	.rodata._Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,"aG",@progbits,_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,comdat
	.weak	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.p2align	3, 0x0
_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj:
	.quad	_Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.size	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/HarthTuwist/GPUPraktikumCUDA/master/Sheet4/idealruntime.hip"
	.size	.L.str, 122

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"np.array("
	.size	.L.str.1, 10

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"("
	.size	.L.str.2, 2

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.5, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj"
	.size	.L__unnamed_1, 40

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj"
	.size	.L__unnamed_2, 42

	.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 _Z30__device_stub__producer_kernelIfLb0EEvPT_PVS0_PVjj
	.addrsig_sym _Z30__device_stub__consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.addrsig_sym _Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.section	.text._Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,"axG",@progbits,_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,comdat
	.protected	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj ; -- Begin function _Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.globl	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
	.p2align	8
	.type	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,@function
_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj: ; @_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
; %bb.0:
	s_load_b32 s8, s[0:1], 0x18
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s8, 0
	s_cbranch_scc1 .LBB0_9
; %bb.1:                                ; %.lr.ph
	s_clause 0x1
	s_load_b32 s12, s[0:1], 0x2c
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mul_i32 s1, s15, s8
	v_lshlrev_b32_e32 v3, 2, v0
	v_cmp_eq_u32_e64 s0, 0, v0
	v_mov_b32_e32 v5, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v1, 0, v3
	s_waitcnt lgkmcnt(0)
	s_and_b32 s9, s12, 0xffff
	s_mul_i32 s2, s1, s9
	v_cvt_f32_u32_e32 v2, s9
	s_lshl_b64 s[10:11], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_add_u32 s2, s4, s10
	s_addc_u32 s4, s5, s11
	v_add_co_u32 v3, s2, s2, v3
	v_add_co_ci_u32_e64 v4, null, s4, 0, s2
	s_cmp_gt_u32 s9, 1
	s_mov_b32 s10, 0
	s_cselect_b32 s4, -1, 0
	s_bfe_u32 s5, s12, 0xf0001
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_mul_i32 s2, s10, s9
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[12:13], s[2:3], 2
	s_mov_b32 s2, s5
	v_add_co_u32 v6, vcc_lo, v3, s12
	v_add_co_ci_u32_e32 v7, vcc_lo, s13, v4, vcc_lo
	s_and_not1_b32 vcc_lo, exec_lo, s4
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v6
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB0_6
.LBB0_3:                                ; %.lr.ph.i
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_mov_b32 s11, exec_lo
	v_cmpx_gt_u32_e64 s2, v0
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=2
	v_lshl_add_u32 v6, s2, 2, v1
	ds_load_b32 v6, v6
	ds_load_b32 v7, v1
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v6, v6, v7
	ds_store_b32 v1, v6
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=2
	s_or_b32 exec_lo, exec_lo, s11
	s_lshr_b32 s11, s2, 1
	s_cmp_gt_u32 s2, 1
	s_mov_b32 s2, s11
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_3
.LBB0_6:                                ; %_Z6reduceIfEvPT_S1_.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_saveexec_b32 s11, s0
	s_cbranch_execz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_2 Depth=1
	ds_load_b32 v6, v5
	s_add_i32 s2, s10, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[12:13], s[2:3], 2
	s_add_u32 s12, s6, s12
	s_addc_u32 s13, s7, s13
	s_waitcnt lgkmcnt(0)
	v_div_scale_f32 v7, null, v2, v2, v6
	v_div_scale_f32 v10, vcc_lo, v6, v2, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v8, v7
	s_waitcnt_depctr 0xfff
	v_fma_f32 v9, -v7, v8, 1.0
	v_fmac_f32_e32 v8, v9, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v9, v10, v8
	v_fma_f32 v11, -v7, v9, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v9, v11, v8
	v_fma_f32 v7, -v7, v9, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v7, v7, v8, v9
	v_div_fixup_f32 v8, v7, v2, v6
	v_dual_mov_b32 v6, s12 :: v_dual_mov_b32 v7, s13
	flat_store_b32 v[6:7], v8 dlc
	s_waitcnt_vscnt null, 0x0
.LBB0_8:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
	s_add_i32 s10, s10, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s10, s8
	s_cbranch_scc0 .LBB0_2
.LBB0_9:                                ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
		.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 0
		.amdhsa_next_free_vgpr 12
		.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
	.section	.text._Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,"axG",@progbits,_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj,comdat
.Lfunc_end0:
	.size	_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj, .Lfunc_end0-_Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 488
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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: 0
	.section	.text._Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,"axG",@progbits,_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,comdat
	.protected	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj ; -- Begin function _Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.globl	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
	.p2align	8
	.type	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,@function
_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj: ; @_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
; %bb.0:
	s_load_b32 s2, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc1 .LBB1_3
; %bb.1:                                ; %.lr.ph
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mul_i32 s15, s15, s2
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s3, v[0:1]
	v_cvt_f32_u32_e32 v0, v0
	v_mov_b32_e32 v2, 0
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, s3, v1
	s_add_i32 s2, s2, -1
	s_cmp_eq_u32 s2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	global_store_b32 v[3:4], v0, off
	s_cbranch_scc0 .LBB1_2
.LBB1_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
		.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 0
		.amdhsa_next_free_vgpr 5
		.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
	.section	.text._Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,"axG",@progbits,_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj,comdat
.Lfunc_end1:
	.size	_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj, .Lfunc_end1-_Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 140
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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: 0
	.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:         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:           _Z15producer_kernelIfLb0EEvPT_PVS0_PVjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15producer_kernelIfLb0EEvPT_PVS0_PVjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .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
    .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:           _Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15consumer_kernelIfLb0EEvPT_PVKS0_PVKjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
