Browse Source

Add auto dataset size in polybench

hmar 4 years ago
parent
commit
d787ee8f3b

File diff suppressed because it is too large
+ 2343 - 157
real-life-dataset/config.txt


+ 88 - 78
real-life-dataset/run_dataset/energy_parser.py

@@ -20,18 +20,20 @@ import os.path
 # The temp directory to save temporary files
 temp_dir = './temp/'
 
-def find_annotated_line(line_text,file):
-	line_number = 0
+def find_annotated_line(after_line,line_text,file):
+	line_number = -1
 	with open(file) as myFile:
 		for num, line in enumerate(myFile, 1):
 			if line_text in line:
-				line_number = num
+				if num > after_line:
+					line_number = num
+					break
 	return line_number
 
 
-def energy_results():
-	line_start = "Start"
-	line_end = "End"
+def energy_results(iter):
+	line_start = 1
+	after_line = 0
 	directory = "./"
 
     #initialize return values
@@ -44,105 +46,113 @@ def energy_results():
 		output[1] = 'No info available'
 		return output, line_info
 
-	line_start = find_annotated_line(line_start,"module-power-input.txt")
-	line_end = find_annotated_line(line_end,"module-power-input.txt")
-
-	# report module power
-	f = open("module-power-input.txt")
 	module_power = 0;
 	suma = 0;
-	flag_in = 0
+	prof_time = 0;
+	gpu_power = 0;
+	cpu_power = 0;
 
-	for num, line in enumerate(f,1):
-		
-		if num == line_end:
-			flag_in = 0
-			break
+	while(line_start>0):
 
-		if flag_in == 1:
-			fields = line.split()		#split the line with whitespace as delimmiter
-			module_power = module_power + int(fields[0])
-			suma = suma + 1
+		line_start = find_annotated_line(after_line,"Start","module-power-input.txt")
+		line_end = find_annotated_line(after_line,"End","module-power-input.txt")
+		after_line = line_end
+		if line_start == -1:
+			break
 
-		if num == line_start:		#find the begining of the specified area aof the code
-			flag_in = 1
+		# report module power
+		f = open("module-power-input.txt")
+		
+		flag_in = 0
 
-	module_power = float(module_power)/suma
+		for num, line in enumerate(f,1):
+			
+			if num == line_end:
+				flag_in = 0
+				break
 
-	line_start = max(1,line_start - 1)
-	line_end = line_end - 1
+			if flag_in == 1:
+				fields = line.split()		#split the line with whitespace as delimmiter
+				module_power = module_power + int(fields[0])
+				suma = suma + 1
 
-	# report gpu power
-	f = open("GPU-power.txt")
-	gpu_power = 0;
-	suma = 0;
-	flag_in = 0
+			if num == line_start:		#find the begining of the specified area aof the code
+				flag_in = 1
 
-	for num, line in enumerate(f,1):
 		
-		if num == line_end:
-			flag_in = 0
-			break
 
-		if flag_in == 1:
-			fields = line.split()		#split the line with whitespace as delimmiter
-			gpu_power = gpu_power + int(fields[0])
-			suma = suma + 1
+		line_start = max(1,line_start - 1)
+		line_end = line_end - 1
 
-		if num == line_start:		#find the begining of the specified area aof the code
-			flag_in = 1
+		# report gpu power
+		f = open("GPU-power.txt")
+		flag_in = 0
 
-	#average module power
-	gpu_power = float(gpu_power)/suma
+		for num, line in enumerate(f,1):
+			
+			if num == line_end:
+				flag_in = 0
+				break
 
-	# report cpu power
-	f = open("CPU-power.txt")
-	cpu_power = 0;
-	suma = 0;
-	flag_in = 0
+			if flag_in == 1:
+				fields = line.split()		#split the line with whitespace as delimmiter
+				gpu_power = gpu_power + int(fields[0])
+				#suma = suma + 1
+
+			if num == line_start:		#find the begining of the specified area aof the code
+				flag_in = 1
 
-	for num, line in enumerate(f,1):
 		
