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_indivs.R
74 lines (67 loc) · 2.32 KB
/
benchmark_comp_indivs.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 1000k snps.
library(miraculix)
# Global RFutils options
RFoptions(install="none", centered=FALSE, normalized=FALSE, cores=12, helpinfo=FALSE, la_mode=LA_GPU)
# Number of individuals
n <- seq(1000, 10000, by = 1000)
# Number of SNPs
snps <- 1e6
# Matrices for time measurements
indivs_time <- matrix(0, nrow=length(n), ncol=3)
rownames(indivs_time) <- n
colnames(indivs_time) <- c("MMAGPU", "mma-MMA1Bit", "wmma-MMA1Bit")
average_benchmark <- 20
divisor <- 1000
# Iterate over number of SNPs
for(i in 1:length(n)){
# Simulate subpopulation
SNPs <- matrix(sample(0:2, n[i]/divisor * snps, replace=T), ncol=n[i]/divisor)
cat("snpcoding=MMAGPU\n")
# Simulate population
RFoptions(snpcoding=MMAGPU)
Z <- miraculix::genomicmatrix(snps, n[i])
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n[i]/divisor)) + n[i]/divisor * j, SNPs)
}
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
indivs_time[i,1] <- indivs_time[i,1] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
n_streams = 6, shape = 1, tilesize = 1024
)
})[3]
}
indivs_time[i,1] <- indivs_time[i,1]/average_benchmark
cat("snpcoding=MMA1Bit, mma version\n")
# Simulate population
RFoptions(snpcoding=MMA1Bit)
Z <- miraculix::genomicmatrix(snps, n[i])
for (j in 0:(divisor-1)) {
fillGeno(Z, (1:(n[i]/divisor)) + n[i]/divisor * j, SNPs)
}
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
indivs_time[i,2] <- indivs_time[i,2] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
warp = FALSE, shape = 6, n_streams = 6, tilesize = 1536, naive = TRUE
)
})[3]
}
indivs_time[i,2] <- indivs_time[i,2]/average_benchmark
cat("snpcoding=MMA1Bit, wmma version\n")
# Start time measurements
for (j in 1:average_benchmark) {
Sys.sleep(0.1)
indivs_time[i,3] <- indivs_time[i,3] + system.time({ # calculate relationship matrix
G <- miraculix::relationshipMatrix(Z,
warp = TRUE, shape = 6, n_streams = 6, tilesize = 1024, naive = TRUE
)
})[3]
}
indivs_time[i,3] <- indivs_time[i,3]/average_benchmark
print(snps)
}
saveRDS(indivs_time, "indivs_time.rds")