iccsa-17-gpulab

Acceleration of Computing and Visualization Processes with OpenCL for Standing Sea Wave Simulation Model
git clone https://git.igankevich.com/iccsa-17-gpulab.git
Log | Files | Refs

common.R (5121B)


      1 load_log_file_as_data_frame <- function (prefix, pattern) {
      2 	runtime <- data.frame()
      3 	dirs <- sort(list.files(prefix))
      4 	rownum <- 1
      5 	run <- 1
      6 	for (d in dirs) {
      7 		files <- sort(list.files(file.path(prefix, d), pattern=pattern))
      8 		for (f in files) {
      9 			lines <- readLines(file.path(prefix, d, f))
     10 			t <- lines[grepl("^prfl.*=.*$", lines, perl=TRUE)]
     11 			routine <- gsub(
     12 				"^prfl\\s+([a-zA-Z0-9_]+).*=\\s*([0-9]+)us$",
     13 				"\\1",
     14 				t,
     15 				perl=TRUE
     16 			)
     17 			t <- gsub(
     18 				"^prfl\\s+([a-zA-Z0-9_]+).*=\\s*([0-9]+)us$",
     19 				"\\2",
     20 				t,
     21 				perl=TRUE
     22 			)
     23 			s <- lines[grepl("^Output grid size", lines, perl=TRUE)]
     24 			s <- gsub(
     25 				"Output grid size\\s*=\\s*\\([0-9]+,([0-9]+),[0-9]+\\)",
     26 				"\\1",
     27 				s,
     28 				perl=TRUE
     29 			)
     30 			s <- as.numeric(s)
     31 			# add new column if needed
     32 			if (!("run" %in% colnames(runtime))) {
     33 				runtime[, "run"] <- rep(NA, nrow(runtime))
     34 			}
     35 			if (!("t" %in% colnames(runtime))) {
     36 				runtime[, "t"] <- rep(NA, nrow(runtime))
     37 			}
     38 			if (!("size" %in% colnames(runtime))) {
     39 				runtime[, "size"] <- rep(NA, nrow(runtime))
     40 			}
     41 			if (!("routine" %in% colnames(runtime))) {
     42 				runtime[, "routine"] <- rep(NA, nrow(runtime))
     43 			}
     44 			# add new row if needed
     45 			for (i in seq(1, length(t))) {
     46 				if (!(rownum %in% rownames(runtime))) {
     47 					runtime[rownum, ] <- rep(NA, ncol(runtime))
     48 				}
     49 				runtime[rownum, "run"] <- run
     50 				runtime[rownum, "t"] <- as.numeric(t[[i]])
     51 				runtime[rownum, "size"] <- s
     52 				runtime[rownum, "routine"] <- routine[[i]]
     53 #				runtime[rownum, ] <- c(as.numeric(t[[i]]), s, routine[[i]])
     54 				rownum <- rownum + 1
     55 			}
     56 			#t <- sum(as.numeric(t))
     57 			#runtime[r, ] <- c(t, s, routine)
     58 			#rownum <- rownum + 1
     59 		}
     60 		run <- run + 1
     61 	}
     62 	runtime
     63 }
     64 
     65 arma.plot_cpu_gpu <- function () {
     66 	data1 <- load_log_file_as_data_frame("data", "^linear.*\\.log$")
     67 	data2 <- load_log_file_as_data_frame("data", "^high_amplitude_realtime.*\\.log$")
     68 	data1 <- aggregate(
     69 		data1$t,
     70 		by=list(run=data1$run, size=data1$size),
     71 		FUN=sum
     72 	)
     73 	names(data1) <- c("run", "size", "t") 
     74 	data2 <- aggregate(
     75 		data2$t,
     76 		by=list(run=data2$run, size=data2$size),
     77 		FUN=sum
     78 	)
     79 	names(data2) <- c("run", "size", "t") 
     80 	#print(data2)
     81 	data1 <- aggregate(
     82 		data1$t*1e-6,
     83 		by=list(size=data1$size),
     84 		FUN=mean
     85 	)
     86 	data2 <- aggregate(
     87 		data2$t*1e-6,
     88 		by=list(size=data2$size),
     89 		FUN=mean
     90 	)
     91 	plot.new()
     92 	plot.window(
     93 		xlim=range(data1$size),
     94 		ylim=range(c(data1$x, data2$x))
     95 	)
     96 	lines(data1$size, data1$x, lty="solid", type="b")
     97 	lines(data2$size, data2$x, lty="dashed", type="b")
     98 	axis(1, at=data1$size, labels=data1$size)
     99 	axis(2)
    100 	title(
    101 		xlab="Wavy surface size",
    102 		ylab="Time, s"
    103 	)
    104 	text(586, 13, "OpenMP", pos=4)
    105 	text(622, 2, "OpenCL", pos=4)
    106 	#legend("top", c("OpenMP", "OpenCL"), lty=c("solid", "dashed"))
    107 	#print(data1)
    108 	#print(data2)
    109 }
    110 
    111 arma.aggregate_dev <- function (data2) {
    112 	dev_to_host_opencl <- data2[data2$routine=="dev_to_host_copy", ] 
    113 	window_function <- data2[data2$routine=="window_function", ] 
    114 	second_function <- data2[data2$routine=="second_function", ] 
    115 	fft <- data2[data2$routine=="fft", ] 
    116 	all_opencl <- data.frame(
    117 		size=dev_to_host_opencl$size,
    118 		t_wnd=window_function$x,
    119 		t_sec=second_function$x,
    120 		t_fft=fft$x,
    121 		t_copy=dev_to_host_opencl$x,
    122 		row.names="size"
    123 	)
    124 	all_opencl
    125 }
    126 
    127 arma.plot_aggregate_dev <- function (all_opencl, ...) {
    128 	args <- list(...)
    129 	if (args$palette == 'gray') {
    130 		bar_colours <- gray.colors(ncol(all_opencl))
    131 	} else if (args$palette == 'spbu') {
    132 		palette <- colorRampPalette(c("#9F2D20", "#A8ADB4"))
    133 		bar_colours <- palette(ncol(all_opencl))
    134 	} else {
    135 		stop(paste("unknown palette: ", args$palette, sep=" "))
    136 	}
    137 	barplot(
    138 		t(as.matrix(all_opencl)),
    139 		ylim=args$ylim,
    140 		axes=FALSE,
    141 		col=bar_colours
    142 	)
    143 	axis(2, at=seq(0, args$ylim[[2]], length.out=6))
    144 	title(
    145 		main=args$title,
    146 		xlab="Wavy surface size",
    147 		ylab="Time, s"
    148 	)
    149 	legend(
    150 		"top",
    151 		args$legend,
    152 		fill=bar_colours
    153 	)
    154 }
    155 
    156 arma.plot_performance_breakdown <- function (palette="gray") {
    157 	data1 <- load_log_file_as_data_frame("data", "^linear.*\\.log$")
    158 	data2 <- load_log_file_as_data_frame("data", "^high_amplitude_realtime.*\\.log$")
    159 	data1 <- aggregate(
    160 		data1$t,
    161 		by=list(run=data1$run, size=data1$size, routine=data1$routine),
    162 		FUN=sum
    163 	)
    164 	names(data1) <- c("run", "size", "routine", "t") 
    165 	data2 <- aggregate(
    166 		data2$t,
    167 		by=list(run=data2$run, size=data2$size, routine=data2$routine),
    168 		FUN=sum
    169 	)
    170 	names(data2) <- c("run", "size", "routine", "t") 
    171 	#print(data2)
    172 	data1 <- aggregate(
    173 		data1$t*1e-6,
    174 		by=list(size=data1$size, routine=data1$routine),
    175 		FUN=mean
    176 	)
    177 	data2 <- aggregate(
    178 		data2$t*1e-6,
    179 		by=list(size=data2$size, routine=data2$routine),
    180 		FUN=mean
    181 	)
    182 	all_openmp <- arma.aggregate_dev(data1)
    183 	all_openmp$t_copy <- NULL
    184 	all_opencl <- arma.aggregate_dev(data2)
    185 	print(all_openmp)
    186 	print(all_opencl)
    187 	par(mfrow=c(1,2))
    188 	arma.plot_aggregate_dev(
    189 		all_opencl,
    190 		ylim=c(0,1),
    191 		title="OpenCL",
    192 		legend=c(expression("g"[1]), expression("g"[2]), "FFT", "Copy"),
    193 		palette=palette
    194 	)
    195 	arma.plot_aggregate_dev(
    196 		all_openmp,
    197 		ylim=c(0,20),
    198 		title="OpenMP",
    199 		legend=c(expression("g"[1]), expression("g"[2]), "FFT"),
    200 		palette=palette
    201 	)
    202 }