-		if num == line_end:
-			flag_in = 0
-			break
 
-		if flag_in == 1:
-			fields = line.split()		#split the line with whitespace as delimmiter
-			cpu_power = cpu_power + int(fields[0])
-			suma = suma + 1
+		# report cpu power
+		f = open("CPU-power.txt")
+		flag_in = 0
 
-		if num == line_start:		#find the begining of the specified area aof the code
-			flag_in = 1
+		for num, line in enumerate(f,1):
+			
+			if num == line_end:
+				flag_in = 0
+				break
 
-	#average module power
-	cpu_power = float(cpu_power)/suma
+			if flag_in == 1:
+				fields = line.split()		#split the line with whitespace as delimmiter
+				cpu_power = cpu_power + int(fields[0])
+				#suma = suma + 1
 
-	# report time
-	f = open("prof_time.txt")
-	prof_time = 0;
-	flag_in = 0
+			if num == line_start:		#find the begining of the specified area aof the code
+				flag_in = 1
 
-	for num, line in enumerate(f,1):
-		
-		if num == line_end:
-			flag_in = 0
-			break
+		# report time
+		f = open("prof_time.txt")
+		flag_in = 0
+
+		for num, line in enumerate(f,1):
+			
+			if num == line_end:
+				flag_in = 0
+				break
+
+			if flag_in == 1:
+				fields = line.split()		#split the line with whitespace as delimmiter
+				prof_time = prof_time + int(fields[0])
 
-		if flag_in == 1:
-			fields = line.split()		#split the line with whitespace as delimmiter
-			prof_time = prof_time + int(fields[0])
+			if num == line_start:		#find the begining of the specified area aof the code
+				flag_in = 1
 
-		if num == line_start:		#find the begining of the specified area aof the code
-			flag_in = 1
+	if (suma > 0):
+		module_power = float(module_power)/suma
+		#average module power
+		gpu_power = float(gpu_power)/suma
+		#average module power
+		cpu_power = float(cpu_power)/suma
 
 	module_energy = (module_power/1000)*(float(prof_time)/1000)
 	cpu_energy = (cpu_power/1000)*(float(prof_time)/1000)
 	gpu_energy = (gpu_power/1000)*(float(prof_time)/1000)
 	total = module_energy + cpu_energy + gpu_energy
 
-	print 'module_energy: ', module_energy;
-	print 'cpu_energy: ', cpu_energy;
-	print 'gpu_energy: ', gpu_energy;
-	print module_energy, cpu_energy, gpu_energy, total
+	print 'module_energy: ', module_energy/int(iter);
+	print 'cpu_energy: ', cpu_energy/int(iter);
+	print 'gpu_energy: ', gpu_energy/int(iter);
+	print module_energy/int(iter), cpu_energy/int(iter), gpu_energy/int(iter), total/int(iter)
 

+ 54 - 0
real-life-dataset/run_dataset/measure_time_energy2.py

@@ -0,0 +1,54 @@
+import sys
+import os
+from profiller import profiller
+from application import application
+
+import signal
+import subprocess
+import time
+
+import collections
+import itertools
+import sys
+import os.path
+
+from energy_parser import *
+
+# we do not need clang parser for this operation
+#from parser import parser
+from transformer import transformer
+import ConfigParser
+from application.code_block import Code_block
+
+if (len(sys.argv) < 2):
+        print "Usage: python profiling.py <application>"
+        exit()
+
+#os.system("rm ./temp/*")
+
+configParser = ConfigParser.RawConfigParser()
+configParser.read('../config.txt')
+
+rasp_ip = configParser.get('raspberry', 'ip')
+
+os.system("cd ../ && "+configParser.get(sys.argv[1], 'build'))
+
+new_application = application.Application(configParser.get(sys.argv[1], 'dir'), configParser.get(sys.argv[1], 'exec'), configParser.get(sys.argv[1], 'source'), configParser.get(sys.argv[1], 'build'))
+
+print "Application initialized"
+
+print "==========================================================================================="
+
+pro = subprocess.Popen("./get-power.sh")
+#execute program
+time.sleep(0.5)
+#os.system("echo \"Start\" >> ./module-power-input.txt")
+start = time.time()
+os.system("cd ../ && "+configParser.get(sys.argv[1], 'exec'))
+end = time.time()
+#os.system("echo \"End\" >> ./module-power-input.txt")
+
+pro.kill()
+
+print "time = "+str(end - start)+" secs"
+energy_results()

