summaryrefslogtreecommitdiffstats
path: root/dis/gen_input.py
blob: 3698e88377d191e87b8e1361d8c90273ad4bee71 (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python3
#####
# Copyright 2020 Joshua Bakita
#
# This program generates input data for the DIS benchmark suite on stdout
# given a requested working set size.
#####


from ctypes import sizeof, c_double, c_int, c_short
from math import sqrt, floor
import sys # For argv and stderr

USAGE = """Usage: {} <benchmark> <template> <WSS in bytes>"""

# Check input
if (len(sys.argv) < 4):
    print(USAGE.format(sys.argv[0]), file=sys.stderr)
    exit(1);

# Don't try to understand the logic in these functions, see WSS_DOCS.md
def setup_field(params, wss):
    params[0] = wss
    return params

def setup_matrix(params, wss):
    nnZR = 0.80 # 8% seems average, but it's too fast to compute. Use 80%.
    si = sizeof(c_int)
    sd = sizeof(c_double)
    # s is size double, i is size int, z in nnZR
    # This formula is out of a solver
    d = (sqrt(sd*sd*(81-4*nnZR) + 4*sd*(wss - si*nnZR + 9*si) - 4) - 9*sd - 2*si) / (2*sd)
    params[1] = floor(d);
    # Make sure that we don't add more elements than the matrix size
    params[2] = floor(d*d*nnZR)
    # Set error as low as possible to slow things down
    params[4] = 1.0e-7
    if params[1] <= 0 or params[2] <= 0:
        raise Exception("WSS too small for matrix benchmark!")
    return params

def setup_neighborhood(params, wss):
    bitDepth = 15
    bitDepthAlloc = sizeof(c_int) * (2**(bitDepth + 1) - 1)
    dim = sqrt((wss - bitDepthAlloc) / sizeof(c_short))
    params[1] = bitDepth
    params[2] = floor(dim)
    if params[1] <= 0 or params[2] <= 0:
        raise Exception("WSS too small for neighborhood benchmark!")
    # Cap maximum line thinkness to the image size
    params[5] = min(params[2]-1, int(params[5]))
    # Cap line lengths to the image size
    params[6] = min(params[2]-1, int(params[6]))
    params[7] = min(params[2]-1, int(params[7]))
    return params

def setup_pointer(params, wss):
    n = 1; # Only use one "thread"
    f = (wss - sizeof(c_int) * 4 * n) / sizeof(c_int)
    params[0] = floor(f)
    params[4] = floor(n)
    if params[0] <= 0 or params[4] <= 0:
        raise Exception("WSS too small for pointer benchmark!")
    return params

def setup_transitive(params, wss):
    n = sqrt(wss / (sizeof(c_int) * 2))
    params[0] = floor(n)
    # Fix edges at 50%
    params[1] = floor(params[0] * 0.5)
    if params[0] <= 0:
        raise Exception("WSS too small for transitive benchmark!")
    return params

def setup_update(params, wss):
    f = wss / sizeof(c_int)
    params[0] = floor(f)
    if params[0] <= 0:
        raise Exception("WSS too small for update benchmark!")
    # Don't do more than 10M hops (keeps time array feasible)
    params[2] = min(10000000, int(params[2]))
    # Enforce size requirements
    params[4] = min(params[0]-1, int(params[4]))
    params[5] = min(params[0]-1, int(params[5]))
    params[6] = min(params[0]-1, int(params[6]))
    return params

def setup_random_walk(params, wss):
    params[0] = wss
    return params

BENCH_TO_PARAMS = {"field":setup_field, "matrix":setup_matrix, "neighborhood":setup_neighborhood, "pointer":setup_pointer, "transitive":setup_transitive, "update":setup_update, "random_walk":setup_random_walk}

# Main logic
benchmark_name = sys.argv[1]
if benchmark_name not in BENCH_TO_PARAMS.keys():
    print("Invalid benchmark name.", file=sys.stderr)
    exit(2)

wss = int(sys.argv[3])
if wss <= 0:
    print("Invalid working set size", file=sys.stderr)
    exit(3)

with open(sys.argv[2], "r") as template:
    # We expect the initialization params to all be on the first line
    params = template.readline().split()
    mutated_params = BENCH_TO_PARAMS[benchmark_name](params, wss);
    print("Using", " ".join(map(lambda x: str(x), mutated_params)), "for", benchmark_name, "stressmark", file=sys.stderr)
    print(" ".join(map(lambda x: str(x), mutated_params)))
    if benchmark_name == "pointer":
        # Clone the data format used in the template
        for i in range(0,10):
            print("10 " + str(mutated_params[0]-10) + " " + str(mutated_params[0]-10))
    else:
        print(template.read())
    
n691' href='#n691'>691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
%PDF-1.3
%Äåòåë§ó ÐÄÆ
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x½ZÙŽ5}ï¯pÂ’ž�ñ´Ý«		�
^ˆt%h4‘@�	ü?Çö©Þ¸KÍèêN"µº¯}ª\uj±»?˜·æƒqÿ­óUåM;ôvLߥËÍ•ùÉüi.žtæò£©Ò¿�—˜SYßTñ/?ï\7X?D„ª³Cqymžm0Ðite6—�‘&ñ²¹6¯œuÆ™Í{SÞ»f6¿c