/* Program : To query the device properties of the Tesla K40c GPU
 * Author : Anant Shah
 * Roll Number : EE16B105
 * Date : 14-8-2018
 **/

#include<stdio.h>
#include<cuda.h>
#include<stdlib.h>
	
#define DEVICE_ID 0
#define ERROR_HANDLER(error_msg) error_handler(error_msg)

void error_handler(cudaError_t error_msg){
	/* Function to handle an error in CUDA; will be used as a macro */
	if(error_msg != cudaSuccess){
		printf("%s in %s at line %d\n", cudaGetErrorString(error_msg),__FILE__,__LINE__);
		exit(EXIT_FAILURE);
	}
}

int main(int argc,char *argv[]){
	
	cudaDeviceProp*		device_properties; /* cudaDeviceProp is a struct whose variable fields consist data about the device */
	FILE			*fp; /* Pointer to a file to which the data is written */
	/* To query the specifications of each device, we run them through a for loop */
		device_properties = (cudaDeviceProp *)malloc(sizeof(cudaDeviceProp));
		ERROR_HANDLER(cudaGetDeviceProperties(device_properties,DEVICE_ID));

		fp = fopen("ee16b105_1_out.txt","w");
		if(fp!=NULL){
			fprintf(fp,"%d\n",(device_properties)->localL1CacheSupported);
			fprintf(fp,"%d \n",(device_properties)->globalL1CacheSupported);
			fprintf(fp,"%d \n",(device_properties)->l2CacheSize);
			fprintf(fp,"%d \n",(device_properties)->maxThreadsPerBlock);
			fprintf(fp,"%d \n",(device_properties)->regsPerBlock);
			fprintf(fp,"%d \n",(device_properties)->regsPerMultiprocessor);
			fprintf(fp,"%d \n",(device_properties)->warpSize);
			fprintf(fp,"%zu \n",device_properties->totalGlobalMem);

		}else{
			printf("Error : File not found");
			exit(EXIT_FAILURE);
		}
}	

	.file	"tmpxft_002fe2ad_00000000-6_ee16b105_1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/anantshah200/CS6023/master/Assignment1/ee16b105_1.cu"
.LC1:
	.string	"%s in %s at line %d\n"
	.text
	.globl	_Z13error_handler9cudaError
	.type	_Z13error_handler9cudaError, @function
_Z13error_handler9cudaError:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	$17, %r8d
	leaq	.LC0(%rip), %rcx
	movq	%rax, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13error_handler9cudaError, .-_Z13error_handler9cudaError
	.section	.rodata.str1.1
.LC2:
	.string	"w"
.LC3:
	.string	"ee16b105_1_out.txt"
.LC4:
	.string	"%d\n"
.LC5:
	.string	"%d \n"
.LC6:
	.string	"%zu \n"
.LC7:
	.string	"Error : File not found"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$1032, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	malloc@PLT
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, %rbp
	call	cudaGetDeviceProperties_v2@PLT
	movl	%eax, %edi
	call	_Z13error_handler9cudaError
	leaq	.LC2(%rip), %rsi
	leaq	.LC3(%rip), %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L11
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L11:
	movl	636(%rbp), %ecx
	movq	%rax, %rbx
	movq	%rax, %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %r12
	call	__fprintf_chk@PLT
	movl	632(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	616(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	320(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	304(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	648(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	308(%rbp), %ecx
	movq	%r12, %rdx
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	movq	288(%rbp), %rcx
	leaq	.LC6(%rip), %rdx
	call	__fprintf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.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:

/* Program : To query the device properties of the Tesla K40c GPU
 * Author : Anant Shah
 * Roll Number : EE16B105
 * Date : 14-8-2018
 **/

#include<stdio.h>
#include<hip/hip_runtime.h>
#include<stdlib.h>
	
#define DEVICE_ID 0
#define ERROR_HANDLER(error_msg) error_handler(error_msg)

void error_handler(hipError_t error_msg){
	/* Function to handle an error in CUDA; will be used as a macro */
	if(error_msg != hipSuccess){
		printf("%s in %s at line %d\n", hipGetErrorString(error_msg),__FILE__,__LINE__);
		exit(EXIT_FAILURE);
	}
}

int main(int argc,char *argv[]){
	
	hipDeviceProp_t*		device_properties; /* cudaDeviceProp is a struct whose variable fields consist data about the device */
	FILE			*fp; /* Pointer to a file to which the data is written */
	/* To query the specifications of each device, we run them through a for loop */
		device_properties = (hipDeviceProp_t *)malloc(sizeof(hipDeviceProp_t));
		ERROR_HANDLER(hipGetDeviceProperties(device_properties,DEVICE_ID));

		fp = fopen("ee16b105_1_out.txt","w");
		if(fp!=NULL){
			fprintf(fp,"%d\n",(device_properties)->localL1CacheSupported);
			fprintf(fp,"%d \n",(device_properties)->globalL1CacheSupported);
			fprintf(fp,"%d \n",(device_properties)->l2CacheSize);
			fprintf(fp,"%d \n",(device_properties)->maxThreadsPerBlock);
			fprintf(fp,"%d \n",(device_properties)->regsPerBlock);
			fprintf(fp,"%d \n",(device_properties)->regsPerMultiprocessor);
			fprintf(fp,"%d \n",(device_properties)->warpSize);
			fprintf(fp,"%zu \n",device_properties->totalGlobalMem);

		}else{
			printf("Error : File not found");
			exit(EXIT_FAILURE);
		}
}	

	.text
	.file	"ee16b105_1.hip"
	.globl	_Z13error_handler10hipError_t   # -- Begin function _Z13error_handler10hipError_t
	.type	_Z13error_handler10hipError_t,@function
_Z13error_handler10hipError_t:          # @_Z13error_handler10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$17, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z13error_handler10hipError_t, .Lfunc_end0-_Z13error_handler10hipError_t
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$1472, %edi                     # imm = 0x5C0
	callq	malloc
	movq	%rax, %rbx
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	%eax, %edi
	callq	_Z13error_handler10hipError_t
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_2
# %bb.1:
	movq	%rax, %r14
	movl	636(%rbx), %edx
	movl	$.L.str.4, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	632(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	616(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	320(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	304(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	648(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	308(%rbx), %edx
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movq	288(%rbx), %rdx
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 32
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s in %s at line %d\n"
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/anantshah200/CS6023/master/Assignment1/ee16b105_1.hip"
	.size	.L.str.1, 116

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"ee16b105_1_out.txt"
	.size	.L.str.2, 19

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d\n"
	.size	.L.str.4, 4

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%zu \n"
	.size	.L.str.6, 6

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Error : File not found"
	.size	.L.str.7, 23

	.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