+ 6 - 9
real-life-dataset/run_dataset/run_dataset.py

@@ -23,7 +23,7 @@ import ConfigParser
 from application.code_block import Code_block
 
 if (len(sys.argv) < 3):
-	print "Usage: python run_dataset.py <hotspot_name> <energy|time>"
+	print "Usage: python run_dataset.py <hotspot_name> <energy|energy_GPUdata> <iterations>"
 	exit()
 
 #os.system("rm ./temp/*")
@@ -42,20 +42,17 @@ print "=========================================================================
 stmts = [Code_block("../"+configParser.get(sys.argv[1], 'source'), " ", configParser.get(sys.argv[1], 'line_start'), configParser.get(sys.argv[1], 'line_end'))]
 
 #insert code to measure execution time or energy
+#set energy for collecting energy on Nvidia Tegra TX1
 transformed_hotspot = transformer.Transformer(stmts[0], sys.argv[2])
-transformed_hotspot.prepare([],[])
+transformed_hotspot.prepare([],sys.argv[3])
 
 #re-build program
 os.system("cd ../ && "+configParser.get(sys.argv[1], 'build'))
-
-if sys.argv[2]=="energy":
-    pro = subprocess.Popen("./get-power.sh")
+pro = subprocess.Popen("./get-power.sh")
 #execute program
 os.system("cd ../ && "+configParser.get(sys.argv[1], 'exec'))
+pro.kill()
 
-if sys.argv[2]=="energy":
-    pro.kill()
+energy_results(sys.argv[3])
 #restore source file
 transformed_hotspot.restore()
-if sys.argv[2]=="energy":
-    energy_results()

+ 114 - 2
real-life-dataset/run_dataset/transformer/energy_transformation.py

@@ -29,7 +29,7 @@ def insert_energy_pragmas(code, transformation_type, info):
 	for i, line in enumerate(f1):
 		### insert pragma scop in the right place for identifying the loop of interest
 		if i == int(code.line_start)-1:
-			line2 = "FILE *fp_energy = fopen(\"./extract_features/module-power-input.txt\",\"a\");\n"
+			line2 = "FILE *fp_energy = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
 			f2.write(line2)
 			line2 = "if(fp_energy) {\n"
 			f2.write(line2)
@@ -39,6 +39,10 @@ def insert_energy_pragmas(code, transformation_type, info):
 			f2.write(line2)
 			line2 = "fclose(fp_energy);}\n"
 			f2.write(line2)
+			line2 = "int iiii;"
+			f2.write(line2)
+			line2 = "for(iiii=0; iiii<"+info+"; iiii++){\n"
+			f2.write(line2)
 			
 
 		### if there is a pragma from previous transformation in another place remove it
@@ -46,7 +50,11 @@ def insert_energy_pragmas(code, transformation_type, info):
 		#	continue
 
 		if i == int(code.line_end):
-			line2 = "fp_energy = fopen(\"./extract_features/module-power-input.txt\",\"a\");\n"
+
+			line2 = "}\n"
+			f2.write(line2)
+
+			line2 = "fp_energy = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
 			f2.write(line2)
 			line2 = "if(fp_energy) {\n"
 			f2.write(line2)
@@ -65,4 +73,108 @@ def insert_energy_pragmas(code, transformation_type, info):
 
 	f1.close()
 	f2.close()
