This repository has been archived by the owner on Dec 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_comp_snps.R
74 lines (67 loc) · 2.34 KB
/
benchmark_comp_snps.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## This script benchmarks MMAGPU against MMA1Bit with both mma and wmma.
# We assume a population with 10k individuals.
library(miraculix)
# Global RFutils options
RFoptions(install="none", centered=FALSE, normalized=FALSE, cores=12, helpinfo=FALSE, la_mode=LA_GPU)
# Number of individuals
n <- 10000
# Number of SNPs
snps <- c(seq(1e3, 9e3, by = 1e3), seq(1e4, 9e4, by = 1e4), seq(1e5, 1e6, by = 1e5))
# Matrices for time measurements
snps_time <- matrix(0, nrow=length(snps), ncol=3)
rownames(snps_time) <- snps
colnames(snps_time) <- c("MMAGPU", "mma-MMA1Bit", "wmma-MMA1Bit")
average_benchmark <- 20
divisor <- 1000
# Iterate over number of SNPs
for(i in 1:length(snps)){
# Simulate subpopulation
SNPs <- matrix(sample(0:2, n/divisor * snps[i], replace=T), ncol=n/divisor)
cat("snpcoding=MMAGPU\n")
# Simulate population
RFoptions(snpcoding=MMAGPU)
Z <- miraculix::genomicmatrix(snps[i], n)
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n/divisor)) + n/divisor * j, SNPs)
}
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
snps_time[i,1] <- snps_time[i,1] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
n_streams = 6, shape = 1, tilesize = 1024
)
})[3]
}
snps_time[i,1] <- snps_time[i,1]/average_benchmark
cat("snpcoding=MMA1Bit, mma version\n")
# Simulate population
RFoptions(snpcoding=MMA1Bit)
Z <- miraculix::genomicmatrix(snps[i], n)
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n/divisor)) + n/divisor * j, SNPs)
}
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
snps_time[i,2] <- snps_time[i,2] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
warp = FALSE, shape = 6, n_streams = 6, tilesize = 1536, naive = TRUE
)
})[3]
}
snps_time[i,2] <- snps_time[i,2]/average_benchmark
cat("snpcoding=MMA1Bit, wmma version\n")
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
snps_time[i,3] <- snps_time[i,3] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
warp = TRUE, shape = 6, n_streams = 6, tilesize = 1024, naive = TRUE
)
})[3]
}
snps_time[i,3] <- snps_time[i,3]/average_benchmark
print(snps[i])
}
saveRDS(snps_time, "snps_time.rds")