+	os.system("mv "+new_file+" "+code.source_file)
+
+def insert_energy_GPUdata_pragmas(code, transformation_type, info):
+	f1 = open(code.source_file,"r")
+	new_file = temp_dir+'temp_source'
+	f2 = open(new_file,"wb")
+	for i, line in enumerate(f1):
+		### insert pragma scop in the right place for identifying the loop of interest
+		if i == int(code.line_start)-1:
+			line2 = "FILE *fp_energy"+str(i)+" = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
+			f2.write(line2)
+			line2 = "if(fp_energy"+str(i)+") {\n"
+			f2.write(line2)
+			line2 = "char Buf[7] = \"Start\\n\";\n"
+			f2.write(line2)
+			line2 = "fwrite(Buf, 1, 6, fp_energy"+str(i)+");\n"
+			f2.write(line2)
+			line2 = "fclose(fp_energy"+str(i)+");}\n"
+			f2.write(line2)
+			line2 = "int iiii;"
+			f2.write(line2)
+			line2 = "for(iiii=0; iiii<"+info+"; iiii++){\n"
+			f2.write(line2)
+			
+
+		### if there is a pragma from previous transformation in another place remove it
+		#elif "#pragma scop" in line:
+		#	continue
+
+		if i == int(code.line_end):
+
+			line2 = "}\n"
+			f2.write(line2)
+
+			line2 = "FILE *fp_energy"+str(i)+" = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
+			f2.write(line2)
+			line2 = "if(fp_energy"+str(i)+") {\n"
+			f2.write(line2)
+			line2 = "char Buf[5] = \"End\\n\";\n"
+			f2.write(line2)
+			line2 = "fwrite(Buf, 1, 4, fp_energy"+str(i)+");\n"
+			f2.write(line2)
+			line2 = "fclose(fp_energy"+str(i)+");}\n"
+			f2.write(line2)
+
+
+		### if there is a pragma from previous transformation in another place remove it
+		#elif "#pragma endscop" in line:
+		#	continue
+
+		f2.write(line.replace("\r",""))
+
+	f1.close()
+	f2.close()
+	os.system("mv "+new_file+" "+code.source_file)
+
+	f1 = open(code.source_file,"r")
+	new_file = temp_dir+'temp_source'
+	f2 = open(new_file,"wb")
+	flag = 0
+	for i, line in enumerate(f1):
+		### insert pragma scop in the right place for identifying the loop of interest
+		if 'cudaMemcpy' in line:
+			if flag == 0:
+				line2 = "FILE *fp_energy"+str(i)+" = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
+				f2.write(line2)
+				line2 = "if(fp_energy"+str(i)+") {\n"
+				f2.write(line2)
+				line2 = "char Buf[7] = \"Start\\n\";\n"
+				f2.write(line2)
+				line2 = "fwrite(Buf, 1, 6, fp_energy"+str(i)+");\n"
+				f2.write(line2)
+				line2 = "fclose(fp_energy"+str(i)+");}\n"
+				
+				f2.write(line2)
+				line2 = "int iiii"+str(i)+";"
+				f2.write(line2)
+				line2 = "for(iiii"+str(i)+"=0; iiii"+str(i)+"<"+info+"; iiii"+str(i)+"++){\n"
+				f2.write(line2)
+				f2.write(line.replace("\r",""))
+				flag = 1
+			else:
+				f2.write(line.replace("\r",""))
+		else:
+			if flag==1:
+				line2 = "}\n"
+				f2.write(line2)
+				line2 = "FILE *fp_energy"+str(i)+" = fopen(\"./run_dataset/module-power-input.txt\",\"a\");\n"
+				f2.write(line2)
+				line2 = "if(fp_energy"+str(i)+") {\n"
+				f2.write(line2)
+				line2 = "char Buf[5] = \"End\\n\";\n"
+				f2.write(line2)
+				line2 = "fwrite(Buf, 1, 4, fp_energy"+str(i)+");\n"
+				f2.write(line2)
+				line2 = "fclose(fp_energy"+str(i)+");}\n"
+				f2.write(line2)
+				
+				flag = 0
+			else:
+				f2.write(line.replace("\r",""))
+
+	f1.close()
+	f2.close()
 	os.system("mv "+new_file+" "+code.source_file)