├── AUTHORS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── config ├── run-analyzer.py ├── run-gltrace-sim.sh ├── run-traces.py └── traces.py ├── gltracesim ├── .gitignore ├── Makefile ├── SConstruct ├── conf.rc ├── env.conf ├── gltracesim-analyze ├── gltracesim-generate ├── gltracesim.config ├── gltracesim.creator ├── gltracesim.files ├── gltracesim.includes ├── site_scons │ └── site_tools │ │ └── protoc.py └── src │ ├── SConscript │ ├── analyzer.cc │ ├── analyzer.hh │ ├── analyzer │ ├── SConscript │ ├── core.cc │ ├── core.hh │ ├── cpu.cc │ ├── cpu.hh │ ├── gpu.cc │ ├── gpu.hh │ ├── memory │ │ ├── SConscript │ │ ├── base.cc │ │ ├── base.hh │ │ ├── base_cache.cc │ │ ├── base_cache.hh │ │ ├── base_cache.proto │ │ ├── intel_cache.cc │ │ ├── intel_cache.hh │ │ ├── ls_cache.cc │ │ ├── ls_cache.hh │ │ └── ls_cache.proto │ ├── schedular │ │ ├── SConscript │ │ ├── base.cc │ │ ├── base.hh │ │ ├── fcfs.cc │ │ ├── fcfs.hh │ │ ├── file.cc │ │ ├── file.hh │ │ ├── random.cc │ │ ├── random.hh │ │ ├── schedule.proto │ │ ├── z.cc │ │ └── z.hh │ ├── trace_manager.cc │ └── trace_manager.hh │ ├── debug.cc │ ├── debug.hh │ ├── debug_impl.hh │ ├── device.cc │ ├── device.hh │ ├── frame.cc │ ├── frame.hh │ ├── frame.proto │ ├── gem5 │ ├── SConscript │ ├── packet.proto │ ├── protoio.cc │ ├── protoio.hh │ ├── trace.cc │ └── trace.hh │ ├── generator │ ├── SConscript │ ├── buffer.cc │ ├── buffer.hh │ ├── filter_cache.cc │ ├── filter_cache.hh │ ├── pipeline │ │ ├── SConscript │ │ ├── analysis_queue.cc │ │ ├── analysis_queue.hh │ │ ├── filter_queue.cc │ │ ├── filter_queue.hh │ │ ├── pipeline.cc │ │ └── pipeline.hh │ ├── stop_timer.cc │ └── stop_timer.hh │ ├── gltracesim.proto │ ├── gltracesim_analyzer.cc │ ├── gltracesim_analyzer.hh │ ├── gltracesim_generator.cc │ ├── gltracesim_generator.hh │ ├── job.cc │ ├── job.hh │ ├── job.proto │ ├── opengl.proto │ ├── packet.cc │ ├── packet.hh │ ├── resource.cc │ ├── resource.hh │ ├── resource.proto │ ├── resource_impl.hh │ ├── resource_jpeg.cc │ ├── resource_tracker.cc │ ├── resource_tracker.hh │ ├── resource_tracker_impl.hh │ ├── scene.cc │ ├── scene.hh │ ├── scene.proto │ ├── stats │ ├── SConscript │ ├── cache.cc │ ├── cache.hh │ ├── cache.proto │ ├── cache_impl.hh │ ├── distribution.cc │ ├── distribution.hh │ ├── distribution.proto │ ├── distribution_impl.hh │ ├── histogram.cc │ ├── histogram.hh │ ├── histogram_impl.hh │ ├── variable_distribution.cc │ ├── variable_distribution.hh │ ├── variable_distribution.proto │ ├── variable_distribution_impl.hh │ ├── vector.cc │ ├── vector.hh │ └── vector_impl.hh │ ├── system.cc │ ├── system.hh │ ├── util │ ├── SConscript │ ├── addr_range.hh │ ├── addr_range_map.hh │ ├── cache.hh │ ├── cache_impl.hh │ ├── cflags.hh │ ├── mkdir.hh │ ├── sat_counter.hh │ ├── sat_counter_impl.hh │ ├── threads.cc │ ├── threads.hh │ ├── timer.cc │ └── timer.hh │ ├── vmemory.cc │ └── vmemory.hh ├── tools ├── frame-print.py ├── job-print.py ├── scene-print.py ├── stats-print.py └── stream │ ├── __init__.py │ ├── release.py │ └── stream.py └── traces └── GET_TRACES /AUTHORS: -------------------------------------------------------------------------------- 1 | Andreas Sembrant 2 | German Ceballos 3 | Trevor E. Carlson -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. 16 | 17 | ## Code of Conduct 18 | 19 | ### Our Pledge 20 | 21 | In the interest of fostering an open and welcoming environment, we as 22 | contributors and maintainers pledge to making participation in our project and 23 | our community a harassment-free experience for everyone, regardless of age, body 24 | size, disability, ethnicity, gender identity and expression, level of experience, 25 | nationality, personal appearance, race, religion, or sexual identity and 26 | orientation. 27 | 28 | ### Our Standards 29 | 30 | Examples of behavior that contributes to creating a positive environment 31 | include: 32 | 33 | * Using welcoming and inclusive language 34 | * Being respectful of differing viewpoints and experiences 35 | * Gracefully accepting constructive criticism 36 | * Focusing on what is best for the community 37 | * Showing empathy towards other community members 38 | 39 | Examples of unacceptable behavior by participants include: 40 | 41 | * The use of sexualized language or imagery and unwelcome sexual attention or 42 | advances 43 | * Trolling, insulting/derogatory comments, and personal or political attacks 44 | * Public or private harassment 45 | * Publishing others' private information, such as a physical or electronic 46 | address, without explicit permission 47 | * Other conduct which could reasonably be considered inappropriate in a 48 | professional setting 49 | 50 | ### Our Responsibilities 51 | 52 | Project maintainers are responsible for clarifying the standards of acceptable 53 | behavior and are expected to take appropriate and fair corrective action in 54 | response to any instances of unacceptable behavior. 55 | 56 | Project maintainers have the right and responsibility to remove, edit, or 57 | reject comments, commits, code, wiki edits, issues, and other contributions 58 | that are not aligned to this Code of Conduct, or to ban temporarily or 59 | permanently any contributor for other behaviors that they deem inappropriate, 60 | threatening, offensive, or harmful. 61 | 62 | ### Scope 63 | 64 | This Code of Conduct applies both within project spaces and in public spaces 65 | when an individual is representing the project or its community. Examples of 66 | representing a project or community include using an official project e-mail 67 | address, posting via an official social media account, or acting as an appointed 68 | representative at an online or offline event. Representation of a project may be 69 | further defined and clarified by project maintainers. 70 | 71 | ### Enforcement 72 | 73 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 74 | reported by contacting the project team at german.ceballos@it.uu.se. All 75 | complaints will be reviewed and investigated and will result in a response that 76 | is deemed necessary and appropriate to the circumstances. The project team is 77 | obligated to maintain confidentiality with regard to the reporter of an incident. 78 | Further details of specific enforcement policies may be posted separately. 79 | 80 | Project maintainers who do not follow or enforce the Code of Conduct in good 81 | faith may face temporary or permanent repercussions as determined by other 82 | members of the project's leadership. 83 | 84 | ### Attribution 85 | 86 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 87 | available at [http://contributor-covenant.org/version/1/4][version] 88 | 89 | [homepage]: http://contributor-covenant.org 90 | [version]: http://contributor-covenant.org/version/1/4/ 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Uppsala Architecture Research Team 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /config/run-analyzer.py: -------------------------------------------------------------------------------- 1 | import os, os.path 2 | import traces 3 | 4 | def parse_arguments(): 5 | from argparse import ArgumentParser 6 | 7 | parser = ArgumentParser('Run gltrace-sim.') 8 | option = parser.add_argument 9 | 10 | option("--sbatch", action="store_true", default=False, 11 | help="Enable batch mode") 12 | 13 | option("--pretend", action="store_true", default=False, 14 | help="Just check which traces need to be run again.") 15 | 16 | option("--cluster", 17 | choices=['local', 'your_own_cluster_conf'], 18 | default='local', 19 | help="Cluster") 20 | 21 | option("--filter", 22 | default=None, 23 | help="Filter trace files") 24 | 25 | option("-f", "--force", 26 | action="store_true", 27 | default=False, 28 | help="Run anyway, even if trace result already exists.") 29 | 30 | option("--no-fast-forward", 31 | action="store_true", 32 | default=False, 33 | help="Start from frame 0.") 34 | 35 | option("--no-sim-end", 36 | action="store_true", 37 | default=False, 38 | help="Stop after specified # frames.") 39 | 40 | option("-n", "--num-gpu-cores", 41 | type=int, 42 | default=1, 43 | help="Number of GPU cores.") 44 | 45 | option("-m", "--models-file", 46 | help="Input models files.") 47 | 48 | option("-i", "--input-dir", 49 | default=None, 50 | help="Input folder") 51 | 52 | option("-o", "--output-dir", 53 | default=None, 54 | help="Output folder") 55 | 56 | return parser.parse_known_args() 57 | 58 | args, extra_args = parse_arguments() 59 | 60 | if args.cluster == 'local': 61 | GLTRACE_SIM_HOME='/home/uart/gltracesim/gltracesim/' 62 | elif args.cluster == 'your_own_cluster_conf': 63 | GLTRACE_SIM_HOME='/path/to/gltracesim/' 64 | else: 65 | pass 66 | 67 | os.environ['GLTRACE_SIM_HOME'] = GLTRACE_SIM_HOME 68 | os.environ['PATH'] = os.environ['PATH'] 69 | CMD = 'run-analyzer.sh' 70 | 71 | args.output_dir = os.path.abspath(args.output_dir) 72 | 73 | num_jobs = 0 74 | 75 | for t in traces.traces: 76 | 77 | out_dir = os.path.join(args.output_dir, t.name) 78 | 79 | os.environ['OUT_DIR'] = out_dir 80 | 81 | if args.filter and args.filter not in t.name: 82 | print 'Skipping %s' % (t.name) 83 | continue 84 | 85 | print 'Simulating trace %s' % (t.name) 86 | 87 | sbatch = 'sbatch --job-name %s --workdir %s -o %s -e %s' % ( 88 | out_dir, 89 | out_dir, 90 | os.path.join(out_dir, 'slurm.out'), 91 | os.path.join(out_dir, 'slurm.out') 92 | ) 93 | 94 | stat_file = os.path.join(out_dir, 'frame_stats.pb') 95 | 96 | if not os.path.exists(stat_file): 97 | pass 98 | elif os.path.getsize(stat_file) == 0: 99 | print 'stats.txt empty, simulating trace' 100 | elif os.path.getsize(stat_file) > 0: 101 | if args.force: 102 | print 'stats.txt exists, re-simulating' 103 | else: 104 | print 'stats.txt exists, skipping' 105 | continue 106 | 107 | if args.pretend: 108 | continue 109 | 110 | if not os.path.exists(out_dir): 111 | os.makedirs(out_dir) 112 | 113 | os.environ['GLTRACE_SIM_BIN'] = 'gltracesim-analyze' 114 | 115 | os.environ['INPUT_DIR'] = os.path.abspath( 116 | os.path.join(args.input_dir, t.name) 117 | ) 118 | 119 | os.environ['MODELS_FILE'] = os.path.abspath(args.models_file) 120 | 121 | os.environ['NUM_GPU_CORES'] = str(args.num_gpu_cores) 122 | 123 | if args.no_fast_forward: 124 | os.environ['F'] = '0' 125 | else: 126 | os.environ['F'] = str(t.fast_forward) 127 | 128 | if args.no_sim_end: 129 | os.environ['W'] = '0' 130 | else: 131 | os.environ['W'] = str(t.sim_end) 132 | 133 | 134 | os.system('%s %s' % ( 135 | '/bin/bash' if not args.sbatch else sbatch, 136 | CMD 137 | ) 138 | ) 139 | 140 | num_jobs += 1 141 | 142 | print "Submitted %d jobs." % (num_jobs) 143 | -------------------------------------------------------------------------------- /config/run-gltrace-sim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #SBATCH -A project_name 4 | #SBATCH -n 16 5 | #SBATCH -t 3-0:00:00 6 | #SBATCH --mail-type=FAIL 7 | #SBATCH --mem=3G 8 | 9 | source /etc/profile 10 | source ${HOME}/local/conf.rc 11 | source ${GLTRACE_SIM_HOME}/ext/conf.rc 12 | 13 | echo "$(date): Simulation started." 14 | 15 | ${XVFB_RUN} -s "${XVFB_ARGS}" ${XVFB_RUN_ARGS} \ 16 | ${GLTRACE_SIM_HOME}/${GLTRACE_SIM_BIN} --pin-flags='-ifeellucky'\ 17 | -i ${TRACE_FILE} -o ${OUT_DIR} --num-analysis-threads 1 --stop-time 169200 \ 18 | -f ${F} -w ${W} -n 16 -d Init,GpuFrameEvent 19 | 20 | echo "$(date): Simulation completed." -------------------------------------------------------------------------------- /config/run-traces.py: -------------------------------------------------------------------------------- 1 | import os, os.path 2 | import traces 3 | 4 | def parse_arguments(): 5 | from argparse import ArgumentParser 6 | 7 | parser = ArgumentParser('Run gltrace-sim.') 8 | option = parser.add_argument 9 | 10 | option("--sbatch", action="store_true", default=False, 11 | help="Enable batch mode") 12 | 13 | option("--pretend", action="store_true", default=False, 14 | help="Just check which traces need to be run again.") 15 | 16 | option("--cluster", 17 | choices=['local', 'your_own_cluster_conf'], 18 | default='local', 19 | help="Cluster") 20 | 21 | option("--filter", default=None, 22 | help="Filter trace files") 23 | 24 | option("-f", "--force", action="store_true", default=False, 25 | help="Run anyway, even if trace result already exists.") 26 | 27 | option("--no-fast-forward", action="store_true", default=False, 28 | help="Start from frame 0.") 29 | 30 | option("-o", "--output-dir", default=None, 31 | help="Output folder") 32 | 33 | return parser.parse_known_args() 34 | 35 | args, gem5_args = parse_arguments() 36 | 37 | if args.cluster == 'local': 38 | GLTRACE_SIM_HOME='/home/uart/gltracesim/gltracesim/' 39 | os.environ['PIN_HOME'] = GLTRACE_SIM_HOME + 'ext/pin-2.14-71313-gcc.4.4.7-linux/' 40 | os.environ['APITRACE_HOME'] = GLTRACE_SIM_HOME + 'ext/apitrace/build' 41 | os.environ['LD_LIBRARY_PATH'] = GLTRACE_SIM_HOME + 'ext/mesa/build/linux-x86_64/gallium/targets/libgl-xlib/' 42 | TRACE_DIR= GLTRACE_SIM_HOME + '../traces/' 43 | elif args.cluster == 'your_own_cluster_conf': 44 | GLTRACE_SIM_HOME='/path/to/gltracesim' 45 | else: 46 | pass 47 | 48 | os.environ['GLTRACE_SIM_HOME'] = GLTRACE_SIM_HOME 49 | os.environ['PATH'] = os.environ['PATH'] 50 | CMD = 'run-gltrace-sim.sh' 51 | 52 | args.output_dir = os.path.abspath(args.output_dir) 53 | 54 | # 55 | if os.path.exists('.display'): 56 | display_nbr_file = open('.display', 'r+') 57 | else: 58 | display_nbr_file = open('.display', 'w+') 59 | 60 | num_jobs = 0 61 | 62 | for t in traces.traces: 63 | 64 | out_dir = os.path.join(args.output_dir, t.name) 65 | 66 | os.environ['OUT_DIR'] = out_dir 67 | 68 | if args.filter and args.filter not in t.name: 69 | print 'Skipping %s' % (t.name) 70 | continue 71 | 72 | print 'Simulating trace %s' % (t.name) 73 | 74 | sbatch = 'sbatch --job-name %s --workdir %s -o %s -e %s' % ( 75 | t.name, 76 | out_dir, 77 | os.path.join(out_dir, 'slurm.out'), 78 | os.path.join(out_dir, 'slurm.out') 79 | ) 80 | 81 | stat_file = os.path.join(out_dir, 'frame_stats.pb') 82 | 83 | if not os.path.exists(stat_file): 84 | pass 85 | elif os.path.getsize(stat_file) == 0: 86 | print 'stats.txt empty, simulating trace' 87 | elif os.path.getsize(stat_file) > 0: 88 | if args.force: 89 | print 'stats.txt exists, re-simulating' 90 | else: 91 | print 'stats.txt exists, skipping' 92 | continue 93 | 94 | if args.pretend: 95 | continue 96 | 97 | if not os.path.exists(out_dir): 98 | os.makedirs(out_dir) 99 | 100 | # Try do read display number 101 | try: 102 | display_nbr_file.seek(0) 103 | display_nbr = int(display_nbr_file.next()) + 1 104 | except: 105 | display_nbr = 100 106 | 107 | if t.trace: 108 | os.environ['GLTRACE_SIM_BIN'] = 'gltracesim-analyze' 109 | else: 110 | os.environ['GLTRACE_SIM_BIN'] = 'gltracesim-generate' 111 | 112 | os.environ['XVFB_RUN'] = 'xvfb-run' 113 | os.environ['XVFB_ARGS'] = '-screen 0 1920x1200x24+32 +extension GLX +render' 114 | os.environ['XVFB_RUN_ARGS'] = '-n %i -a -e %s' % ( 115 | display_nbr, os.path.join(out_dir, 'xvfb.err') 116 | ) 117 | 118 | os.environ['TRACE_FILE'] = os.path.join(TRACE_DIR, t.input) 119 | if args.no_fast_forward: 120 | os.environ['F'] = '0' 121 | os.environ['W'] = '1000000' 122 | else: 123 | os.environ['F'] = str(t.fast_forward) 124 | os.environ['W'] = str(t.fast_forward + t.sim_window) 125 | 126 | 127 | os.system('%s %s' % ( 128 | '/bin/bash' if not args.sbatch else sbatch, 129 | CMD 130 | ) 131 | ) 132 | 133 | # Update global display number 134 | display_nbr_file.seek(0) 135 | display_nbr_file.write('%i\n' % display_nbr) 136 | 137 | num_jobs += 1 138 | 139 | print "Submitted %d jobs." % (num_jobs) 140 | -------------------------------------------------------------------------------- /config/traces.py: -------------------------------------------------------------------------------- 1 | class Trace: 2 | def __init__(self, name, input = None, fast_forward = 0, sim_end = 1E6, trace=False): 3 | self.name = name 4 | self.input = input 5 | self.fast_forward = fast_forward 6 | self.sim_end = sim_end 7 | self.trace = trace 8 | 9 | traces = [ 10 | Trace( 11 | name="telemetry_youtube", 12 | input="youtube.gltrace", 13 | fast_forward=0, 14 | sim_end=177 15 | ), 16 | Trace( 17 | name="telemetry_wikipedia", 18 | input="wikipedia.gltrace", 19 | fast_forward=0, 20 | sim_end=378 21 | ), 22 | Trace( 23 | name="telemetry_twitter", 24 | input="twitter.gltrace", 25 | fast_forward=0, 26 | sim_end=286 27 | ), 28 | Trace( 29 | name="telemetry_techcrunch", 30 | input="techcrunch.gltrace", 31 | fast_forward=0, 32 | sim_end=488 33 | ), 34 | Trace( 35 | name="telemetry_sports_yahoo", 36 | input="sports_yahoo.gltrace", 37 | fast_forward=0, 38 | sim_end=398 39 | ), 40 | Trace( 41 | name="telemetry_reddit", 42 | input="reddit.gltrace", 43 | fast_forward=0, 44 | sim_end=165 45 | ), 46 | Trace( 47 | name="telemetry_news_yahoo", 48 | input="news_yahoo.gltrace", 49 | fast_forward=0, 50 | sim_end=229 51 | ), 52 | Trace( 53 | name="telemetry_google", 54 | input="google.gltrace", 55 | fast_forward=0, 56 | sim_end=165 57 | ), 58 | Trace( 59 | name="telemetry_facebook", 60 | input="facebook.gltrace", 61 | fast_forward=0, 62 | sim_end=237 63 | ), 64 | Trace( 65 | name="telemetry_ebay", 66 | input="ebay.gltrace", 67 | fast_forward=0, 68 | sim_end=276 69 | ), 70 | Trace( 71 | name="telemetry_cnn", 72 | input="cnn.gltrace", 73 | fast_forward=0, 74 | sim_end=455 75 | ), 76 | Trace( 77 | name="telemetry_booking", 78 | input="booking.gltrace", 79 | fast_forward=0, 80 | sim_end=417 81 | ), 82 | Trace( 83 | name="telemetry_answers_yahoo", 84 | input="answers_yahoo.gltrace", 85 | fast_forward=0, 86 | sim_end=195 87 | ), 88 | Trace( 89 | name="telemetry_amazon", 90 | input="amazon.gltrace", 91 | fast_forward=0, 92 | sim_end=309 93 | ), 94 | Trace( 95 | name="ue4_tappy_chicken", 96 | input="ue4-tappy-chicken.gltrace", 97 | fast_forward=20, 98 | sim_end=5000 99 | ), 100 | Trace( 101 | name="pts_tesseract_1.1.0_1920x1200", 102 | input="pts-tesseract-1.1.0-1920x1200.gltrace", 103 | fast_forward=410, 104 | sim_end=906 105 | ), 106 | Trace( 107 | name="pts_unigine_heaven_1.6.2_1920x1200", 108 | input="pts-unigine-heaven-1.6.2-1920x1200.gltrace", 109 | fast_forward=110, 110 | sim_end=161 111 | ), 112 | Trace( 113 | name="pts_unigine_valley_1.1.4_1920x1200", 114 | input="pts-unigine-valley-1.1.4-1920x1200.gltrace", 115 | fast_forward=110, 116 | sim_end=163 117 | ), 118 | Trace( 119 | name="pts_openarena_1.5.3_1920x1200", 120 | input="pts-openarena-1.5.3-1920x1200.gltrace", 121 | fast_forward=45, 122 | sim_end=1148 123 | ), 124 | Trace( 125 | name="pts_xonotic_1.4.0_1920x1200_LD", 126 | input="pts-xonotic-1.4.0-1920x1200-Low.gltrace", 127 | fast_forward=65, 128 | sim_end=3475 129 | ), 130 | Trace( 131 | name="pts_xonotic_1.4.0_1920x1200_UD", 132 | input="pts-xonotic-1.4.0-1920x1200-Ultimate.gltrace", 133 | fast_forward=65, 134 | sim_end=1116 135 | ), 136 | Trace( 137 | name="gfxbench_manhattan_1920x1200", 138 | input="gfxbench-manhattan-1920x1200.gltrace", 139 | fast_forward=0, 140 | sim_end=1079 141 | ), 142 | Trace( 143 | name="gfxbench_trex_1920x1200", 144 | input="gfxbench-trex-1920x1200.gltrace", 145 | fast_forward=0, 146 | sim_end=1507 147 | ), 148 | ] 149 | 150 | -------------------------------------------------------------------------------- /gltracesim/.gitignore: -------------------------------------------------------------------------------- 1 | .pbtmp* 2 | *.pyc 3 | build/ 4 | ext/ 5 | -------------------------------------------------------------------------------- /gltracesim/Makefile: -------------------------------------------------------------------------------- 1 | PIN_HOME:=ext/pin-2.14-71313-gcc.4.4.7-linux 2 | MESA_HOME:=ext/mesa 3 | PROTO_HOME:=ext/protobuf/install 4 | PROTOC:=$(PROTO_HOME)/bin/protoc 5 | 6 | _CXXFLAGS=-std=c++11 -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -g \ 7 | -Wno-unknown-pragmas -fno-stack-protector -DTARGET_IA32E \ 8 | -DHOST_IA32E -fPIC -DTARGET_LINUX -O3 -fomit-frame-pointer \ 9 | -fno-strict-aliasing \ 10 | -I$(PIN_HOME)/source/include/pin \ 11 | -I$(PIN_HOME)/source/include/pin/gen \ 12 | -I$(PIN_HOME)/extras/components/include \ 13 | -I$(PIN_HOME)/extras/xed-intel64/include \ 14 | -I$(MESA_HOME)/include/ \ 15 | -I$(MESA_HOME)/src/ \ 16 | -I$(MESA_HOME)/src/gallium/include/ \ 17 | -I$(MESA_HOME)/src/gallium/auxiliary/ \ 18 | -I$(PROTO_HOME)/include/ \ 19 | -Isrc/ -I. $(CXXFLAGS) 20 | 21 | 22 | _LDFLAGS=-shared -Wl,--hash-style=sysv -Wl,-Bsymbolic \ 23 | -Wl,--version-script=$(PIN_HOME)/source/include/pin/pintool.ver \ 24 | -L$(PIN_HOME)/intel64/lib \ 25 | -L$(PIN_HOME)/intel64/lib-ext \ 26 | -L$(PIN_HOME)/intel64/runtime/glibc \ 27 | -L$(PIN_HOME)/extras/xed-intel64/lib \ 28 | -L$(PROTO_HOME)/lib/ \ 29 | -lpin -lxed -lpindwarf -ldl -lprotobuf -ljsoncpp 30 | 31 | all: obj-intel64/gltrace_sim.so src/gltrace_sim_pb2.py 32 | 33 | obj-intel64/%.o: src/%.cpp 34 | g++ $(_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< 35 | 36 | obj-intel64/%.o: src/%.cc 37 | g++ $(_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< 38 | 39 | src/gltrace_sim.pb.cc: src/gltrace_sim.proto 40 | $(PROTOC) --cpp_out ./ $< 41 | 42 | src/gltrace_sim_pb2.py: src/gltrace_sim.proto 43 | $(PROTOC) --python_out ./ $< 44 | 45 | obj-intel64/gltrace_sim.so: obj-intel64/gltrace_sim.pb.o obj-intel64/gltrace_sim.o obj-intel64/resource.o obj-intel64/cache.o 46 | g++ -o $@ $^ $(_LDFLAGS) $(LDFLAGS) 47 | 48 | clean: 49 | rm obj-intel64/*.o 50 | rm obj-intel64/*.so 51 | rm src/*.pb.* 52 | -------------------------------------------------------------------------------- /gltracesim/conf.rc: -------------------------------------------------------------------------------- 1 | # Set up your base path here 2 | BASE=/home/uart/gltracesim/gltracesim/ext 3 | BASE_LOCAL=$BASE/local 4 | 5 | export PYTHONPATH=$BASE_LOCAL/lib/python2.7/site-packages/:$PYTHONPATH 6 | export CPATH=$BASE_LOCAL/include/:$BASE_LOCAL/usr/include/:$CPATH 7 | export PATH=$BASE_LOCAL/bin/:$PATH 8 | export LD_LIBRARY_PATH=$BASE_LOCAL/../mesa/build/linux-x86_64/gallium/targets/libgl-xlib/:$BASE_LOCAL/lib/:$BASE_LOCAL/usr/lib64/:/usr/lib64/:/usr/lib/:/usr/local/lib:$LD_LIBRARY_PATH 9 | export LIBRARY_PATH=$BASE_LOCAL/lib/:$BASE_LOCAL/usr/lib64/:/usr/local/lib:/usr/lib:$LIBRARY_PATH 10 | export PKG_CONFIG_PATH=$BASE_LOCAL/lib/pkgconfig:$BASE_LOCAL/usr/lib64/pkgconfig:$BASE_LOCAL/share/pkgconfig/:$PKG_CONFIG_PATH 11 | 12 | LOCAL_ROOT=$BASE 13 | 14 | export PYTHONPATH="${LOCAL_ROOT}/protobuf/python:${PYTHONPATH}" 15 | export LD_LIBRARY_PATH="${LOCAL_ROOT}/protobuf/src/.libs:${LD_LIBRARY_PATH}" 16 | 17 | # Force the use of the CPP extension 18 | export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp 19 | export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2 20 | # Add the CPP extension to the PYTHONPATH 21 | export PYTHONPATH="${LOCAL_ROOT}/protobuf/python/build/lib.linux-x86_64-2.7:${PYTHONPATH}" 22 | 23 | # Compiling with this protobuf implementation 24 | export CFLAGS="-pthread -I$BASE_LOCAL/include" 25 | export LDFLAGS="-pthread -L$BASE_LOCAL/lib -lprotobuf -lpthreads" 26 | -------------------------------------------------------------------------------- /gltracesim/env.conf: -------------------------------------------------------------------------------- 1 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/uart/gltracesim/gltracesim/ext/mesa/build/linux-x86_64-debug/gallium/targets/libgl-xlib/ 2 | export DISPLAY=:0 3 | export LIBGL_ALWAYS_SOFTWARE=1 4 | export GALLIUM_DRIVER=llvmpipe 5 | export LP_NUM_THREADS=4 6 | -------------------------------------------------------------------------------- /gltracesim/gltracesim.config: -------------------------------------------------------------------------------- 1 | // ADD PREDEFINED MACROS HERE! 2 | -------------------------------------------------------------------------------- /gltracesim/gltracesim.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /gltracesim/gltracesim.files: -------------------------------------------------------------------------------- 1 | src/addr_range.hpp 2 | src/addr_range_map.hpp 3 | src/filter_cache.hh 4 | src/gltracesim_generator.cc 5 | src/resource.cc 6 | src/resource.hh 7 | src/gltracesim.proto 8 | src/pipeline.hpp 9 | src/analyzer.hh 10 | src/analyzer/vanilla_cache.cc 11 | src/analyzer/vanilla_cache.hh 12 | src/analyzer.cc 13 | SConstruct 14 | src/SConscript 15 | src/analyzer/SConscript 16 | src/util/addr_range_map.hh 17 | src/util/addr_range.hh 18 | src/util/SConscript 19 | src/pipeline/analysis_queue.hh 20 | src/pipeline/filter_queue.hh 21 | src/pipeline/pipeline.hh 22 | src/pipeline/SConscript 23 | src/pipeline/analysis_queue.cc 24 | src/pipeline/analysis_queue.hpp 25 | src/pipeline/buffer_manager.hpp 26 | src/pipeline/filter_queue.cc 27 | src/pipeline/filter_queue.hpp 28 | src/pipeline/pipeline.cc 29 | src/pipeline/pipeline.hpp 30 | src/pipeline/SConscript 31 | src/pipeline/buffer.hh 32 | src/gltracesim_generator.hh 33 | src/resource_tracker.cc 34 | src/resource_tracker.hh 35 | src/resource_impl.hh 36 | src/resource_tracker_impl.hh 37 | src/util/cache_impl.hh 38 | src/util/cache.hh 39 | src/analyzer/vanilla_cache.proto 40 | src/stats/cache_impl.hh 41 | src/stats/cache.hh 42 | src/stats/histogram_impl.hh 43 | src/stats/histogram.cc 44 | src/stats/histogram.hh 45 | src/stats/SConscript 46 | src/stats/cache_impl.hh 47 | src/stats/cache.hh 48 | src/stats/distribution_impl.hh 49 | src/stats/distribution.cc 50 | src/stats/distribution.hh 51 | src/stats/histogram_impl.hh 52 | src/stats/histogram.cc 53 | src/stats/histogram.hh 54 | src/stats/SConscript 55 | src/stats/cache.cc 56 | src/stats/cache_impl.hh 57 | src/stats/cache.cc 58 | src/stats/cache.hh 59 | src/stats/distribution_impl.hh 60 | src/stats/distribution.cc 61 | src/stats/distribution.hh 62 | src/stats/histogram_impl.hh 63 | src/stats/histogram.cc 64 | src/stats/histogram.hh 65 | src/stats/SConscript 66 | src/stats/vector_impl.hh 67 | src/stats/vector.cc 68 | src/stats/vector.hh 69 | src/stats/cache_impl.hh 70 | src/stats/cache.cc 71 | src/stats/cache.hh 72 | src/stats/cache.proto 73 | src/stats/distribution_impl.hh 74 | src/stats/distribution.cc 75 | src/stats/distribution.hh 76 | src/stats/distribution.proto 77 | src/stats/histogram_impl.hh 78 | src/stats/histogram.cc 79 | src/stats/histogram.hh 80 | src/stats/SConscript 81 | src/stats/vector_impl.hh 82 | src/stats/vector.cc 83 | src/stats/vector.hh 84 | src/debug.hh 85 | src/debug.cc 86 | src/debug_impl.hh 87 | src/stats/variable_distribution_impl.hh 88 | src/stats/variable_distribution.cc 89 | src/stats/variable_distribution.hh 90 | src/stats/variable_distribution.proto 91 | src/analyzer/SConscript 92 | src/resource.proto 93 | src/util/threads.hh 94 | src/util/threads.cc 95 | src/util/stop_timer.hh 96 | src/util/stop_timer.cc 97 | SConstruct 98 | src/gem5/trace.cc 99 | src/gem5/trace.hh 100 | src/vmemory.cc 101 | src/vmemory.hh 102 | src/gltracesim_analyzer.hh 103 | src/gltracesim_analyzer.cc 104 | src/gem5/packet.proto 105 | src/gem5/SConscript 106 | src/gem5/protoio.hh 107 | src/gem5/protoio.cc 108 | src/system.cc 109 | src/system.hh 110 | src/buffer.hh 111 | src/packet.hh 112 | src/packet.cc 113 | gltracesim-generate 114 | gltracesim-analyze 115 | src/device.cc 116 | src/device.hh 117 | gltracesim-analyze 118 | src/util/cflags.hh 119 | src/job.proto 120 | src/job.hh 121 | src/job.cc 122 | src/generator/buffer.cc 123 | src/generator/buffer.hh 124 | src/generator/stop_timer.cc 125 | src/generator/stop_timer.hh 126 | src/generator/threads.cc 127 | src/generator/threads.hh 128 | src/generator/pipeline/analysis_queue.cc 129 | src/generator/pipeline/analysis_queue.hh 130 | src/generator/pipeline/filter_queue.cc 131 | src/generator/pipeline/filter_queue.hh 132 | src/generator/pipeline/pipeline.cc 133 | src/generator/pipeline/pipeline.hh 134 | src/generator/pipeline/SConscript 135 | src/generator/SConscript 136 | src/util/mkdir.hh 137 | src/resource_jpeg.cc 138 | src/scene.cc 139 | src/scene.hh 140 | src/scene.proto 141 | src/frame.cc 142 | src/frame.hh 143 | src/frame.proto 144 | src/util/timer.hh 145 | src/util/timer.cc 146 | src/opengl.proto 147 | src/analyzer/cpu.cc 148 | src/analyzer/cpu.hh 149 | src/analyzer/gpu.cc 150 | src/analyzer/gpu.hh 151 | src/analyzer/SConscript 152 | src/analyzer/schedular/base.hh 153 | src/analyzer/schedular/fcfs.cc 154 | src/analyzer/schedular/fcfs.hh 155 | src/analyzer/schedular/SConscript 156 | src/analyzer/memory/base.hh 157 | src/analyzer/memory/SConscript 158 | src/analyzer/memory/base_cache.cc 159 | src/analyzer/memory/base_cache.hh 160 | src/analyzer/memory/base_cache.proto 161 | src/analyzer/trace_manager.cc 162 | src/analyzer/trace_manager.hh 163 | src/analyzer/schedular/base.cc 164 | src/analyzer/core.cc 165 | src/analyzer/core.hh 166 | src/analyzer/schedular/z.cc 167 | src/analyzer/schedular/z.hh 168 | src/analyzer/schedular/random.cc 169 | src/analyzer/schedular/random.hh 170 | src/analyzer/schedular/file.cc 171 | src/analyzer/schedular/file.hh 172 | src/analyzer/memory/intel_cache.cc 173 | src/analyzer/memory/intel_cache.hh 174 | src/analyzer/schedular/schedule.proto 175 | src/analyzer/memory/base.cc 176 | src/analyzer/memory/ls_cache.cc 177 | src/analyzer/memory/ls_cache.hh 178 | src/analyzer/memory/ls_cache.proto 179 | -------------------------------------------------------------------------------- /gltracesim/gltracesim.includes: -------------------------------------------------------------------------------- 1 | src/ 2 | . 3 | src/util 4 | ext/mesa/src/ 5 | src/gem5 6 | src/generator 7 | src/generator/pipeline 8 | proto/ 9 | src/analyzer 10 | src/analyzer/schedular 11 | src/analyzer/model 12 | src/analyzer/memory 13 | -------------------------------------------------------------------------------- /gltracesim/src/SConscript: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | # 4 | Import('simulator') 5 | Import('analyzer') 6 | 7 | _env = {} 8 | 9 | # 10 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 11 | 'job.cc', 12 | 'debug.cc', 13 | 'frame.cc', 14 | 'scene.cc', 15 | 'device.cc', 16 | 'system.cc', 17 | 'analyzer.cc', 18 | 'packet.cc', 19 | 'vmemory.cc', 20 | 'resource.cc', 21 | 'resource_jpeg.cc', 22 | 'resource_tracker.cc', 23 | 'gltracesim_generator.cc', 24 | ]]) 25 | 26 | # 27 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 28 | 'job.cc', 29 | 'debug.cc', 30 | 'frame.cc', 31 | 'scene.cc', 32 | 'device.cc', 33 | 'system.cc', 34 | 'analyzer.cc', 35 | 'packet.cc', 36 | 'vmemory.cc', 37 | 'resource.cc', 38 | 'resource_jpeg.cc', 39 | 'resource_tracker.cc', 40 | 'gltracesim_analyzer.cc', 41 | ]]) 42 | 43 | PROTO_SOURCES = [ 44 | 'opengl.proto', 45 | 'job.proto', 46 | 'scene.proto', 47 | 'frame.proto', 48 | 'resource.proto', 49 | 'gltracesim.proto' 50 | ] 51 | 52 | _env['proto'] = [ 53 | simulator.File(x) for x in PROTO_SOURCES 54 | ] 55 | 56 | # 57 | Return('_env') 58 | 59 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "analyzer.hh" 4 | #include "debug_impl.hh" 5 | 6 | namespace gltracesim { 7 | 8 | AnalyzerBuilder::AnalyzerBuilder(const std::string &name) : name(name) 9 | { 10 | Analyzer::register_builder(name, this); 11 | } 12 | 13 | AnalyzerBuilder::~AnalyzerBuilder() 14 | { 15 | // Do nothing 16 | } 17 | 18 | const std::string& 19 | AnalyzerBuilder::get_name() const 20 | { 21 | return name; 22 | } 23 | 24 | bool 25 | AnalyzerBuilder::can_create(const std::string &name) const 26 | { 27 | return (this->name == name); 28 | } 29 | 30 | Analyzer::builder_map_t& 31 | Analyzer::builders() 32 | { 33 | // Global map of all builders. 34 | static builder_map_t builders; 35 | 36 | // 37 | return builders; 38 | } 39 | 40 | AnalyzerBuilder* 41 | Analyzer::find_builder(const std::string &name) 42 | { 43 | if (Analyzer::builders().count(name) == 0) { 44 | return NULL; 45 | } 46 | 47 | return Analyzer::builders()[name]; 48 | } 49 | 50 | void 51 | Analyzer::register_builder(const std::string &name, AnalyzerBuilder* builder) 52 | { 53 | builders()[name] = builder; 54 | } 55 | 56 | void 57 | Analyzer::dprint_builders() 58 | { 59 | for (auto &it: Analyzer::builders()) { 60 | DPRINTF(Init, "AnalyzerBuilder: %s -> %p.\n", 61 | it.first.c_str(), (void*) it.second 62 | ); 63 | } 64 | } 65 | 66 | 67 | Analyzer::Analyzer(const Json::Value &p, int id) : id(id), params(p) 68 | { 69 | 70 | } 71 | 72 | Analyzer::~Analyzer() 73 | { 74 | 75 | } 76 | 77 | void 78 | Analyzer::dump_stats() 79 | { 80 | // Do nothing 81 | } 82 | 83 | void 84 | Analyzer::reset_stats() 85 | { 86 | // Do nothing 87 | } 88 | 89 | void 90 | Analyzer::add_child_analyzer(Analyzer* analyzer) 91 | { 92 | // 93 | child_analyzers.push_back(analyzer); 94 | } 95 | 96 | } // end namespace gltracesim 97 | 98 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_MODEL_HH__ 2 | #define __GLTRACESIM_MODEL_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "packet.hh" 10 | #include "gltracesim.pb.h" 11 | 12 | #include "gem5/protoio.hh" 13 | 14 | namespace gltracesim { 15 | 16 | class Analyzer; 17 | 18 | /** 19 | * @brief 20 | */ 21 | typedef std::shared_ptr AnalyzerPtr; 22 | 23 | /** 24 | * @brief The AnalyzerBuilder class 25 | */ 26 | class AnalyzerBuilder 27 | { 28 | 29 | public: 30 | 31 | /** 32 | * @brief AnalyzerBuilder 33 | * @param name 34 | */ 35 | AnalyzerBuilder(const std::string &name); 36 | 37 | /** 38 | * @brief AnalyzerBuilder 39 | * @param name 40 | */ 41 | virtual ~AnalyzerBuilder(); 42 | 43 | public: 44 | 45 | /** 46 | * @brief get_name 47 | * @return 48 | */ 49 | const std::string& get_name() const; 50 | 51 | /** 52 | * @brief can_create 53 | * @param params 54 | */ 55 | virtual bool can_create(const std::string &name) const; 56 | 57 | /** 58 | * @brief create 59 | * @param params 60 | * @return 61 | */ 62 | virtual AnalyzerPtr create(const Json::Value ¶ms) = 0; 63 | 64 | protected: 65 | 66 | /** 67 | * @brief name 68 | */ 69 | std::string name; 70 | }; 71 | 72 | class Analyzer 73 | { 74 | 75 | public: 76 | 77 | /** 78 | * @brief Analyzer 79 | */ 80 | Analyzer(const Json::Value &p, int id); 81 | 82 | /** 83 | * @brief ~Analyzer 84 | */ 85 | virtual ~Analyzer(); 86 | 87 | /** 88 | * @brief process 89 | * @param pkt 90 | */ 91 | virtual void process(const packet_t &pkt) = 0; 92 | 93 | /** 94 | * @brief start_new_frame 95 | */ 96 | virtual void start_new_frame(int frame_id) = 0; 97 | 98 | /** 99 | * @brief start_new_scene 100 | */ 101 | virtual void start_new_scene(int frame_id, int scene_id) = 0; 102 | 103 | /** 104 | * @brief process 105 | * @param buffer 106 | */ 107 | virtual void dump_stats(); 108 | 109 | /** 110 | * @brief process 111 | * @param buffer 112 | */ 113 | virtual void reset_stats(); 114 | 115 | /** 116 | * @brief get_aid 117 | * @return 118 | */ 119 | int get_id() const { 120 | return id; 121 | } 122 | 123 | /** 124 | * @brief add_child_analyzer 125 | */ 126 | void add_child_analyzer(Analyzer*); 127 | 128 | protected: 129 | 130 | /** 131 | * @brief send_packet 132 | * @param pkt 133 | */ 134 | void send_packet(const packet_t &pkt) 135 | { 136 | for (auto &analyzer: child_analyzers) 137 | { 138 | // 139 | analyzer->process(pkt); 140 | } 141 | } 142 | 143 | protected: 144 | 145 | /** 146 | * @brief id 147 | */ 148 | int id; 149 | 150 | /** 151 | * @brief params 152 | */ 153 | Json::Value params; 154 | 155 | /** 156 | * @brief mem_side_analyzers 157 | */ 158 | std::vector child_analyzers; 159 | 160 | public: 161 | 162 | /** 163 | * @brief find_builder 164 | * @param analyzer 165 | * @return 166 | */ 167 | static AnalyzerBuilder* find_builder(const std::string &name); 168 | 169 | /** 170 | * @brief register_builder 171 | */ 172 | static void register_builder( 173 | const std::string &name, AnalyzerBuilder* builder 174 | ); 175 | 176 | /** 177 | * @brief dprint_builders 178 | */ 179 | static void dprint_builders(); 180 | 181 | private: 182 | 183 | /** 184 | * @brief builder_map_t 185 | */ 186 | typedef std::map builder_map_t; 187 | 188 | /** 189 | * @brief builders Construct on first use. 190 | * @return 191 | */ 192 | static builder_map_t& builders(); 193 | 194 | }; 195 | 196 | } // end namespace gltracesim 197 | 198 | #endif // __GLTRACESIM_MODEL_HH__ 199 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 10 | ]]) 11 | 12 | # 13 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 14 | 'cpu.cc', 15 | 'gpu.cc', 16 | 'core.cc', 17 | 'trace_manager.cc' 18 | ]]) 19 | 20 | PROTO_SOURCES = [ 21 | 22 | ] 23 | 24 | _env['proto'] = [ 25 | simulator.File(x) for x in PROTO_SOURCES 26 | ] 27 | 28 | # 29 | Return('_env') 30 | 31 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/core.cc: -------------------------------------------------------------------------------- 1 | #include "analyzer/core.hh" 2 | 3 | #include "debug_impl.hh" 4 | 5 | #include "gltracesim_analyzer.hh" 6 | 7 | namespace gltracesim { 8 | namespace analyzer { 9 | 10 | Core::Core(const Json::Value ¶ms, 11 | GlTraceSimAnalyzer *simulator, schedular::SchedularPtr schedular) : 12 | simulator(simulator), schedular(schedular), state(RUNNING) 13 | { 14 | id = params["id"].asInt(); 15 | dev = params["dev"].asInt(); 16 | } 17 | 18 | void 19 | Core::tick() 20 | { 21 | // 22 | state = RUNNING; 23 | 24 | // Done with previous job 25 | if (_u(job == NULL || job->pkts.empty())) { 26 | 27 | // Try to get a new job from the schedular 28 | job = schedular->get_next_job(id, dev); 29 | 30 | // Did not get any job, continue 31 | if (job == NULL) { 32 | // 33 | state = IDLE; 34 | // 35 | return; 36 | } 37 | 38 | // Load pakcets 39 | job->load_trace(); 40 | 41 | // 42 | stats.no_jobs++; 43 | } 44 | 45 | if (_u(job == NULL || job->pkts.empty())) { 46 | return; 47 | } 48 | 49 | // 50 | auto &pkt = job->pkts.front(); 51 | // Core id 52 | pkt.tid = id; 53 | // Handle packet 54 | simulator->send_packet(pkt); 55 | // Remove from queue 56 | job->pkts.pop_front(); 57 | // 58 | stats.no_pkts++; 59 | 60 | // 61 | state = RUNNING; 62 | } 63 | 64 | } // end namespace analyzer 65 | } // end namespace gltracesim 66 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/core.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_CORE_HH__ 2 | #define __GLTRACESIM_ANALYZER_CORE_HH__ 3 | 4 | #include 5 | #include 6 | 7 | #include "gem5/protoio.hh" 8 | #include "gem5/packet.pb.h" 9 | 10 | #include "job.hh" 11 | 12 | #include "analyzer/schedular/base.hh" 13 | 14 | namespace gltracesim { 15 | 16 | class GlTraceSimAnalyzer; 17 | 18 | namespace analyzer { 19 | 20 | class Core { 21 | 22 | public: 23 | 24 | /** 25 | * @brief The state_t enum 26 | */ 27 | enum RuntimeState { 28 | IDLE, 29 | RUNNING 30 | }; 31 | 32 | public: 33 | 34 | /** 35 | * @brief core_t 36 | */ 37 | Core( 38 | const Json::Value ¶ms, 39 | GlTraceSimAnalyzer *simulator, 40 | schedular::SchedularPtr schedular 41 | ); 42 | 43 | 44 | /** 45 | * @brief tick 46 | */ 47 | void tick(); 48 | 49 | /** 50 | * @brief has_work 51 | * @return 52 | */ 53 | RuntimeState get_state() { 54 | return state; 55 | } 56 | 57 | private: 58 | 59 | /** 60 | * @brief id 61 | */ 62 | int id; 63 | 64 | /** 65 | * @brief dev 66 | */ 67 | int dev; 68 | 69 | /** 70 | * @brief simulator 71 | */ 72 | GlTraceSimAnalyzer *simulator; 73 | 74 | /** 75 | * @brief schedular 76 | */ 77 | schedular::SchedularPtr schedular; 78 | 79 | /** 80 | * @brief job_id 81 | */ 82 | GpuJobPtr job; 83 | 84 | /** 85 | * @brief has_work 86 | */ 87 | RuntimeState state; 88 | 89 | public: 90 | 91 | /** 92 | * @brief The stats_t struct 93 | */ 94 | struct stats_t { 95 | 96 | /** 97 | * @brief stats_t 98 | */ 99 | stats_t() : 100 | no_jobs(0), 101 | no_pkts(0) 102 | { 103 | // Do nothing 104 | } 105 | 106 | /** 107 | * @brief no_jobs 108 | */ 109 | size_t no_jobs; 110 | 111 | /** 112 | * @brief no_pkts 113 | */ 114 | size_t no_pkts; 115 | 116 | } stats; 117 | }; 118 | 119 | /** 120 | * @brief CorePtr 121 | */ 122 | typedef std::unique_ptr CorePtr; 123 | 124 | } // end namespace analyzer 125 | } // end namespace gltracesim 126 | 127 | #endif // __GLTRACESIM_ANALYZER_CORE_HH__ 128 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/cpu.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_CPU_HH__ 2 | #define __GLTRACESIM_ANALYZER_CPU_HH__ 3 | 4 | #include 5 | #include 6 | 7 | #include "gem5/protoio.hh" 8 | #include "gem5/packet.pb.h" 9 | 10 | #include "analyzer/core.hh" 11 | #include "analyzer/schedular/base.hh" 12 | 13 | namespace gltracesim { 14 | 15 | class GlTraceSimAnalyzer; 16 | 17 | namespace analyzer { 18 | 19 | class CPU { 20 | 21 | public: 22 | 23 | /** 24 | * @brief 25 | */ 26 | CPU( 27 | const Json::Value ¶ms, 28 | GlTraceSimAnalyzer *simulator, 29 | schedular::SchedularPtr schedular 30 | ); 31 | 32 | /** 33 | * 34 | */ 35 | ~CPU(); 36 | 37 | /** 38 | * @brief tick 39 | */ 40 | void tick(); 41 | 42 | /** 43 | * @brief get_core 44 | * @param core_id 45 | * @return 46 | */ 47 | Core* get_core() { 48 | return core.get(); 49 | } 50 | 51 | private: 52 | 53 | /** 54 | * @brief The proto_t struct 55 | */ 56 | struct proto_t { 57 | ProtoInputStream *cpu; 58 | } pb; 59 | 60 | /** 61 | * @brief simulator 62 | */ 63 | GlTraceSimAnalyzer *simulator; 64 | 65 | /** 66 | * @brief schedular 67 | */ 68 | schedular::SchedularPtr schedular; 69 | 70 | /** 71 | * @brief barrier_id 72 | */ 73 | uint64_t barrier_id; 74 | 75 | enum RuntimeState { 76 | PROCESS_CMD, 77 | D_SYNC, 78 | W_SYNC, 79 | D_RSC_SYNC, 80 | W_RSC_SYNC, 81 | D_NEW_SCENE_SYNC, 82 | D_END_SCENE_SYNC, 83 | W_NEW_SCENE_SYNC, 84 | W_END_SCENE_SYNC, 85 | D_FRAME_SYNC, 86 | W_FRAME_SYNC 87 | }; 88 | 89 | RuntimeState state; 90 | 91 | /** 92 | * @brief core 93 | */ 94 | CorePtr core; 95 | 96 | }; 97 | 98 | } // end namespace analyzer 99 | } // end namespace gltracesim 100 | 101 | #endif // __GLTRACESIM_ANALYZER_GPU_HH__ 102 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/gpu.cc: -------------------------------------------------------------------------------- 1 | #include "analyzer/cpu.hh" 2 | #include "analyzer/gpu.hh" 3 | 4 | #include "debug_impl.hh" 5 | 6 | #include "gltracesim_analyzer.hh" 7 | 8 | namespace gltracesim { 9 | namespace analyzer { 10 | 11 | GPU::GPU(const Json::Value ¶ms, 12 | GlTraceSimAnalyzer *simulator, schedular::SchedularPtr schedular) : 13 | simulator(simulator), schedular(schedular), barrier_id(0), 14 | core_state(Core::RuntimeState::IDLE), state(PROCESS_CMD) 15 | { 16 | // 17 | ProtoMessage::PacketHeader hdr; 18 | 19 | pb.gpu = new ProtoInputStream( 20 | params["input-dir"].asString() + "/gpu.pb.gz" 21 | ); 22 | 23 | // 24 | pb.gpu->read(hdr); 25 | 26 | DPRINTF(Init, "GPU CMD File Header [id:%s, ver:%i, tick_freq:%lu].\n", 27 | hdr.obj_id().c_str(), hdr.ver(), hdr.tick_freq() 28 | ); 29 | 30 | // 31 | for (int core_id = 0; 32 | core_id < params["num-gpu-cores"].asInt(); 33 | ++core_id) 34 | { 35 | Json::Value p; 36 | p["id"] = core_id + 1; // 0 == CPU 37 | p["dev"] = dev::GPU; 38 | 39 | // 40 | cores.push_back(CorePtr(new Core(p, simulator, schedular))); 41 | } 42 | } 43 | 44 | GPU::~GPU() 45 | { 46 | delete pb.gpu; 47 | } 48 | 49 | 50 | void 51 | GPU::tick_cores() 52 | { 53 | // 54 | bool is_running = false; 55 | 56 | // 57 | for (size_t core_id = 0; core_id < cores.size(); ++core_id) { 58 | // 59 | cores[core_id]->tick(); 60 | // 61 | is_running |= 62 | (cores[core_id]->get_state() == Core::RuntimeState::RUNNING); 63 | } 64 | 65 | // 66 | if (_l(is_running)) { 67 | core_state = Core::RuntimeState::RUNNING; 68 | } else { 69 | core_state = Core::RuntimeState::IDLE; 70 | } 71 | } 72 | 73 | void 74 | GPU::tick() 75 | { 76 | 77 | // Current state 78 | switch (state) 79 | { 80 | case D_SYNC: 81 | case D_RSC_SYNC: 82 | { 83 | // 84 | schedular->set_gpu_ready(++barrier_id); 85 | 86 | // Current state 87 | switch (state) 88 | { 89 | case D_SYNC: { state = W_SYNC; break; } 90 | case D_RSC_SYNC: { state = W_RSC_SYNC; break; } 91 | default: assert(0); 92 | } 93 | 94 | // 95 | return; 96 | } 97 | case D_NEW_SCENE_SYNC: 98 | case D_END_SCENE_SYNC: 99 | case D_FRAME_SYNC: 100 | { 101 | // Advance cores 102 | tick_cores(); 103 | 104 | // Wait for all cores 105 | if (_l(core_state == Core::RuntimeState::RUNNING)) { 106 | return; 107 | } 108 | 109 | // 110 | schedular->set_gpu_ready(++barrier_id); 111 | 112 | // Current state 113 | switch (state) 114 | { 115 | case D_NEW_SCENE_SYNC: { state = W_NEW_SCENE_SYNC; break; } 116 | case D_END_SCENE_SYNC: { state = W_END_SCENE_SYNC; break; } 117 | case D_FRAME_SYNC: { state = W_FRAME_SYNC; break; } 118 | default: assert(0); 119 | } 120 | 121 | return; 122 | } 123 | case W_SYNC: 124 | case W_RSC_SYNC: 125 | case W_NEW_SCENE_SYNC: 126 | case W_END_SCENE_SYNC: 127 | case W_FRAME_SYNC: 128 | { 129 | // Wait for CPU barrier 130 | if (_l(schedular->is_cpu_ready(barrier_id) == false)) { 131 | return; 132 | } 133 | 134 | // 135 | state = PROCESS_CMD; 136 | 137 | // 138 | return; 139 | } 140 | case PROCESS_CMD: 141 | { 142 | break; 143 | } 144 | default: assert(0); 145 | } 146 | 147 | // 148 | ProtoMessage::Packet pkt; 149 | 150 | // Next Packet 151 | if (_u(pb.gpu->read(pkt) == false)) { 152 | // 153 | return; 154 | } 155 | 156 | // Next state 157 | switch (pkt.cmd()) 158 | { 159 | case gem5::NewSceneCMD: 160 | { 161 | // 162 | state = D_NEW_SCENE_SYNC; 163 | // 164 | return; 165 | } 166 | case gem5::EndSceneCMD: 167 | { 168 | // 169 | state = D_NEW_SCENE_SYNC; 170 | // 171 | return; 172 | } 173 | case gem5::NewJobCMD: 174 | case gem5::EndJobCMD: 175 | { 176 | // 177 | return; 178 | } 179 | case gem5::NewResourceCMD: 180 | case gem5::EndResourceCMD: 181 | { 182 | // 183 | state = D_RSC_SYNC; 184 | // 185 | return; 186 | } 187 | case gem5::SyncProvidesCMD: 188 | case gem5::SyncRequiresCMD: 189 | case gem5::SyncCMD: 190 | { 191 | // 192 | state = D_SYNC; 193 | // 194 | return; 195 | } 196 | case gem5::NewFrameCMD: 197 | { 198 | // 199 | state = D_FRAME_SYNC; 200 | // 201 | return; 202 | } 203 | default: 204 | assert(0); 205 | } 206 | } 207 | 208 | } // end namespace analyzer 209 | } // end namespace gltracesim 210 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/gpu.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_GPU_HH__ 2 | #define __GLTRACESIM_ANALYZER_GPU_HH__ 3 | 4 | #include 5 | #include 6 | 7 | #include "gem5/protoio.hh" 8 | #include "gem5/packet.pb.h" 9 | 10 | #include "job.hh" 11 | 12 | #include "analyzer/core.hh" 13 | #include "analyzer/schedular/base.hh" 14 | 15 | namespace gltracesim { 16 | 17 | class GlTraceSimAnalyzer; 18 | 19 | namespace analyzer { 20 | 21 | class GPU { 22 | 23 | public: 24 | 25 | /** 26 | * @brief GPU 27 | */ 28 | GPU( 29 | const Json::Value ¶ms, 30 | GlTraceSimAnalyzer *simulator, 31 | schedular::SchedularPtr schedular 32 | ); 33 | 34 | /** 35 | * 36 | */ 37 | ~GPU(); 38 | 39 | /** 40 | * @brief tick 41 | */ 42 | void tick(); 43 | 44 | /** 45 | * @brief get_core 46 | * @param core_id 47 | * @return 48 | */ 49 | Core* get_core(int core_id) { 50 | return cores[core_id].get(); 51 | } 52 | 53 | /** 54 | * @brief num_cores 55 | * @return 56 | */ 57 | size_t num_cores() const { 58 | return cores.size(); 59 | } 60 | 61 | private: 62 | 63 | /** 64 | * @brief sync 65 | * @return 66 | */ 67 | bool sync(); 68 | 69 | /** 70 | * @brief tick 71 | */ 72 | void tick_cores(); 73 | 74 | private: 75 | 76 | /** 77 | * @brief The proto_t struct 78 | */ 79 | struct proto_t { 80 | ProtoInputStream *gpu; 81 | } pb; 82 | 83 | /** 84 | * @brief simulator 85 | */ 86 | GlTraceSimAnalyzer *simulator; 87 | 88 | /** 89 | * @brief schedular 90 | */ 91 | schedular::SchedularPtr schedular; 92 | 93 | /** 94 | * @brief barrier_id 95 | */ 96 | uint64_t barrier_id; 97 | 98 | /** 99 | * @brief state 100 | */ 101 | Core::RuntimeState core_state; 102 | 103 | enum RuntimeState { 104 | PROCESS_CMD, 105 | D_SYNC, 106 | W_SYNC, 107 | D_RSC_SYNC, 108 | W_RSC_SYNC, 109 | D_NEW_SCENE_SYNC, 110 | D_END_SCENE_SYNC, 111 | W_NEW_SCENE_SYNC, 112 | W_END_SCENE_SYNC, 113 | D_FRAME_SYNC, 114 | W_FRAME_SYNC 115 | }; 116 | 117 | RuntimeState state; 118 | 119 | /** 120 | * @brief gpu 121 | */ 122 | std::vector cores; 123 | 124 | }; 125 | 126 | } // end namespace analyzer 127 | } // end namespace gltracesim 128 | 129 | #endif // __GLTRACESIM_ANALYZER_GPU_HH__ 130 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 10 | ]]) 11 | 12 | # 13 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 14 | 'base.cc', 15 | 'base_cache.cc', 16 | 'intel_cache.cc', 17 | 'ls_cache.cc' 18 | ]]) 19 | 20 | PROTO_SOURCES = [ 21 | 'base_cache.proto', 22 | 'ls_cache.proto', 23 | ] 24 | 25 | _env['proto'] = [ 26 | simulator.File(x) for x in PROTO_SOURCES 27 | ] 28 | 29 | # 30 | Return('_env') 31 | 32 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/base.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "analyzer/memory/base.hh" 4 | #include "gem5/packet.pb.h" 5 | #include "debug_impl.hh" 6 | 7 | namespace gltracesim { 8 | namespace analyzer { 9 | namespace memory { 10 | 11 | BaseModel::BaseModel(const Json::Value &p) : 12 | Analyzer(p, p["id"].asInt()) 13 | { 14 | // 15 | ProtoMessage::PacketHeader hdr; 16 | 17 | // 18 | hdr.set_obj_id("gltracesim-stats"); 19 | hdr.set_ver(0); 20 | hdr.set_tick_freq(1); 21 | 22 | std::stringstream basename; 23 | basename << params["output-dir"].asCString() << "/" << id; 24 | 25 | // 26 | pb.stats = new ProtoOutputStream( 27 | basename.str() + ".stats.pb.gz" 28 | ); 29 | // 30 | pb.job_stats = new ProtoOutputStream( 31 | basename.str() + ".job_stats.pb.gz" 32 | ); 33 | // 34 | pb.core_stats = new ProtoOutputStream( 35 | basename.str() + ".core_stats.pb.gz" 36 | ); 37 | // 38 | pb.rsc_stats = new ProtoOutputStream( 39 | basename.str() + ".rsc_stats.pb.gz" 40 | ); 41 | 42 | // 43 | pb.stats->write(hdr); 44 | pb.job_stats->write(hdr); 45 | pb.core_stats->write(hdr); 46 | pb.rsc_stats->write(hdr); 47 | 48 | DPRINTF(Init, "BaseAnalyzer [id: %i].\n", id); 49 | 50 | } 51 | 52 | BaseModel::~BaseModel() 53 | { 54 | delete pb.stats; 55 | delete pb.job_stats; 56 | delete pb.core_stats; 57 | delete pb.rsc_stats; 58 | 59 | DPRINTF(Init, "-BaseAnalyzer [id: %i].\n", id); 60 | } 61 | 62 | } // end namespace memory 63 | } // end namespace analyzer 64 | } // end namespace gltracesim 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/base.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_MEMORY_BASE_HH__ 2 | #define __GLTRACESIM_ANALYZER_MEMORY_BASE_HH__ 3 | 4 | #include "analyzer.hh" 5 | #include 6 | 7 | namespace gltracesim { 8 | namespace analyzer { 9 | namespace memory { 10 | 11 | class BaseModel : public Analyzer 12 | { 13 | 14 | public: 15 | 16 | /** 17 | * @brief Analyzer 18 | */ 19 | BaseModel(const Json::Value ¶ms); 20 | 21 | /** 22 | * @brief ~Analyzer 23 | */ 24 | virtual ~BaseModel(); 25 | 26 | /** 27 | * @brief process 28 | * @param pkt 29 | */ 30 | void process(const packet_t &pkt) = 0; 31 | 32 | /** 33 | * @brief start_new_frame 34 | */ 35 | virtual void start_new_frame(int frame_id) { /* do nothing */ } 36 | 37 | /** 38 | * @brief start_new_scene 39 | */ 40 | virtual void start_new_scene(int frame_id, int scene_id) { /* do nothing */ } 41 | 42 | /** 43 | * @brief process 44 | * @param buffer 45 | */ 46 | virtual void dump_stats() = 0; 47 | 48 | /** 49 | * @brief process 50 | * @param buffer 51 | */ 52 | virtual void reset_stats() = 0; 53 | 54 | protected: 55 | 56 | /** 57 | * @brief The pb_t struct 58 | */ 59 | struct pb_t { 60 | // 61 | ProtoOutputStream *stats; 62 | // 63 | ProtoOutputStream *job_stats; 64 | // 65 | ProtoOutputStream *core_stats; 66 | // 67 | ProtoOutputStream *rsc_stats; 68 | } pb; 69 | 70 | }; 71 | 72 | } // end namespace memory 73 | } // end namespace analyzer 74 | } // end namespace gltracesim 75 | 76 | #endif // __GLTRACESIM_ANALYZER_MEMORY_BASE_HH__ 77 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/base_cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_MODEL_CACHE_HH__ 2 | #define __GLTRACESIM_MODEL_CACHE_HH__ 3 | 4 | #include 5 | #include 6 | 7 | #include "util/cache.hh" 8 | #include "util/cache_impl.hh" 9 | #include "util/sat_counter.hh" 10 | 11 | #include "stats/cache.hh" 12 | #include "stats/cache_impl.hh" 13 | #include "stats/distribution.hh" 14 | #include "stats/distribution_impl.hh" 15 | 16 | #include "analyzer.hh" 17 | #include "analyzer/memory/base.hh" 18 | #include 19 | 20 | namespace gltracesim { 21 | namespace analyzer { 22 | namespace memory { 23 | 24 | class BaseCacheModel : public BaseModel 25 | { 26 | 27 | protected: 28 | 29 | /** 30 | * @brief The filter_cache_params_t struct 31 | */ 32 | struct cache_params_t : public gltracesim::cache_params_t 33 | { 34 | 35 | }; 36 | 37 | /** 38 | * @brief sat_counter_t 39 | */ 40 | typedef SatCounter sat_counter_t; 41 | 42 | /** 43 | * @brief blk_util_vector 44 | */ 45 | typedef std::vector blk_util_vector; 46 | 47 | /** 48 | * @brief The cache_entry_t struct 49 | */ 50 | struct cache_entry_t : public gltracesim::cache_entry_t 51 | { 52 | /** 53 | * @brief frame number 54 | */ 55 | uint16_t last_frame_nbr; 56 | 57 | /** 58 | * @brief scene number 59 | */ 60 | uint16_t last_scene_nbr; 61 | 62 | /** 63 | * @brief job number 64 | */ 65 | uint16_t last_job_nbr; 66 | 67 | /** 68 | * @brief rsc number 69 | */ 70 | uint16_t last_rsc_nbr; 71 | 72 | /** 73 | * @brief touched_sub_blks 74 | */ 75 | blk_util_vector sub_blk_ctrs; 76 | }; 77 | 78 | /** 79 | * @brief cache_base_t 80 | */ 81 | typedef gltracesim::Cache BaseCache; 82 | 83 | /** 84 | * @brief The BasicCache class 85 | */ 86 | struct Cache : public BaseCache 87 | { 88 | // 89 | typedef BaseCache Base; 90 | typedef cache_params_t params_t; 91 | typedef cache_entry_t entry_t; 92 | 93 | /** 94 | * @brief BasicCache 95 | * @param p 96 | */ 97 | Cache(params_t *p); 98 | 99 | }; 100 | 101 | // 102 | typedef std::shared_ptr CachePtr; 103 | 104 | public: 105 | 106 | /** 107 | * @brief Analyzer 108 | */ 109 | BaseCacheModel(const Json::Value ¶ms); 110 | 111 | /** 112 | * @brief ~Analyzer 113 | */ 114 | virtual ~BaseCacheModel(); 115 | 116 | /** 117 | * @brief process 118 | * @param pkt 119 | */ 120 | void process(const packet_t &pkt); 121 | 122 | /** 123 | * @brief bypass 124 | * @param pkt 125 | * @return 126 | */ 127 | virtual bool bypass(const packet_t &pkt) { return false; } 128 | 129 | /** 130 | * @brief start_new_frame 131 | */ 132 | virtual void start_new_frame(int frame_id) { /* do nothing */ } 133 | 134 | /** 135 | * @brief start_new_scene 136 | */ 137 | virtual void start_new_scene(int frame_id, int scene_id) { /* do nothing */ } 138 | 139 | /** 140 | * @brief process 141 | * @param buffer 142 | */ 143 | virtual void dump_stats(); 144 | 145 | /** 146 | * @brief process 147 | * @param buffer 148 | */ 149 | virtual void reset_stats(); 150 | 151 | protected: 152 | 153 | /** 154 | * @brief tick 155 | */ 156 | size_t tick; 157 | 158 | /** 159 | * @brief install_wr_in_lru 160 | */ 161 | bool fetch_on_wr_miss; 162 | 163 | /** 164 | * @brief cache 165 | */ 166 | CachePtr cache; 167 | 168 | /** 169 | * @brief cache_stats 170 | */ 171 | stats::Cache cache_stats; 172 | 173 | /** 174 | * @brief job_stats 175 | */ 176 | std::unordered_map job_stats; 177 | 178 | /** 179 | * @brief core_stats 180 | */ 181 | std::unordered_map core_stats; 182 | 183 | /** 184 | * @brief rsc_stats 185 | */ 186 | std::unordered_map rsc_stats; 187 | 188 | /** 189 | * @brief blk_utilization 190 | */ 191 | stats::Distribution blk_utilization; 192 | 193 | /** 194 | * @brief blk_reutilization 195 | */ 196 | stats::Distribution blk_reutilization; 197 | 198 | }; 199 | 200 | } // end namespace memory 201 | } // end namespace analyzer 202 | } // end namespace gltracesim 203 | 204 | #endif // __GLTRACESIM_MODEL_CACHE_HH__ 205 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/base_cache.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "stats/cache.proto"; 4 | import "stats/distribution.proto"; 5 | 6 | package gltracesim.proto; 7 | 8 | message BaseCacheStats { 9 | // 10 | uint32 frame_id = 1; 11 | // 12 | uint32 scene_id = 2; 13 | // 14 | gltracesim.proto.CacheStats cache_stats = 3; 15 | // 16 | gltracesim.proto.Distribution blk_utilization = 4; 17 | // 18 | gltracesim.proto.Distribution blk_reutilization = 5; 19 | } 20 | 21 | message BaseCacheCoreStats { 22 | // 23 | uint32 id = 1; 24 | // 25 | gltracesim.proto.CacheStats cache_stats = 2; 26 | } 27 | 28 | message BaseCacheJobStats { 29 | // 30 | uint32 id = 1; 31 | // 32 | gltracesim.proto.CacheStats cache_stats = 2; 33 | } 34 | 35 | message BaseCacheRscStats { 36 | // 37 | uint32 id = 1; 38 | // 39 | uint32 frame_id = 2; 40 | // 41 | uint32 scene_id = 3; 42 | // 43 | gltracesim.proto.CacheStats cache_stats = 4; 44 | } 45 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/intel_cache.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "analyzer/memory/base_cache.pb.h" 4 | #include "analyzer/memory/intel_cache.hh" 5 | 6 | #include "debug_impl.hh" 7 | #include "system.hh" 8 | 9 | namespace gltracesim { 10 | namespace analyzer { 11 | namespace memory { 12 | 13 | /** 14 | * @brief The VanillaCacheAnalyzerBuilder struct 15 | */ 16 | struct IntelCacheModelBuilder : public gltracesim::AnalyzerBuilder 17 | { 18 | IntelCacheModelBuilder() : AnalyzerBuilder("IntelCache") { 19 | // Do nothing 20 | } 21 | 22 | AnalyzerPtr create(const Json::Value ¶ms) { 23 | return AnalyzerPtr(new IntelCacheModel(params)); 24 | } 25 | }; 26 | 27 | // 28 | IntelCacheModelBuilder intel_cache_analyzer_builder; 29 | 30 | IntelCacheModel::IntelCacheModel(const Json::Value &p) : 31 | BaseCacheModel(p) 32 | { 33 | DPRINTF(Init, "IntelCacheAnalyzer [id: %i].\n", 34 | id 35 | ); 36 | 37 | max_rsc_size = p["max-rsc-size"].asUInt64(); 38 | } 39 | 40 | IntelCacheModel::~IntelCacheModel() 41 | { 42 | DPRINTF(Init, "-IntelCacheAnalyzer [id: %i].\n", id); 43 | } 44 | 45 | bool 46 | IntelCacheModel::bypass(const packet_t &pkt) 47 | { 48 | // 49 | GpuResourcePtr gpu_resource = system->rt->find_id(pkt.rsc_id); 50 | // 51 | assert(gpu_resource); 52 | 53 | // 54 | if (gpu_resource->size() > max_rsc_size) { 55 | return true; 56 | } else { 57 | return false; 58 | } 59 | } 60 | 61 | } // end namespace memory 62 | } // end namespace analyzer 63 | } // end namespace gltracesim 64 | 65 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/intel_cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_MEMORY_INTEL_CACHE_HH__ 2 | #define __GLTRACESIM_ANALYZER_MEMORY_INTEL_CACHE_HH__ 3 | 4 | #include 5 | 6 | #include "util/cache.hh" 7 | #include "util/cache_impl.hh" 8 | #include "util/sat_counter.hh" 9 | 10 | #include "stats/cache.hh" 11 | #include "stats/cache_impl.hh" 12 | #include "stats/distribution.hh" 13 | #include "stats/distribution_impl.hh" 14 | 15 | #include "analyzer/memory/base_cache.hh" 16 | 17 | namespace gltracesim { 18 | namespace analyzer { 19 | namespace memory { 20 | 21 | 22 | class IntelCacheModel : public BaseCacheModel 23 | { 24 | 25 | public: 26 | 27 | /** 28 | * @brief Analyzer 29 | */ 30 | IntelCacheModel(const Json::Value ¶ms); 31 | 32 | /** 33 | * @brief ~Analyzer 34 | */ 35 | virtual ~IntelCacheModel(); 36 | 37 | /** 38 | * @brief bypass 39 | * @param pkt 40 | * @return 41 | */ 42 | virtual bool bypass(const packet_t &pkt); 43 | 44 | protected: 45 | 46 | /** 47 | * @brief max_rsc_size 48 | */ 49 | uint64_t max_rsc_size; 50 | 51 | }; 52 | 53 | } // end namespace memory 54 | } // end namespace analyzer 55 | } // end namespace gltracesim 56 | 57 | #endif // __GLTRACESIM_ANALYZER_MEMORY_INTEL_CACHE_HH__ 58 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/ls_cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_MEMORY_LIMIT_STUDY_CACHE_HH__ 2 | #define __GLTRACESIM_ANALYZER_MEMORY_LIMIT_STUDY_CACHE_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "util/cache.hh" 9 | #include "util/cache_impl.hh" 10 | #include "util/sat_counter.hh" 11 | 12 | #include "stats/cache.hh" 13 | #include "stats/cache_impl.hh" 14 | #include "stats/distribution.hh" 15 | #include "stats/distribution_impl.hh" 16 | 17 | #include "analyzer/memory/base_cache.hh" 18 | 19 | namespace gltracesim { 20 | namespace analyzer { 21 | namespace memory { 22 | 23 | 24 | class LimitStudyCacheModel : public BaseCacheModel 25 | { 26 | 27 | public: 28 | 29 | /** 30 | * @brief Analyzer 31 | */ 32 | LimitStudyCacheModel(const Json::Value ¶ms); 33 | 34 | /** 35 | * @brief ~Analyzer 36 | */ 37 | virtual ~LimitStudyCacheModel(); 38 | 39 | /** 40 | * @brief process 41 | * @param pkt 42 | */ 43 | virtual void process(const packet_t &pkt); 44 | 45 | /** 46 | * @brief start_new_frame 47 | */ 48 | virtual void start_new_frame(int frame_id); 49 | 50 | /** 51 | * @brief start_new_scene 52 | */ 53 | virtual void start_new_scene(int frame_id, int scene_id); 54 | 55 | protected: 56 | 57 | /** 58 | * @brief filter_inter_scene_sharing 59 | */ 60 | bool filter_inter_scene_sharing; 61 | 62 | /** 63 | * @brief filter_inter_scene_sharing 64 | */ 65 | bool filter_intra_scene_sharing; 66 | 67 | /** 68 | * @brief filter_inter_scene_sharing 69 | */ 70 | bool filter_intra_task_sharing; 71 | 72 | protected: 73 | 74 | /** 75 | * @brief load_inter_scene_sharing_data 76 | * @param frame_id 77 | */ 78 | void load_inter_scene_sharing_data( 79 | int frame_id 80 | ); 81 | 82 | /** 83 | * @brief load_intra_scene_sharing_data 84 | * @param frame_id 85 | * @param scene_id 86 | */ 87 | void load_intra_scene_sharing_data( 88 | int frame_id, 89 | int scene_id 90 | ); 91 | 92 | protected: 93 | 94 | /** 95 | * @brief addr_set_t 96 | */ 97 | typedef std::unordered_set addr_set_t; 98 | 99 | /** 100 | * @brief inter_scene_sharing_mask 101 | */ 102 | addr_set_t inter_scene_sharing_mask; 103 | 104 | /** 105 | * @brief inter_scene_sharing_mask_asseses 106 | */ 107 | addr_set_t inter_scene_sharing_mask_accesses; 108 | 109 | /** 110 | * @brief intra_scene_sharing_mask 111 | */ 112 | addr_set_t intra_scene_sharing_mask; 113 | 114 | /** 115 | * @brief inter_scene_sharing_mask_asseses 116 | */ 117 | addr_set_t intra_scene_sharing_mask_accesses; 118 | 119 | /** 120 | * @brief intra_task_sharing_mask 121 | */ 122 | std::unordered_map intra_task_sharing_mask; 123 | 124 | }; 125 | 126 | } // end namespace memory 127 | } // end namespace analyzer 128 | } // end namespace gltracesim 129 | 130 | #endif // __GLTRACESIM_ANALYZER_MEMORY_LIMIT_STUDY_CACHE_HH__ 131 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/memory/ls_cache.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message FrameCachelineUsers { 6 | uint32 frame_id = 1; 7 | uint64 addr = 2; 8 | uint32 scene_users = 3; 9 | } 10 | 11 | message SceneCachelineUsers { 12 | uint32 frame_id = 1; 13 | uint32 scene_id = 2; 14 | uint64 addr = 3; 15 | uint32 task_users = 4; 16 | } 17 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 10 | ]]) 11 | 12 | # 13 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 14 | 'base.cc', 15 | 'fcfs.cc', 16 | 'z.cc', 17 | 'random.cc', 18 | ]]) 19 | 20 | PROTO_SOURCES = [ 21 | 'schedule.proto' 22 | ] 23 | 24 | _env['proto'] = [ 25 | simulator.File(x) for x in PROTO_SOURCES 26 | ] 27 | 28 | # 29 | Return('_env') 30 | 31 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/base.cc: -------------------------------------------------------------------------------- 1 | #include "frame.pb.h" 2 | #include "scene.pb.h" 3 | #include "job.pb.h" 4 | 5 | #include "debug_impl.hh" 6 | #include "gem5/packet.pb.h" 7 | 8 | #include "analyzer/schedular/base.hh" 9 | #include "analyzer/schedular/schedule.pb.h" 10 | 11 | namespace gltracesim { 12 | namespace analyzer { 13 | namespace schedular { 14 | 15 | Schedular::Schedular(const Json::Value ¶ms) 16 | { 17 | // 18 | system_barrier_id[dev::CPU] = 0; 19 | system_barrier_id[dev::GPU] = 0; 20 | 21 | // 22 | ProtoMessage::PacketHeader hdr; 23 | 24 | // 25 | hdr.set_obj_id("gltracesim"); 26 | hdr.set_ver(0); 27 | hdr.set_tick_freq(1); 28 | 29 | // 30 | pb.output_schedule = new ProtoOutputStream( 31 | params["output-dir"].asString() + "/output_schedule.pb.gz" 32 | ); 33 | 34 | pb.output_schedule->write(hdr); 35 | 36 | } 37 | 38 | Schedular::~Schedular() 39 | { 40 | delete pb.output_schedule; 41 | } 42 | 43 | void 44 | Schedular::dump_schedule_descision(GpuJobPtr &job) 45 | { 46 | // 47 | gltracesim::proto::JobSchedule schedule; 48 | // 49 | schedule.set_id(job->id); 50 | // 51 | schedule.set_core_id(job->core_id); 52 | // 53 | pb.output_schedule->write(schedule); 54 | } 55 | 56 | bool 57 | Schedular::provide(uint64_t id) 58 | { 59 | assert(0); 60 | return true; 61 | } 62 | 63 | bool 64 | Schedular::require(uint64_t id) 65 | { 66 | assert(0); 67 | return true; 68 | } 69 | 70 | } // end namespace schedular 71 | } // end namespace analyzer 72 | } // end namespace gltracesim 73 | 74 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/base.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_SCHEDULAR_BASE_HH__ 2 | #define __GLTRACESIM_ANALYZER_SCHEDULAR_BASE_HH__ 3 | 4 | #include 5 | 6 | #include "util/cflags.hh" 7 | #include "job.hh" 8 | 9 | namespace gltracesim { 10 | namespace analyzer { 11 | namespace schedular { 12 | 13 | 14 | class Schedular 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Schedular 21 | */ 22 | Schedular(const Json::Value ¶ms); 23 | 24 | /** 25 | * @brief ~Schedular 26 | */ 27 | virtual ~Schedular(); 28 | 29 | protected: 30 | 31 | /** 32 | * @brief save_schedule_descision 33 | * @param core_id 34 | * @param dev 35 | * @return 36 | */ 37 | void dump_schedule_descision(GpuJobPtr &job); 38 | 39 | /** 40 | * @brief get_next_cpu_job 41 | * @param core_id 42 | * @return 43 | */ 44 | virtual GpuJobPtr get_next_cpu_job(int core_id) = 0; 45 | 46 | /** 47 | * @brief get_next_gpu_job 48 | * @param core_id 49 | * @return 50 | */ 51 | virtual GpuJobPtr get_next_gpu_job(int core_id) = 0; 52 | 53 | public: 54 | 55 | /** 56 | * @brief get_next_gpu_job 57 | * @param core_id 58 | * @return 59 | */ 60 | virtual GpuJobPtr get_next_job(int core_id, int dev) { 61 | // 62 | GpuJobPtr job; 63 | 64 | // 65 | if (dev == dev::CPU) { 66 | job = get_next_cpu_job(core_id); 67 | } else { 68 | job = get_next_gpu_job(core_id); 69 | } 70 | 71 | // 72 | if (job) { 73 | // 74 | job->core_id = core_id; 75 | // 76 | dump_schedule_descision(job); 77 | } 78 | 79 | // 80 | return job; 81 | } 82 | 83 | /** 84 | * @brief start_new_frame 85 | */ 86 | virtual void start_new_frame(int frame_id) = 0; 87 | 88 | /** 89 | * @brief start_new_scene 90 | */ 91 | virtual void start_new_scene(int frame_id, int scene_id) = 0; 92 | 93 | public: 94 | 95 | /** 96 | * @brief is_gpu_ready 97 | * @param id 98 | * @return 99 | */ 100 | bool is_gpu_ready(uint64_t id) { 101 | // 102 | if (_u(system_barrier_id[dev::GPU] < id)) { 103 | return false; 104 | } 105 | // 106 | return true; 107 | } 108 | 109 | /** 110 | * @brief set_gpu_ready 111 | * @param id 112 | */ 113 | void set_gpu_ready(uint64_t id) { 114 | system_barrier_id[dev::GPU] = id; 115 | } 116 | 117 | /** 118 | * @brief is_cpu_ready 119 | * @param id 120 | * @return 121 | */ 122 | bool is_cpu_ready(uint64_t id) { 123 | // 124 | if (_u(system_barrier_id[dev::CPU] < id)) { 125 | return false; 126 | } 127 | // 128 | return true; 129 | } 130 | 131 | /** 132 | * @brief set_cpu_ready 133 | * @param id 134 | */ 135 | void set_cpu_ready(uint64_t id) { 136 | system_barrier_id[dev::CPU] = id; 137 | } 138 | 139 | /** 140 | * @brief provide 141 | * @param id 142 | * @return 143 | */ 144 | bool provide(uint64_t id); 145 | 146 | /** 147 | * @brief require 148 | * @param id 149 | * @return 150 | */ 151 | bool require(uint64_t id); 152 | 153 | protected: 154 | 155 | /** 156 | * @brief The pb_t struct 157 | */ 158 | struct pb_t { 159 | // 160 | ProtoOutputStream *output_schedule; 161 | } pb; 162 | 163 | protected: 164 | 165 | /** 166 | * @brief no_cores 167 | */ 168 | size_t no_cores; 169 | 170 | protected: 171 | 172 | /** 173 | * @brief barrier_id 174 | */ 175 | std::array system_barrier_id; 176 | 177 | /** 178 | * @brief scoreboard 179 | */ 180 | std::set system_scoreboard; 181 | 182 | }; 183 | 184 | /** 185 | * @brief SchedularPtr 186 | */ 187 | typedef std::shared_ptr SchedularPtr; 188 | 189 | } // end namespace schedular 190 | } // end namespace analyzer 191 | } // end namespace gltracesim 192 | 193 | #endif // __GLTRACESIM_ANALYZER_SCHEDULAR_BASE_HH__ 194 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/fcfs.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug_impl.hh" 3 | 4 | #include "analyzer/trace_manager.hh" 5 | #include "analyzer/schedular/fcfs.hh" 6 | 7 | namespace gltracesim { 8 | namespace analyzer { 9 | namespace schedular { 10 | 11 | FCFSSchedular::FCFSSchedular(const Json::Value ¶ms) 12 | : Schedular(params), next_scene_id(0), next_frame_id(0) 13 | { 14 | 15 | } 16 | 17 | FCFSSchedular::~FCFSSchedular() 18 | { 19 | 20 | } 21 | 22 | GpuJobPtr 23 | FCFSSchedular::get_next_cpu_job(int core_id) 24 | { 25 | if (cpu_queue.empty()) { 26 | return NULL; 27 | } 28 | 29 | // 30 | auto job = cpu_queue.front(); 31 | // 32 | cpu_queue.pop_front(); 33 | // 34 | return job; 35 | } 36 | 37 | GpuJobPtr 38 | FCFSSchedular::get_next_gpu_job(int core_id) 39 | { 40 | if (gpu_queue.empty()) { 41 | return NULL; 42 | } 43 | 44 | // 45 | auto job = gpu_queue.front(); 46 | // 47 | gpu_queue.pop_front(); 48 | // 49 | DPRINTF(ScheduleEvent, "GPU Job: %d [x: %d, y: %d].\n", 50 | job->id, job->x, job->y 51 | ); 52 | // 53 | return job; 54 | } 55 | 56 | void 57 | FCFSSchedular::start_new_frame(int frame_id) 58 | { 59 | assert(cpu_queue.empty()); 60 | assert(gpu_queue.empty()); 61 | 62 | // 63 | current_frame = trace_manager->get_frame(next_frame_id); 64 | 65 | DPRINTF(ScheduleEvent, "New Frame: %d [scenes: %lu].\n", 66 | current_frame->id, 67 | current_frame->scenes.size() 68 | ); 69 | 70 | // 71 | assert(current_frame->id == next_frame_id); 72 | 73 | next_frame_id++; 74 | } 75 | 76 | void 77 | FCFSSchedular::start_new_scene(int frame_id, int scene_id) 78 | { 79 | assert(cpu_queue.empty()); 80 | assert(gpu_queue.empty()); 81 | 82 | // 83 | current_scene = trace_manager->get_scene(next_scene_id); 84 | 85 | DPRINTF(ScheduleEvent, "New Scene: %d [frame: %d, width: %d, height: %d, jobs: %lu].\n", 86 | current_scene->id, 87 | current_scene->frame_id, 88 | current_scene->width, 89 | current_scene->height, 90 | current_scene->jobs.size() 91 | ); 92 | 93 | std::vector pending_draw_jobs; 94 | std::vector pending_tile_jobs; 95 | std::vector pending_misc_jobs; 96 | 97 | // Fill job queues 98 | for (auto job_id: current_scene->jobs) { 99 | // 100 | GpuJobPtr job = trace_manager->get_job(current_scene->frame_id, job_id); 101 | 102 | // 103 | if (job->dev == dev::CPU) { 104 | // 105 | cpu_queue.push_back(job); 106 | // 107 | continue; 108 | } 109 | 110 | // GPU 111 | assert(job->dev == dev::GPU); 112 | 113 | if (job->type == GpuJob::DRAW_JOB) { 114 | pending_draw_jobs.push_back(job); 115 | } 116 | 117 | if (job->type == GpuJob::TILE_JOB) { 118 | pending_tile_jobs.push_back(job); 119 | } 120 | 121 | if (job->type == GpuJob::MISC_JOB) { 122 | pending_misc_jobs.push_back(job); 123 | } 124 | } 125 | 126 | struct cmp_t { 127 | cmp_t(int width) : width(width) {} 128 | int width; 129 | bool operator()(GpuJobPtr a, GpuJobPtr b) 130 | { 131 | return (a->y * width + a->x) < (b->y * width + b->x); 132 | } 133 | }; 134 | 135 | // 136 | std::sort( 137 | pending_tile_jobs.begin(), 138 | pending_tile_jobs.end(), 139 | cmp_t(current_scene->width) 140 | ); 141 | 142 | gpu_queue.insert( 143 | gpu_queue.end(), 144 | pending_draw_jobs.begin(), 145 | pending_draw_jobs.end() 146 | ); 147 | 148 | gpu_queue.insert( 149 | gpu_queue.end(), 150 | pending_tile_jobs.begin(), 151 | pending_tile_jobs.end() 152 | ); 153 | 154 | gpu_queue.insert( 155 | gpu_queue.end(), 156 | pending_misc_jobs.begin(), 157 | pending_misc_jobs.end() 158 | ); 159 | 160 | // 161 | DPRINTF(ScheduleEvent, "Loaded %lu CPU jobs.\n", cpu_queue.size()); 162 | DPRINTF(ScheduleEvent, "Loaded %lu GPU jobs.\n", gpu_queue.size()); 163 | 164 | next_scene_id++; 165 | } 166 | 167 | } // end namespace schedular 168 | } // end namespace analyzer 169 | } // end namespace gltracesim 170 | 171 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/fcfs.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_SCHEDULAR_FCFS_HH__ 2 | #define __GLTRACESIM_ANALYZER_SCHEDULAR_FCFS_HH__ 3 | 4 | #include "job.hh" 5 | #include "scene.hh" 6 | #include "frame.hh" 7 | 8 | #include "analyzer/schedular/base.hh" 9 | 10 | namespace gltracesim { 11 | namespace analyzer { 12 | namespace schedular { 13 | 14 | class FCFSSchedular : public Schedular 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Schedular 21 | */ 22 | FCFSSchedular(const Json::Value ¶ms); 23 | 24 | /** 25 | * @brief ~Schedular 26 | */ 27 | virtual ~FCFSSchedular(); 28 | 29 | public: 30 | 31 | /** 32 | * @brief get_next_cpu_job 33 | * @param core_id 34 | * @return 35 | */ 36 | virtual GpuJobPtr get_next_cpu_job(int core_id); 37 | 38 | /** 39 | * @brief get_next_gpu_job 40 | * @param core_id 41 | * @return 42 | */ 43 | virtual GpuJobPtr get_next_gpu_job(int core_id); 44 | 45 | /** 46 | * @brief start_new_frame 47 | */ 48 | virtual void start_new_frame(int frame_id); 49 | 50 | /** 51 | * @brief start_new_scene 52 | */ 53 | virtual void start_new_scene(int frame_id, int scene_id); 54 | 55 | protected: 56 | 57 | /** 58 | * @brief scene_barrier_id 59 | */ 60 | uint64_t next_scene_id; 61 | 62 | /** 63 | * @brief frame_barrier_id 64 | */ 65 | uint64_t next_frame_id; 66 | 67 | /** 68 | * @brief current_scene 69 | */ 70 | ScenePtr current_scene; 71 | 72 | /** 73 | * @brief current_frame 74 | */ 75 | FramePtr current_frame; 76 | 77 | /** 78 | * @brief job_queue 79 | */ 80 | std::deque gpu_queue; 81 | 82 | /** 83 | * @brief cpu_queue 84 | */ 85 | std::deque cpu_queue; 86 | 87 | }; 88 | 89 | 90 | } // end namespace schedular 91 | } // end namespace analyzer 92 | } // end namespace gltracesim 93 | 94 | #endif // __GLTRACESIM_ANALYZER_SCHEDULAR_FCFS_HH__ 95 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/file.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug_impl.hh" 3 | 4 | #include "analyzer/schedular/schedule.pb.h" 5 | 6 | #include "analyzer/trace_manager.hh" 7 | #include "analyzer/schedular/file.hh" 8 | 9 | namespace gltracesim { 10 | namespace analyzer { 11 | namespace schedular { 12 | 13 | FileSchedular::FileSchedular(const Json::Value ¶ms) 14 | : Schedular(params), next_scene_id(0), next_frame_id(0) 15 | { 16 | // 17 | DPRINTF(Init, "FileSchedular.\n"); 18 | 19 | // 20 | ProtoMessage::PacketHeader hdr; 21 | 22 | // 23 | pb.schedule = new ProtoInputStream( 24 | p["schedule"].asString() 25 | ); 26 | 27 | // 28 | pb.cluster = new ProtoInputStream( 29 | p["clusters"].asString() 30 | ); 31 | 32 | // 33 | pb.schedule->read(hdr); 34 | pb.cluster->read(hdr); 35 | 36 | // 37 | gltracesim::proto::Schedule schedule; 38 | 39 | // 40 | if (pb.schedule->read(schedule) == false) { 41 | assert(0); 42 | } 43 | 44 | while (true) { 45 | 46 | // 47 | gltracesim::proto::Cluster cluster; 48 | 49 | // 50 | if (pb.cluster->read(cluster) == false) { 51 | break; 52 | } 53 | 54 | // 55 | FramePtr frame = FramePtr(new Frame(info.id())); 56 | 57 | // 58 | for (int i = 0; i < info.scene_size(); ++i) { 59 | frame->add_scene(info.scene(i)); 60 | } 61 | 62 | // 63 | frames.push_back(frame); 64 | } 65 | } 66 | 67 | FileSchedular::~FileSchedular() 68 | { 69 | 70 | } 71 | 72 | GpuJobPtr 73 | FileSchedular::get_next_cpu_job(int core_id) 74 | { 75 | if (cpu_queue.empty()) { 76 | return NULL; 77 | } 78 | 79 | // 80 | auto job = cpu_queue.front(); 81 | // 82 | cpu_queue.pop_front(); 83 | // 84 | return job; 85 | } 86 | 87 | GpuJobPtr 88 | FileSchedular::get_next_gpu_job(int core_id) 89 | { 90 | if (gpu_queue.empty()) { 91 | return NULL; 92 | } 93 | 94 | // 95 | auto job = gpu_queue.front(); 96 | // 97 | gpu_queue.pop_front(); 98 | // 99 | DPRINTF(ScheduleEvent, "GPU Job: %d [x: %d, y: %d].\n", 100 | job->id, job->x, job->y 101 | ); 102 | // 103 | return job; 104 | } 105 | 106 | void 107 | FileSchedular::start_new_frame(int frame_id) 108 | { 109 | assert(cpu_queue.empty()); 110 | assert(gpu_queue.empty()); 111 | 112 | // 113 | current_frame = trace_manager->get_frame(next_frame_id); 114 | 115 | DPRINTF(ScheduleEvent, "New Frame: %d [scenes: %lu].\n", 116 | current_frame->id, 117 | current_frame->scenes.size() 118 | ); 119 | 120 | // 121 | assert(current_frame->id == next_frame_id); 122 | 123 | next_frame_id++; 124 | } 125 | 126 | void 127 | FileSchedular::start_new_scene(int frame_id, int scene_id) 128 | { 129 | assert(cpu_queue.empty()); 130 | assert(gpu_queue.empty()); 131 | 132 | // 133 | current_scene = trace_manager->get_scene(next_scene_id); 134 | 135 | DPRINTF(ScheduleEvent, "New Scene: %d [frame: %d, width: %d, height: %d, jobs: %lu].\n", 136 | current_scene->id, 137 | current_scene->frame_id, 138 | current_scene->width, 139 | current_scene->height, 140 | current_scene->jobs.size() 141 | ); 142 | 143 | next_scene_id++; 144 | } 145 | 146 | } // end namespace schedular 147 | } // end namespace analyzer 148 | } // end namespace gltracesim 149 | 150 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/file.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_SCHEDULAR_FILE_HH__ 2 | #define __GLTRACESIM_ANALYZER_SCHEDULAR_FILE_HH__ 3 | 4 | #include "job.hh" 5 | #include "scene.hh" 6 | #include "frame.hh" 7 | 8 | #include "analyzer/schedular/base.hh" 9 | 10 | namespace gltracesim { 11 | namespace analyzer { 12 | namespace schedular { 13 | 14 | class FileSchedular : public Schedular 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Schedular 21 | */ 22 | FileSchedular(const Json::Value ¶ms); 23 | 24 | /** 25 | * @brief ~Schedular 26 | */ 27 | virtual ~FileSchedular(); 28 | 29 | public: 30 | 31 | /** 32 | * @brief get_next_cpu_job 33 | * @param core_id 34 | * @return 35 | */ 36 | virtual GpuJobPtr get_next_cpu_job(int core_id); 37 | 38 | /** 39 | * @brief get_next_gpu_job 40 | * @param core_id 41 | * @return 42 | */ 43 | virtual GpuJobPtr get_next_gpu_job(int core_id); 44 | 45 | /** 46 | * @brief start_new_frame 47 | */ 48 | virtual void start_new_frame(int frame_id); 49 | 50 | /** 51 | * @brief start_new_scene 52 | */ 53 | virtual void start_new_scene(int frame_id, int scene_id); 54 | 55 | private: 56 | 57 | /** 58 | * @brief The proto_t struct 59 | */ 60 | struct proto_t { 61 | // 62 | ProtoInputStream *schedule; 63 | // 64 | ProtoInputStream *cluster; 65 | } pb; 66 | 67 | 68 | protected: 69 | 70 | struct Cluster { 71 | // 72 | uint32_t id; 73 | // 74 | std::vector jobs; 75 | }; 76 | 77 | struct Schedule { 78 | // 79 | uint32_t id; 80 | // 81 | uint32_t frame_id; 82 | // 83 | uint32_t scene_id; 84 | // 85 | std::vector clusters; 86 | }; 87 | 88 | /** 89 | * @brief scene_barrier_id 90 | */ 91 | uint64_t next_scene_id; 92 | 93 | /** 94 | * @brief frame_barrier_id 95 | */ 96 | uint64_t next_frame_id; 97 | 98 | /** 99 | * @brief current_scene 100 | */ 101 | ScenePtr current_scene; 102 | 103 | /** 104 | * @brief current_frame 105 | */ 106 | FramePtr current_frame; 107 | 108 | /** 109 | * @brief job_queue 110 | */ 111 | std::deque gpu_queue; 112 | 113 | /** 114 | * @brief cpu_queue 115 | */ 116 | std::deque cpu_queue; 117 | 118 | 119 | 120 | }; 121 | 122 | 123 | } // end namespace schedular 124 | } // end namespace analyzer 125 | } // end namespace gltracesim 126 | 127 | #endif // __GLTRACESIM_ANALYZER_SCHEDULAR_FILE_HH__ 128 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/random.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug_impl.hh" 3 | 4 | #include "analyzer/trace_manager.hh" 5 | #include "analyzer/schedular/random.hh" 6 | 7 | namespace gltracesim { 8 | namespace analyzer { 9 | namespace schedular { 10 | 11 | RandomSchedular::RandomSchedular(const Json::Value ¶ms) 12 | : Schedular(params), next_scene_id(0), next_frame_id(0) 13 | { 14 | 15 | } 16 | 17 | RandomSchedular::~RandomSchedular() 18 | { 19 | 20 | } 21 | 22 | GpuJobPtr 23 | RandomSchedular::get_next_cpu_job(int core_id) 24 | { 25 | if (cpu_queue.empty()) { 26 | return NULL; 27 | } 28 | 29 | // 30 | auto job = cpu_queue.front(); 31 | // 32 | cpu_queue.pop_front(); 33 | // 34 | return job; 35 | } 36 | 37 | GpuJobPtr 38 | RandomSchedular::get_next_gpu_job(int core_id) 39 | { 40 | if (gpu_queue.empty()) { 41 | return NULL; 42 | } 43 | 44 | // 45 | auto job = gpu_queue.front(); 46 | // 47 | gpu_queue.pop_front(); 48 | // 49 | DPRINTF(ScheduleEvent, "GPU Job: %d [x: %d, y: %d].\n", 50 | job->id, job->x, job->y 51 | ); 52 | // 53 | return job; 54 | } 55 | 56 | void 57 | RandomSchedular::start_new_frame(int frame_id) 58 | { 59 | assert(cpu_queue.empty()); 60 | assert(gpu_queue.empty()); 61 | 62 | // 63 | current_frame = trace_manager->get_frame(next_frame_id); 64 | 65 | DPRINTF(ScheduleEvent, "New Frame: %d [scenes: %lu].\n", 66 | current_frame->id, 67 | current_frame->scenes.size() 68 | ); 69 | 70 | // 71 | assert(current_frame->id == next_frame_id); 72 | 73 | next_frame_id++; 74 | } 75 | 76 | void 77 | RandomSchedular::start_new_scene(int frame_id, int scene_id) 78 | { 79 | assert(cpu_queue.empty()); 80 | assert(gpu_queue.empty()); 81 | 82 | // 83 | current_scene = trace_manager->get_scene(next_scene_id); 84 | 85 | DPRINTF(ScheduleEvent, "New Scene: %d [frame: %d, width: %d, height: %d, jobs: %lu].\n", 86 | current_scene->id, 87 | current_scene->frame_id, 88 | current_scene->width, 89 | current_scene->height, 90 | current_scene->jobs.size() 91 | ); 92 | 93 | std::vector pending_jobs; 94 | 95 | // Fill job queues 96 | for (auto job_id: current_scene->jobs) { 97 | // 98 | GpuJobPtr job = trace_manager->get_job(current_scene->frame_id, job_id); 99 | 100 | // 101 | if (job->dev == dev::CPU) { 102 | // 103 | cpu_queue.push_back(job); 104 | // 105 | continue; 106 | } 107 | 108 | // GPU 109 | assert(job->dev == dev::GPU); 110 | 111 | if (job->type == GpuJob::DRAW_JOB) { 112 | pending_jobs.push_back(job); 113 | } 114 | 115 | if (job->type == GpuJob::TILE_JOB) { 116 | pending_jobs.push_back(job); 117 | } 118 | 119 | if (job->type == GpuJob::MISC_JOB) { 120 | pending_jobs.push_back(job); 121 | } 122 | } 123 | 124 | // 125 | std::random_shuffle( 126 | pending_jobs.begin(), 127 | pending_jobs.end() 128 | ); 129 | 130 | gpu_queue.insert( 131 | gpu_queue.end(), 132 | pending_jobs.begin(), 133 | pending_jobs.end() 134 | ); 135 | 136 | // 137 | DPRINTF(ScheduleEvent, "Loaded %lu CPU jobs.\n", cpu_queue.size()); 138 | DPRINTF(ScheduleEvent, "Loaded %lu GPU jobs.\n", gpu_queue.size()); 139 | 140 | next_scene_id++; 141 | } 142 | 143 | } // end namespace schedular 144 | } // end namespace analyzer 145 | } // end namespace gltracesim 146 | 147 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/random.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_SCHEDULAR_RANDOM_HH__ 2 | #define __GLTRACESIM_ANALYZER_SCHEDULAR_RANDOM_HH__ 3 | 4 | #include "job.hh" 5 | #include "scene.hh" 6 | #include "frame.hh" 7 | 8 | #include "analyzer/schedular/base.hh" 9 | 10 | namespace gltracesim { 11 | namespace analyzer { 12 | namespace schedular { 13 | 14 | class RandomSchedular : public Schedular 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Schedular 21 | */ 22 | RandomSchedular(const Json::Value ¶ms); 23 | 24 | /** 25 | * @brief ~Schedular 26 | */ 27 | virtual ~RandomSchedular(); 28 | 29 | public: 30 | 31 | /** 32 | * @brief get_next_cpu_job 33 | * @param core_id 34 | * @return 35 | */ 36 | virtual GpuJobPtr get_next_cpu_job(int core_id); 37 | 38 | /** 39 | * @brief get_next_gpu_job 40 | * @param core_id 41 | * @return 42 | */ 43 | virtual GpuJobPtr get_next_gpu_job(int core_id); 44 | 45 | /** 46 | * @brief start_new_frame 47 | */ 48 | virtual void start_new_frame(int frame_id); 49 | 50 | /** 51 | * @brief start_new_scene 52 | */ 53 | virtual void start_new_scene(int frame_id, int scene_id); 54 | 55 | protected: 56 | 57 | /** 58 | * @brief scene_barrier_id 59 | */ 60 | uint64_t next_scene_id; 61 | 62 | /** 63 | * @brief frame_barrier_id 64 | */ 65 | uint64_t next_frame_id; 66 | 67 | /** 68 | * @brief current_scene 69 | */ 70 | ScenePtr current_scene; 71 | 72 | /** 73 | * @brief current_frame 74 | */ 75 | FramePtr current_frame; 76 | 77 | /** 78 | * @brief job_queue 79 | */ 80 | std::deque gpu_queue; 81 | 82 | /** 83 | * @brief cpu_queue 84 | */ 85 | std::deque cpu_queue; 86 | 87 | }; 88 | 89 | 90 | } // end namespace schedular 91 | } // end namespace analyzer 92 | } // end namespace gltracesim 93 | 94 | #endif // __GLTRACESIM_ANALYZER_SCHEDULAR_RANDOM_HH__ 95 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/schedule.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | enum SchedulePolicy { 6 | SCHEDULE_FCFS = 0; 7 | SCHEDULE_STRICT_ORDER = 1; 8 | } 9 | 10 | message Cluster { 11 | // Cluster ID 12 | uint32 id = 1; 13 | // 14 | SchedulePolicy policy = 2; 15 | // Jobs 16 | repeated uint32 job = 3; 17 | // 18 | uint32 footprint = 4; 19 | } 20 | 21 | message Schedule { 22 | // Schdule ID 23 | uint32 id = 1; 24 | // Frame number 25 | uint32 frame_id = 2; 26 | // Scene number 27 | uint32 scene_id = 3; 28 | // Clusters 29 | repeated uint32 cluster = 4; 30 | } 31 | 32 | message JobSchedule { 33 | // Schdule ID 34 | uint32 id = 1; 35 | // Frame number 36 | uint32 core_id = 2; 37 | } 38 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/schedular/z.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_SCHEDULAR_Z_HH__ 2 | #define __GLTRACESIM_ANALYZER_SCHEDULAR_Z_HH__ 3 | 4 | #include "job.hh" 5 | #include "scene.hh" 6 | #include "frame.hh" 7 | 8 | #include "analyzer/schedular/base.hh" 9 | 10 | namespace gltracesim { 11 | namespace analyzer { 12 | namespace schedular { 13 | 14 | class ZSchedular : public Schedular 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Schedular 21 | */ 22 | ZSchedular(const Json::Value ¶ms); 23 | 24 | /** 25 | * @brief ~Schedular 26 | */ 27 | virtual ~ZSchedular(); 28 | 29 | public: 30 | 31 | /** 32 | * @brief get_next_cpu_job 33 | * @param core_id 34 | * @return 35 | */ 36 | virtual GpuJobPtr get_next_cpu_job(int core_id); 37 | 38 | /** 39 | * @brief get_next_gpu_job 40 | * @param core_id 41 | * @return 42 | */ 43 | virtual GpuJobPtr get_next_gpu_job(int core_id); 44 | 45 | /** 46 | * @brief start_new_frame 47 | */ 48 | virtual void start_new_frame(int frame_id); 49 | 50 | /** 51 | * @brief start_new_scene 52 | */ 53 | virtual void start_new_scene(int frame_id, int scene_id); 54 | 55 | private: 56 | 57 | /** 58 | * @brief schedule_tiles 59 | * @param x 60 | * @param y 61 | * @param size 62 | * @param order 63 | */ 64 | void schedule_tiles(int x, int y, int size, int order); 65 | 66 | protected: 67 | 68 | // A B 69 | // C D 70 | enum TileOrder { 71 | TILE_ACBD, 72 | TILE_CADB, 73 | }; 74 | 75 | /** 76 | * @brief z_width 77 | */ 78 | int z_width; 79 | 80 | protected: 81 | 82 | /** 83 | * @brief scene_barrier_id 84 | */ 85 | uint64_t next_scene_id; 86 | 87 | /** 88 | * @brief frame_barrier_id 89 | */ 90 | uint64_t next_frame_id; 91 | 92 | /** 93 | * @brief current_scene 94 | */ 95 | ScenePtr current_scene; 96 | 97 | /** 98 | * @brief current_frame 99 | */ 100 | FramePtr current_frame; 101 | 102 | /** 103 | * @brief job_queue 104 | */ 105 | std::deque gpu_draw_queue; 106 | 107 | /** 108 | * @brief job_queue 109 | */ 110 | std::deque gpu_tile_queue; 111 | 112 | /** 113 | * @brief job_queue 114 | */ 115 | std::deque gpu_misc_queue; 116 | 117 | /** 118 | * @brief coord 119 | */ 120 | typedef std::pair coord_t; 121 | 122 | /** 123 | * @brief job_map 124 | */ 125 | std::map pending_tile_jobs; 126 | 127 | /** 128 | * @brief cpu_queue 129 | */ 130 | std::deque cpu_queue; 131 | 132 | }; 133 | 134 | 135 | } // end namespace schedular 136 | } // end namespace analyzer 137 | } // end namespace gltracesim 138 | 139 | #endif // __GLTRACESIM_ANALYZER_SCHEDULAR_Z_HH__ 140 | -------------------------------------------------------------------------------- /gltracesim/src/analyzer/trace_manager.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYZER_TRACE_MANAGER_HH__ 2 | #define __GLTRACESIM_ANALYZER_TRACE_MANAGER_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "frame.hh" 9 | #include "scene.hh" 10 | #include "job.hh" 11 | 12 | namespace gltracesim { 13 | 14 | class TraceManager { 15 | 16 | public: 17 | 18 | /** 19 | * @brief TraceManager 20 | * @param params 21 | */ 22 | TraceManager(const Json::Value ¶ms); 23 | 24 | /** 25 | * 26 | */ 27 | ~TraceManager(); 28 | 29 | private: 30 | 31 | /** 32 | * @brief The proto_t struct 33 | */ 34 | struct proto_t { 35 | // 36 | ProtoInputStream *frames; 37 | // 38 | ProtoInputStream *scenes; 39 | // 40 | ProtoInputStream *jobs; 41 | // 42 | ProtoInputStream *resources; 43 | } pb; 44 | 45 | public: 46 | 47 | /** 48 | * @brief get_frame 49 | * @param id 50 | * @return 51 | */ 52 | FramePtr get_frame(size_t id); 53 | 54 | /** 55 | * @brief get_scene 56 | * @param id 57 | * @return 58 | */ 59 | ScenePtr get_scene(size_t id); 60 | 61 | /** 62 | * @brief get_job 63 | * @param id 64 | * @return 65 | */ 66 | GpuJobPtr get_job(size_t frame_id, size_t id); 67 | 68 | /** 69 | * @brief get_resource 70 | * @param id 71 | * @return 72 | */ 73 | GpuResourcePtr get_resource(size_t id); 74 | 75 | private: 76 | 77 | /** 78 | * @brief prefetch_fs_metadata 79 | */ 80 | void prefetch_fs_metadata(); 81 | 82 | /** 83 | * @brief fs_prefetcher 84 | */ 85 | std::thread *fs_prefetcher; 86 | 87 | private: 88 | 89 | 90 | /** 91 | * @brief last_frame 92 | */ 93 | FramePtr last_frame; 94 | 95 | /** 96 | * @brief last_frame 97 | */ 98 | ScenePtr last_scene; 99 | 100 | /** 101 | * @brief frame_id 102 | */ 103 | size_t frame_id; 104 | 105 | /** 106 | * @brief scene_id 107 | */ 108 | size_t scene_id; 109 | 110 | /** 111 | * @brief job_scene_id 112 | */ 113 | size_t job_frame_id; 114 | 115 | /** 116 | * @brief jobs within last scene 117 | */ 118 | std::unordered_map jobs; 119 | 120 | /** 121 | * @brief resource_id 122 | */ 123 | size_t resource_id; 124 | 125 | }; 126 | 127 | /** 128 | * @brief SystemPtr 129 | */ 130 | typedef std::unique_ptr TraceManagerPtr; 131 | 132 | /** 133 | * @brief system 134 | */ 135 | extern TraceManagerPtr trace_manager; 136 | 137 | } // end namespace gltracesim 138 | 139 | #endif // __GLTRACESIM_ANALYZER_TRACE_MANAGER_HH__ 140 | -------------------------------------------------------------------------------- /gltracesim/src/debug.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug.hh" 3 | 4 | namespace gltracesim { 5 | 6 | const char* 7 | Debug::debug_flag_names[] = { 8 | "Init", 9 | "Info", 10 | "Warn", 11 | "Error", 12 | "OpenGL", 13 | "AutoPrune", 14 | "PinMemOp", 15 | "ScheduleEvent", 16 | "SyncEvent", 17 | "GpuCoreMemOp", 18 | "GpuOffCoreMemOp", 19 | "GpuFlushEvent", 20 | "GpuDrawVboEvent", 21 | "GpuTileEvent", 22 | "GpuSceneEvent", 23 | "GpuFrameEvent", 24 | "GpuResourceEvent", 25 | "GpuThreadEvent", 26 | "Prefetcher", 27 | "VirtualMemoryManager", 28 | }; 29 | 30 | const char* 31 | Debug::get_event_name(int event) 32 | { 33 | return Debug::debug_flag_names[event]; 34 | } 35 | 36 | Mutex Debug::mtx; 37 | bool Debug::enabled; 38 | Debug::DebugLevel Debug::level; 39 | bool Debug::flags[Debug::NUM_DEBUG_FLAGS]; 40 | std::vector Debug::id_flags; 41 | 42 | int 43 | find_flag(const std::string &flag) 44 | { 45 | for (int i = 0; i < Debug::NUM_DEBUG_FLAGS; ++i) { 46 | if (flag == Debug::get_event_name(i)) { 47 | return i; 48 | } 49 | } 50 | 51 | return -1; 52 | } 53 | 54 | void 55 | Debug::init(const Json::Value ¶ms) 56 | { 57 | // 58 | Debug::enabled = params.get("enable", false).asBool(); 59 | Debug::level = DebugLevel(params.get("level", Normal).asInt()); 60 | 61 | // 62 | std::set flags; 63 | for (unsigned i = 0; i < params["flags"].size(); ++i) { 64 | char *endptr; 65 | 66 | int id_flag = std::strtol( 67 | params["flags"][i].asCString(), 68 | &endptr, 69 | 10 70 | ); 71 | 72 | id_flag += NUM_DEBUG_FLAGS; 73 | 74 | if (*endptr == '\0') { 75 | id_flags.resize(id_flag + 1, false); 76 | id_flags[id_flag] = true; 77 | } else { 78 | flags.insert(params["flags"][i].asCString()); 79 | } 80 | } 81 | 82 | // 83 | bool all = flags.count("All"); 84 | // 85 | for (size_t i = 0; i < NUM_DEBUG_FLAGS; ++i) { 86 | Debug::flags[i] = all || flags.count(Debug::get_event_name(i)); 87 | } 88 | } 89 | 90 | void 91 | Debug::set_flag(DebugFlag flag) 92 | { 93 | Debug::flags[flag] = 1; 94 | } 95 | 96 | } // end namespace gltracesim 97 | 98 | -------------------------------------------------------------------------------- /gltracesim/src/debug.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_DEBUG_HH__ 2 | #define __GLTRACESIM_DEBUG_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "util/cflags.hh" 11 | #include "util/threads.hh" 12 | 13 | namespace gltracesim { 14 | 15 | class Debug 16 | { 17 | 18 | public: 19 | 20 | /** 21 | * @brief The DebugFlag enum 22 | */ 23 | enum DebugFlag 24 | { 25 | Init = 0, 26 | Info, 27 | Warn, 28 | Error, 29 | OpenGL, 30 | AutoPrune, 31 | PinMemOp, 32 | ScheduleEvent, 33 | SyncEvent, 34 | GpuCoreMemOp, 35 | GpuOffCoreMemOp, 36 | GpuFlushEvent, 37 | GpuDrawVboEvent, 38 | GpuTileEvent, 39 | GpuSceneEvent, 40 | GpuFrameEvent, 41 | GpuResourceEvent, 42 | GpuThreadEvent, 43 | Prefetcher, 44 | VirtualMemoryManager, 45 | NUM_DEBUG_FLAGS 46 | }; 47 | 48 | /** 49 | * @brief The DebugFlag enum 50 | */ 51 | enum DebugLevel 52 | { 53 | Normal = 0, 54 | Verbose, 55 | SuperVerbose, 56 | NUM_DEBUG_LEVELS 57 | }; 58 | 59 | /** 60 | * @brief init 61 | */ 62 | static void init(const Json::Value ¶ms); 63 | 64 | /** 65 | * @brief is_enabled 66 | * @return 67 | */ 68 | static bool is_enabled(); 69 | 70 | /** 71 | * @brief is_enabled 72 | * @return 73 | */ 74 | static DebugLevel get_level(); 75 | 76 | /** 77 | * @brief is_enabled 78 | * @return 79 | */ 80 | static void turn_on(); 81 | 82 | /** 83 | * @brief debug 84 | * @param flag 85 | * @return 86 | */ 87 | static bool debug(DebugFlag flag); 88 | 89 | /** 90 | * @brief debug 91 | * @param flag 92 | * @return 93 | */ 94 | static bool debug(int flag); 95 | 96 | /** 97 | * @brief set_flag 98 | * @param flag 99 | */ 100 | static void set_flag(DebugFlag flag); 101 | 102 | /** 103 | * @brief get_event_name 104 | * @param flag 105 | * @return 106 | */ 107 | static const char* get_event_name(int event); 108 | 109 | /** 110 | * 111 | */ 112 | template 113 | static void printf( 114 | DebugFlag event, const std::string &name, 115 | const char *fmt, const Args &...args 116 | ); 117 | 118 | /** 119 | * 120 | */ 121 | template 122 | void printf( 123 | int id, const std::string &name, 124 | const char *fmt, const Args &...args 125 | ); 126 | 127 | private: 128 | 129 | /** 130 | * @brief mtx 131 | */ 132 | static Mutex mtx; 133 | 134 | /** 135 | * @brief enabled 136 | */ 137 | static bool enabled; 138 | 139 | /** 140 | * @brief enabled 141 | */ 142 | static DebugLevel level; 143 | 144 | /** 145 | * @brief Debug 146 | */ 147 | static bool flags[NUM_DEBUG_FLAGS]; 148 | 149 | /** 150 | * @brief Debug 151 | */ 152 | static std::vector id_flags; 153 | 154 | /** 155 | * @brief debug_flag_names 156 | */ 157 | static const char* debug_flag_names[NUM_DEBUG_FLAGS]; 158 | 159 | }; 160 | 161 | #ifdef __GLTRACESIM_DEBUG_ON__ 162 | 163 | #define DPRINTF(x, ...) do { \ 164 | if (_u(Debug::debug(Debug::x) && Debug::is_enabled())) { \ 165 | Debug::printf(Debug::x, __FILE__, __VA_ARGS__); \ 166 | } \ 167 | } while (0) 168 | 169 | #define LDPRINTF(l, x, ...) do { \ 170 | if (_u(Debug::debug(Debug::x) && l <= Debug::get_level() && Debug::is_enabled())) { \ 171 | Debug::printf(Debug::x, __FILE__, __VA_ARGS__); \ 172 | } \ 173 | } while (0) 174 | 175 | #define IDPRINTF(id, ...) do { \ 176 | if (_u(Debug::debug(id) && Debug::is_enabled())) { \ 177 | Debug::printf(id, __FILE__, __VA_ARGS__); \ 178 | } \ 179 | } while (0) 180 | 181 | #define LIDPRINTF(l, id, ...) do { \ 182 | if (_u(Debug::debug(id) && l <= Debug::get_level() && Debug::is_enabled())) { \ 183 | Debug::printf(id, __FILE__, __VA_ARGS__); \ 184 | } \ 185 | } while (0) 186 | 187 | 188 | #else 189 | 190 | #define DPRINTF(x, ...) do {} while (0) 191 | 192 | #endif 193 | 194 | } // end namespace gltracesim 195 | 196 | #endif // __GLTRACESIM_DEBUG_HH__ 197 | -------------------------------------------------------------------------------- /gltracesim/src/debug_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_TRACE_IMPL_HH__ 2 | #define __GLTRACESIM_TRACE_IMPL_HH__ 3 | 4 | #include 5 | #include "debug.hh" 6 | #include "system.hh" 7 | 8 | namespace gltracesim { 9 | 10 | inline bool 11 | Debug::is_enabled() 12 | { 13 | return enabled; 14 | } 15 | 16 | inline Debug::DebugLevel 17 | Debug::get_level() 18 | { 19 | return level; 20 | } 21 | 22 | inline bool 23 | Debug::debug(DebugFlag flag) 24 | { 25 | return flags[flag]; 26 | } 27 | 28 | inline bool 29 | Debug::debug(int flag) 30 | { 31 | // 32 | int id_flag = NUM_DEBUG_FLAGS + flag; 33 | 34 | // 35 | return (id_flag < int(id_flags.size()) && id_flags[id_flag]); 36 | } 37 | 38 | template 39 | void 40 | Debug::printf( 41 | DebugFlag event, const std::string &name, 42 | const char *fmt, const Args &...args) 43 | { 44 | uint64_t tsc = 0; 45 | 46 | if (gltracesim::system) { 47 | tsc = gltracesim::system->get_tsc(); 48 | } 49 | 50 | mtx.lock(); 51 | ::printf("%14lu: <%s> ", tsc, Debug::debug_flag_names[event]); 52 | ::printf(fmt, args...); 53 | mtx.unlock(); 54 | } 55 | 56 | template 57 | void 58 | Debug::printf( 59 | int id, const std::string &name, 60 | const char *fmt, const Args &...args) 61 | { 62 | uint64_t tsc = 0; 63 | 64 | if (gltracesim::system) { 65 | tsc = gltracesim::system->get_tsc(); 66 | } 67 | 68 | mtx.lock(); 69 | ::printf("%14lu: ", tsc, id); 70 | ::printf(fmt, args...); 71 | mtx.unlock(); 72 | } 73 | 74 | } // end namespace gltracesim 75 | 76 | #endif // __GLTRACESIM_TRACE_IMPL_HH__ 77 | -------------------------------------------------------------------------------- /gltracesim/src/device.cc: -------------------------------------------------------------------------------- 1 | #include "device.hh" 2 | 3 | namespace gltracesim { 4 | namespace dev { 5 | 6 | const char* hardware_devices_names[] = { 7 | "CPU", 8 | "GPU" 9 | }; 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /gltracesim/src/device.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_DEV_HH__ 2 | #define __GLTRACESIM_DEV_HH__ 3 | 4 | namespace gltracesim { 5 | namespace dev { 6 | 7 | /** 8 | * @brief The ThreadMode enum 9 | */ 10 | enum HardwareDevice { 11 | CPU = 0, 12 | GPU, 13 | NumHardwareDevices 14 | }; 15 | 16 | extern const char* hardware_devices_names[]; 17 | 18 | inline const char* 19 | get_dev_name(int dev) { 20 | return hardware_devices_names[dev]; 21 | } 22 | 23 | } // end namespace dev 24 | } // end namespace gltracesim 25 | 26 | #endif // __GLTRACESIM_DEV_HH__ 27 | -------------------------------------------------------------------------------- /gltracesim/src/frame.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "frame.hh" 5 | 6 | #include "debug.hh" 7 | #include "debug_impl.hh" 8 | 9 | namespace gltracesim { 10 | 11 | Frame::Frame(uint16_t id) : id(id) 12 | { 13 | 14 | } 15 | 16 | Frame::~Frame() 17 | { 18 | 19 | } 20 | 21 | void 22 | Frame::dump_info(gltracesim::proto::FrameInfo *info) 23 | { 24 | // 25 | info->set_id(id); 26 | // 27 | for (auto scene_id: scenes) { 28 | info->add_scene(scene_id); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /gltracesim/src/frame.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_FRAME_HH__ 2 | #define __GLTRACESIM_FRAME_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "frame.pb.h" 10 | #include "device.hh" 11 | 12 | #include "util/timer.hh" 13 | 14 | namespace gltracesim { 15 | 16 | class Frame : public Timer 17 | { 18 | 19 | public: 20 | 21 | /** 22 | * @brief Frame 23 | */ 24 | Frame(uint16_t id); 25 | 26 | /** 27 | * 28 | */ 29 | ~Frame(); 30 | 31 | public: 32 | 33 | /** 34 | * @brief add_job 35 | * @param job_id 36 | */ 37 | void add_scene(size_t scene_id) { 38 | scenes.push_back(scene_id); 39 | } 40 | 41 | public: 42 | 43 | /** 44 | * @brief id 45 | */ 46 | uint16_t id; 47 | 48 | /** 49 | * @brief jobs 50 | */ 51 | std::vector scenes; 52 | 53 | public: 54 | 55 | /** 56 | * @brief dump_info 57 | * @param info 58 | */ 59 | virtual void dump_info(gltracesim::proto::FrameInfo *info); 60 | 61 | }; 62 | 63 | // 64 | typedef std::shared_ptr FramePtr; 65 | 66 | } // end namespace gltracesim 67 | 68 | 69 | #endif // __GLTRACESIM_FRAME_HH__ 70 | -------------------------------------------------------------------------------- /gltracesim/src/frame.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message FrameInfo { 6 | // Scene ID 7 | uint32 id = 1; 8 | // Scene ids 9 | repeated uint32 scene = 2; 10 | } 11 | -------------------------------------------------------------------------------- /gltracesim/src/gem5/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 'protoio.cc', 10 | 'trace.cc', 11 | ]]) 12 | 13 | # 14 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 15 | 'protoio.cc', 16 | 'trace.cc', 17 | ]]) 18 | 19 | PROTO_SOURCES = [ 20 | 'packet.proto', 21 | ] 22 | 23 | _env['proto'] = [ 24 | simulator.File(x) for x in PROTO_SOURCES 25 | ] 26 | 27 | # 28 | Return('_env') 29 | 30 | -------------------------------------------------------------------------------- /gltracesim/src/gem5/packet.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 ARM Limited 2 | // All rights reserved 3 | // 4 | // The license below extends only to copyright in the software and shall 5 | // not be construed as granting a license to any other intellectual 6 | // property including but not limited to intellectual property relating 7 | // to a hardware implementation of the functionality of the software 8 | // licensed hereunder. You may use the software subject to the license 9 | // terms below provided that you ensure that this notice is replicated 10 | // unmodified and in its entirety in all distributions of the software, 11 | // modified or unmodified, in source code or in binary form. 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are 15 | // met: redistributions of source code must retain the above copyright 16 | // notice, this list of conditions and the following disclaimer; 17 | // redistributions in binary form must reproduce the above copyright 18 | // notice, this list of conditions and the following disclaimer in the 19 | // documentation and/or other materials provided with the distribution; 20 | // neither the name of the copyright holders nor the names of its 21 | // contributors may be used to endorse or promote products derived from 22 | // this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | // 36 | // Authors: Andreas Hansson 37 | 38 | syntax = "proto2"; 39 | 40 | // Put all the generated messages in a namespace 41 | package ProtoMessage; 42 | 43 | // Packet header with the identifier describing what object captured 44 | // the trace, the version of this file format, and the tick frequency 45 | // for all the packet time stamps. 46 | message PacketHeader { 47 | required string obj_id = 1; 48 | optional uint32 ver = 2 [default = 0]; 49 | required uint64 tick_freq = 3; 50 | } 51 | 52 | // Each packet in the trace contains a tick (which can be translated 53 | // to absolute time using the frequency in the header), the command, 54 | // the address, and the size in bytes. The optional flags are used to 55 | // capture the request flags that convey information about 56 | // cacheability, if the packet is an instruction fetch or prefetch or 57 | // not, etc. An optional id field is added for generic use to identify 58 | // the packet or the "owner" of the packet. An example of the latter 59 | // is the sequential id of an instruction, or the master id etc. 60 | message Packet { 61 | required uint64 tick = 1; 62 | required uint32 cmd = 2; 63 | required uint64 addr = 3; 64 | required uint32 size = 4; 65 | optional uint32 flags = 5; 66 | optional uint64 pkt_id = 6; 67 | 68 | // Resource ID 69 | optional uint32 rsc_id = 100; 70 | // Parallel Job ID 71 | optional uint32 job_id = 101; 72 | // Device ID [ CPU, GPU ] 73 | optional uint32 dev_id = 102; 74 | } 75 | -------------------------------------------------------------------------------- /gltracesim/src/gem5/trace.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_TRACE_HH__ 2 | #define __GLTRACESIM_TRACE_HH__ 3 | 4 | #include 5 | 6 | #include "analyzer.hh" 7 | #include "gem5/protoio.hh" 8 | #include "gem5/packet.pb.h" 9 | 10 | #include "util/cflags.hh" 11 | 12 | #include 13 | 14 | namespace gltracesim { 15 | namespace gem5 { 16 | 17 | enum { 18 | // gem5: src/mem/packet.hh 19 | MemCmd_ReadReq = (0x1), 20 | MemCmd_WriteReq = (0x4), 21 | // 22 | NewFrameCMD = (0x1 << 10), 23 | SyncCMD = (0x2 << 10), 24 | SyncProvidesCMD = (0x3 << 10), 25 | SyncRequiresCMD = (0x4 << 10), 26 | SyncInsnCMD = (0x5 << 10), 27 | NewJobCMD = (0x6 << 10), 28 | EndJobCMD = (0x7 << 10), 29 | NewResourceCMD = (0x8 << 10), 30 | EndResourceCMD = (0x9 << 10), 31 | NewSceneCMD = (0xA << 10), 32 | EndSceneCMD = (0xB << 10), 33 | OpenGlCMD = (0xC << 10) 34 | }; 35 | 36 | class TraceGenerator : public Analyzer 37 | { 38 | 39 | public: 40 | 41 | /** 42 | * @brief Analyzer 43 | */ 44 | TraceGenerator(const Json::Value ¶ms, int id); 45 | 46 | /** 47 | * @brief ~Analyzer 48 | */ 49 | virtual ~TraceGenerator(); 50 | 51 | /** 52 | * @brief process 53 | * @param pkt 54 | */ 55 | virtual void process(const packet_t &pkt) = 0; 56 | 57 | /** 58 | * @brief start_new_frame 59 | */ 60 | virtual void start_new_frame(int frame_id) { /* do nothing */ } 61 | 62 | /** 63 | * @brief start_new_scene 64 | */ 65 | virtual void start_new_scene(int frame_id, int scene_id) { /* do nothing */ } 66 | 67 | protected: 68 | 69 | /** 70 | * @brief tick 71 | */ 72 | static size_t tick; 73 | 74 | }; 75 | 76 | class AddrTraceGenerator : public TraceGenerator 77 | { 78 | 79 | public: 80 | 81 | /** 82 | * @brief Analyzer 83 | */ 84 | AddrTraceGenerator(const Json::Value ¶ms, int id); 85 | 86 | /** 87 | * @brief ~Analyzer 88 | */ 89 | virtual ~AddrTraceGenerator(); 90 | 91 | /** 92 | * @brief process 93 | * @param pkt 94 | */ 95 | virtual void process(const packet_t &pkt); 96 | 97 | private: 98 | 99 | /** 100 | * @brief trace_file 101 | */ 102 | ProtoOutputStream* trace_file; 103 | 104 | }; 105 | 106 | class CmdTraceGenerator : public TraceGenerator 107 | { 108 | 109 | public: 110 | 111 | /** 112 | * @brief Analyzer 113 | */ 114 | CmdTraceGenerator(const Json::Value ¶ms, int id); 115 | 116 | /** 117 | * @brief ~Analyzer 118 | */ 119 | virtual ~CmdTraceGenerator(); 120 | 121 | /** 122 | * @brief process 123 | * @param pkt 124 | */ 125 | virtual void process(const packet_t &pkt); 126 | 127 | private: 128 | 129 | /** 130 | * @brief trace_file [ CPU | GPU ] 131 | */ 132 | std::array trace_file; 133 | }; 134 | 135 | } // end namespace gem5 136 | } // end namespace gltracesim 137 | 138 | #endif // __GLTRACESIM_TRACE_HH__ 139 | -------------------------------------------------------------------------------- /gltracesim/src/generator/SConscript: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | # 4 | Import('simulator') 5 | Import('analyzer') 6 | 7 | _env = {} 8 | 9 | # 10 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 11 | 'filter_cache.cc', 12 | 'buffer.cc', 13 | 'stop_timer.cc', 14 | ]]) 15 | 16 | # 17 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 18 | 19 | ]]) 20 | 21 | PROTO_SOURCES = [ 22 | 23 | ] 24 | 25 | _env['proto'] = [ 26 | simulator.File(x) for x in PROTO_SOURCES 27 | ] 28 | 29 | # 30 | Return('_env') 31 | 32 | -------------------------------------------------------------------------------- /gltracesim/src/generator/buffer.cc: -------------------------------------------------------------------------------- 1 | #include "generator/buffer.hh" 2 | 3 | namespace gltracesim { 4 | 5 | buffer_t::buffer_t() : pos(0) 6 | { 7 | // Do nothing 8 | } 9 | 10 | } // end namespace gltracesim 11 | -------------------------------------------------------------------------------- /gltracesim/src/generator/buffer.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_BUFFER_HH__ 2 | #define __GLTRACESIM_BUFFER_HH__ 3 | 4 | #include 5 | #include "packet.hh" 6 | 7 | namespace gltracesim { 8 | 9 | // Buffer size 10 | #define BUFFER_SIZE 4096 11 | 12 | // 13 | struct buffer_t 14 | { 15 | // 16 | buffer_t(); 17 | // 18 | uint64_t pos; 19 | // 20 | std::array data; 21 | }; 22 | 23 | } // end namespace gltracesim 24 | 25 | #endif // __GLTRACESIM_BUFFER_HH__ 26 | -------------------------------------------------------------------------------- /gltracesim/src/generator/filter_cache.cc: -------------------------------------------------------------------------------- 1 | #include "filter_cache.hh" 2 | #include "debug_impl.hh" 3 | 4 | namespace gltracesim { 5 | 6 | FilterCache::FilterCache(params_t *p) : Base(p), tick(0) 7 | { 8 | // 9 | DPRINTF(Init, "FilterCache [size: %lu, a: %lu, blk: %lu, sblk: %lu].\n", 10 | p->size, p->associativity, p->blk_size, p->sub_blk_size 11 | ); 12 | } 13 | 14 | void 15 | FilterCache::dump_stats(gltracesim::proto::CacheStats *cache_stats) 16 | { 17 | // 18 | cache_stats->set_id(params.id); 19 | 20 | // 21 | stats.dump(cache_stats); 22 | } 23 | 24 | void 25 | FilterCache::reset_stats() 26 | { 27 | stats.reset(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /gltracesim/src/generator/filter_cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_FILTER_CACHE_HH__ 2 | #define __GLTRACESIM_FILTER_CACHE_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "util/cache.hh" 10 | #include "util/cache_impl.hh" 11 | #include "stats/cache.hh" 12 | #include "stats/cache.pb.h" 13 | #include "stats/cache_impl.hh" 14 | 15 | #include "gltracesim.pb.h" 16 | 17 | namespace gltracesim { 18 | 19 | struct filter_cache_params_t : public cache_params_t 20 | { 21 | /** 22 | * @brief addr 23 | */ 24 | uint64_t id; 25 | 26 | /** 27 | * @brief addr 28 | */ 29 | bool filter_cache; 30 | 31 | /** 32 | * @brief fetch_on_wr_miss 33 | */ 34 | bool fetch_on_wr_miss; 35 | 36 | }; 37 | 38 | // 39 | struct filter_cache_entry_t : public cache_entry_t 40 | { 41 | /** 42 | * @brief paddr 43 | */ 44 | uint64_t paddr; 45 | }; 46 | 47 | // 48 | typedef Cache filter_cache_base_t; 49 | 50 | /** 51 | * @brief The FilterCache class 52 | */ 53 | class FilterCache : public filter_cache_base_t 54 | { 55 | 56 | public: 57 | 58 | // 59 | typedef filter_cache_base_t Base; 60 | 61 | // 62 | typedef filter_cache_params_t params_t; 63 | 64 | // 65 | typedef filter_cache_entry_t entry_t; 66 | 67 | public: 68 | 69 | /** 70 | * @brief stats 71 | */ 72 | gltracesim::stats::Cache stats; 73 | 74 | public: 75 | 76 | /** 77 | * @brief Cache 78 | * @param p 79 | */ 80 | FilterCache(params_t *p); 81 | 82 | public: 83 | 84 | /** 85 | * @brief dump_stats 86 | * @param c 87 | */ 88 | void dump_stats(gltracesim::proto::CacheStats *cache_stats); 89 | 90 | /** 91 | * @brief reset_stats 92 | */ 93 | void reset_stats(); 94 | 95 | public: 96 | 97 | /** 98 | * @brief tick 99 | */ 100 | size_t tick; 101 | 102 | }; 103 | 104 | // 105 | typedef std::shared_ptr FilterCachePtr; 106 | 107 | } // end namespace gltracesim 108 | 109 | #endif // __GLTRACESIM_FILTER_CACHE_HH__ 110 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 'analysis_queue.cc', 10 | 'filter_queue.cc', 11 | 'pipeline.cc', 12 | ]]) 13 | 14 | # 15 | Return('_env') 16 | 17 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/analysis_queue.cc: -------------------------------------------------------------------------------- 1 | #include "generator/pipeline/analysis_queue.hh" 2 | 3 | namespace gltracesim { 4 | namespace pipeline { 5 | 6 | AnalysisQueue::AnalysisQueue() : 7 | fout_buffer(&_data0), analysis_buffer(&_data1) 8 | { 9 | 10 | } 11 | 12 | AnalysisQueue::~AnalysisQueue() 13 | { 14 | 15 | } 16 | 17 | // 18 | void 19 | AnalysisQueue::add_work_thread(int tid) 20 | { 21 | // 22 | work_threads.push_back(work_thread_t()); 23 | 24 | // tid 25 | work_threads.back().tid = tid; 26 | } 27 | 28 | // 29 | void 30 | AnalysisQueue::add_work_item(int aid) 31 | { 32 | // 33 | work_items.push_back(aid); 34 | } 35 | 36 | // 37 | void 38 | AnalysisQueue::push(const packet_t &pkt) 39 | { 40 | // 41 | producer_mtx.lock(); 42 | 43 | // 44 | fout_buffer->data[fout_buffer->pos] = pkt; 45 | 46 | // 47 | ++fout_buffer->pos; 48 | 49 | // Buffer is full, need to process 50 | if (fout_buffer->pos >= fout_buffer->data.size()) { 51 | 52 | // Wait 53 | for (size_t i = 0; i < work_threads.size(); ++i) { 54 | // 55 | work_threads[i].done.wait(); 56 | // 57 | work_threads[i].done.clear(); 58 | } 59 | 60 | consumer_mtx.lock(); 61 | 62 | // 63 | rotate_buffers(); 64 | 65 | // 66 | job_queue.insert( 67 | job_queue.begin(), work_items.begin(), work_items.end() 68 | ); 69 | 70 | // Start consumers 71 | for (size_t i = 0; i < work_threads.size(); ++i) { 72 | work_threads[i].has_work.set(); 73 | } 74 | 75 | consumer_mtx.unlock(); 76 | } 77 | 78 | // 79 | producer_mtx.unlock(); 80 | } 81 | 82 | void 83 | AnalysisQueue::start() 84 | { 85 | // 86 | producer_mtx.lock(); 87 | 88 | // Push all analazers on work queue 89 | job_queue.insert( 90 | job_queue.begin(), work_items.begin(), work_items.end() 91 | ); 92 | 93 | // 94 | for (size_t i = 0; i < work_threads.size(); ++i) { 95 | work_threads[i].has_work.set(); 96 | } 97 | 98 | // 99 | producer_mtx.unlock(); 100 | } 101 | 102 | void 103 | AnalysisQueue::rotate_buffers() 104 | { 105 | // temp 106 | buffer_t *p = fout_buffer; 107 | // P <- A 108 | fout_buffer = analysis_buffer; 109 | // 110 | analysis_buffer = p; 111 | // 112 | fout_buffer->pos = 0; 113 | } 114 | 115 | int 116 | AnalysisQueue::pop(int timeout, int tid) 117 | { 118 | 119 | // 120 | if (work_threads[tid].has_work.wait(timeout) == false) { 121 | return -1; 122 | } 123 | 124 | // 125 | consumer_mtx.lock(); 126 | 127 | // No more jobs, clear state 128 | if (job_queue.empty()) { 129 | 130 | // No more work 131 | work_threads[tid].has_work.clear(); 132 | 133 | // Nothing alse todo 134 | work_threads[tid].done.set(); 135 | 136 | // 137 | consumer_mtx.unlock(); 138 | 139 | // 140 | return -1; 141 | } 142 | 143 | // 144 | int aid = job_queue.front(); 145 | 146 | // 147 | job_queue.pop_front(); 148 | 149 | // 150 | consumer_mtx.unlock(); 151 | 152 | // 153 | return aid; 154 | } 155 | 156 | void 157 | AnalysisQueue::signal_producer(int tid, int aid) 158 | { 159 | // 160 | consumer_mtx.lock(); 161 | 162 | // No more jobs, clear state 163 | if (job_queue.empty()) { 164 | // No more work 165 | work_threads[tid].has_work.clear(); 166 | // 167 | work_threads[tid].done.set(); 168 | } 169 | 170 | // 171 | consumer_mtx.unlock(); 172 | } 173 | 174 | void 175 | AnalysisQueue::wait() 176 | { 177 | // 178 | producer_mtx.lock(); 179 | 180 | for (size_t i = 0; i < work_threads.size(); ++i) { 181 | // 182 | work_threads[i].done.wait(); 183 | // 184 | work_threads[i].done.clear(); 185 | } 186 | 187 | // 188 | producer_mtx.unlock(); 189 | } 190 | 191 | } // end namespace pipeline 192 | } // end namespace gltracesim 193 | 194 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/analysis_queue.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ANALYSIS_QUEUE_HH__ 2 | #define __GLTRACESIM_ANALYSIS_QUEUE_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "pin.H" 9 | #include "util/threads.hh" 10 | #include "generator/buffer.hh" 11 | 12 | namespace gltracesim { 13 | namespace pipeline { 14 | 15 | /** 16 | * @brief The AnalysisQueue class 17 | * 18 | * Multiple procuders, single consumer queue. 19 | */ 20 | class AnalysisQueue { 21 | 22 | public: 23 | 24 | /** 25 | * @brief AnalysisQueue 26 | */ 27 | AnalysisQueue(); 28 | 29 | /** 30 | * @brief AnalysisQueue 31 | */ 32 | ~AnalysisQueue(); 33 | 34 | /** 35 | * @brief push 36 | * @param tid 37 | */ 38 | void add_work_thread(int tid); 39 | 40 | /** 41 | * @brief add_work_item 42 | * @param aid 43 | */ 44 | void add_work_item(int aid); 45 | 46 | /** 47 | * @brief push 48 | * @param tid 49 | */ 50 | void push(const packet_t &pkt); 51 | 52 | /** 53 | * @brief pop 54 | * @param timeout 55 | * @return 56 | */ 57 | int pop(int timeout, int tid); 58 | 59 | /** 60 | * @brief signal_producer 61 | * @param tid 62 | */ 63 | void signal_producer(int tid, int aid); 64 | 65 | /** 66 | * @brief wait 67 | * @param tid 68 | */ 69 | void start(); 70 | 71 | /** 72 | * @brief wait 73 | * @param tid 74 | */ 75 | void rotate_buffers(); 76 | 77 | /** 78 | * @brief wait 79 | * @param tid 80 | */ 81 | void wait(); 82 | 83 | /** 84 | * @brief front 85 | */ 86 | buffer_t *fout_buffer; 87 | buffer_t *analysis_buffer; 88 | 89 | private: 90 | 91 | /** 92 | * @brief mtx 93 | */ 94 | Mutex producer_mtx; 95 | 96 | /** 97 | * @brief mtx 98 | */ 99 | Mutex consumer_mtx; 100 | 101 | /** 102 | * @brief The work_thread_t struct 103 | */ 104 | struct work_thread_t { 105 | /** 106 | * @brief id 107 | */ 108 | int tid; 109 | 110 | /** 111 | * @brief has_work 112 | */ 113 | Semaphore has_work; 114 | 115 | /** 116 | * @brief done 117 | */ 118 | Semaphore done; 119 | }; 120 | 121 | /** 122 | * @brief signal 123 | */ 124 | std::vector work_threads; 125 | 126 | struct work_item_t { 127 | /** 128 | * @brief id 129 | */ 130 | int aid; 131 | }; 132 | 133 | /** 134 | * @brief analyzers 135 | */ 136 | std::vector work_items; 137 | 138 | /** 139 | * @brief job_queue 140 | */ 141 | std::deque job_queue; 142 | 143 | /** 144 | * @brief queue 145 | */ 146 | buffer_t _data0; 147 | buffer_t _data1; 148 | 149 | private: 150 | 151 | /** 152 | * @brief operator = 153 | * @param other 154 | */ 155 | void operator=(const AnalysisQueue &other) {} 156 | 157 | }; 158 | 159 | /** 160 | * @brief AnalysisQueuePtr 161 | */ 162 | typedef std::shared_ptr AnalysisQueuePtr; 163 | 164 | } // end namespace pipeline 165 | } // end namespace gltracesim 166 | 167 | #endif // __GLTRACESIM_ANALYSIS_QUEUE_HH__ 168 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/filter_queue.cc: -------------------------------------------------------------------------------- 1 | #include "generator/pipeline/filter_queue.hh" 2 | 3 | namespace gltracesim { 4 | namespace pipeline { 5 | 6 | // 7 | FilterQueue::FilterQueue() : 8 | gpu(&_data0), fin(&_data1) 9 | { 10 | 11 | } 12 | 13 | FilterQueue::~FilterQueue() 14 | { 15 | 16 | } 17 | 18 | 19 | void 20 | FilterQueue::push() 21 | { 22 | // 23 | consumer_has_work.set(); 24 | } 25 | 26 | bool 27 | FilterQueue::pop(int timeout) 28 | { 29 | 30 | // 31 | if (consumer_has_work.wait(timeout) == false) { 32 | return false; 33 | } 34 | 35 | consumer_has_work.clear(); 36 | 37 | // 38 | return true; 39 | } 40 | 41 | void 42 | FilterQueue::signal_producer() 43 | { 44 | // 45 | consumer_done.set(); 46 | } 47 | 48 | void 49 | FilterQueue::wait() { 50 | // 51 | consumer_done.wait(); 52 | // 53 | consumer_done.clear(); 54 | } 55 | 56 | void 57 | FilterQueue::rotate_buffers() 58 | { 59 | // temp 60 | buffer_t *p = gpu; 61 | 62 | // P <- A 63 | gpu = fin; 64 | // 65 | fin = p; 66 | 67 | // Start from beginning 68 | gpu->pos = 0; 69 | } 70 | 71 | } // end namespace pipeline 72 | } // end namespace gltracesim 73 | 74 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/filter_queue.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_FILTER_QUEUE_HH__ 2 | #define __GLTRACESIM_FILTER_QUEUE_HH__ 3 | 4 | #include 5 | 6 | #include "pin.H" 7 | #include "util/threads.hh" 8 | #include "generator/buffer.hh" 9 | 10 | namespace gltracesim { 11 | namespace pipeline { 12 | 13 | /** 14 | * @brief The FilterQueue class 15 | * 16 | * Single producer, single consumer queue. 17 | * 18 | */ 19 | class FilterQueue { 20 | 21 | public: 22 | 23 | /** 24 | * @brief FilterQueue 25 | */ 26 | FilterQueue(); 27 | 28 | /** 29 | * @brief FilterQueue 30 | */ 31 | ~FilterQueue(); 32 | 33 | /** 34 | * @brief push 35 | */ 36 | void push(); 37 | 38 | /** 39 | * @brief pop 40 | * @param timeout 41 | * @return 42 | */ 43 | bool pop(int timeout); 44 | 45 | /** 46 | * @brief signal_producer 47 | */ 48 | void signal_producer(); 49 | 50 | /** 51 | * @brief wait 52 | */ 53 | void wait(); 54 | 55 | /** 56 | * @brief rotate_buffers 57 | * 58 | * G -> FI -> G 59 | * 60 | */ 61 | void rotate_buffers(); 62 | 63 | // Pointers to pipeline stage buffer 64 | buffer_t *gpu; 65 | buffer_t *fin; 66 | 67 | private: 68 | 69 | // 70 | Semaphore consumer_has_work; 71 | 72 | // 73 | Semaphore consumer_done; 74 | 75 | private: 76 | 77 | // Storage 78 | buffer_t _data0; 79 | buffer_t _data1; 80 | 81 | private: 82 | 83 | /** 84 | * @brief operator = 85 | * @param other 86 | */ 87 | void operator=(const FilterQueue &other) {} 88 | 89 | }; 90 | 91 | /** 92 | * @brief AnalysisQueuePtr 93 | */ 94 | typedef std::shared_ptr FilterQueuePtr; 95 | 96 | } // end namespace pipeline 97 | } // end namespace gltracesim 98 | 99 | #endif // __GLTRACESIM_FILTER_QUEUE_HH__ 100 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/pipeline.cc: -------------------------------------------------------------------------------- 1 | #include "generator/pipeline/pipeline.hh" 2 | 3 | namespace gltracesim { 4 | namespace pipeline { 5 | 6 | Pipeline::Pipeline() : 7 | _num_gpu_threads(0), _num_filter_threads(0), _num_analysis_threads(0) 8 | { 9 | // 10 | analysis_queue = AnalysisQueuePtr(new AnalysisQueue()); 11 | } 12 | 13 | int 14 | Pipeline::add_gpu_thread() 15 | { 16 | // Allocate internal id 17 | int internal_tid = _num_gpu_threads++; 18 | 19 | // 20 | filter_queue[internal_tid] = FilterQueuePtr(new FilterQueue()); 21 | 22 | // GPU thread id 23 | return internal_tid; 24 | } 25 | 26 | int 27 | Pipeline::add_filter_thread() 28 | { 29 | // Allocate internal id 30 | int internal_tid = _num_filter_threads++; 31 | 32 | // GPU thread id 33 | return internal_tid; 34 | } 35 | 36 | 37 | void 38 | Pipeline::add_analyzer(int aid) 39 | { 40 | // 41 | analysis_queue->add_work_item(aid); 42 | } 43 | 44 | int 45 | Pipeline::add_analysis_thread() 46 | { 47 | // Allocate internal id 48 | int internal_tid = _num_analysis_threads++; 49 | 50 | // 51 | analysis_queue->add_work_thread(internal_tid); 52 | 53 | // GPU thread id 54 | return internal_tid; 55 | } 56 | 57 | void 58 | Pipeline::map_gpu_thread(int internal_tid, int external_tid) 59 | { 60 | // 61 | eid2gid_map[external_tid] = internal_tid; 62 | gid2eid_map[internal_tid] = external_tid; 63 | } 64 | 65 | void 66 | Pipeline::map_filter_thread(int internal_tid, int external_tid) 67 | { 68 | // 69 | eid2fid_map[external_tid] = internal_tid; 70 | fid2eid_map[internal_tid] = external_tid; 71 | } 72 | 73 | void 74 | Pipeline::map_analysis_thread(int internal_tid, int external_tid) 75 | { 76 | // 77 | eid2aid_map[external_tid] = internal_tid; 78 | aid2eid_map[internal_tid] = external_tid; 79 | } 80 | 81 | 82 | } // end namespace pipeline 83 | } // end namespace gltracesim 84 | 85 | -------------------------------------------------------------------------------- /gltracesim/src/generator/pipeline/pipeline.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_PIPELINE_PIPELINE_HH__ 2 | #define __GLTRACESIM_PIPELINE_PIPELINE_HH__ 3 | 4 | #include 5 | #include 6 | 7 | #include "generator/pipeline/filter_queue.hh" 8 | #include "generator/pipeline/analysis_queue.hh" 9 | 10 | namespace gltracesim { 11 | namespace pipeline { 12 | 13 | // Max number of threads (for std::array) 14 | #define MAX_THREADS 128 15 | 16 | // 17 | class Pipeline 18 | { 19 | 20 | public: 21 | 22 | /** 23 | * @brief Pipeline 24 | */ 25 | Pipeline(); 26 | 27 | // Size: Number of gpu threads 28 | std::array filter_queue; 29 | 30 | // Size: Number of analysis threads (fixed) 31 | AnalysisQueuePtr analysis_queue; 32 | 33 | // 34 | int num_gpu_threads() { return _num_gpu_threads; } 35 | int num_filter_threads() { return _num_filter_threads; } 36 | int num_anaysis_threads() { return _num_analysis_threads; } 37 | 38 | // 39 | int get_gid(int external_tid) { return eid2gid_map[external_tid]; } 40 | int get_fid(int external_tid) { return eid2fid_map[external_tid]; } 41 | int get_aid(int external_tid) { return eid2aid_map[external_tid]; } 42 | 43 | // 44 | int get_gtid(int internal_tid) { return gid2eid_map[internal_tid]; } 45 | int get_ftid(int internal_tid) { return fid2eid_map[internal_tid]; } 46 | int get_atid(int internal_tid) { return aid2eid_map[internal_tid]; } 47 | 48 | // 49 | void add_analyzer(int aid); 50 | 51 | // 52 | int add_gpu_thread(); 53 | int add_filter_thread(); 54 | int add_analysis_thread(); 55 | 56 | void map_gpu_thread(int gid, int external_tid); 57 | void map_filter_thread(int fid, int external_tid); 58 | void map_analysis_thread(int aid, int external_tid); 59 | 60 | private: 61 | 62 | // 63 | int _num_gpu_threads; 64 | int _num_filter_threads; 65 | int _num_analysis_threads; 66 | 67 | // Size: Number of threads 68 | std::array eid2gid_map; 69 | std::array eid2fid_map; 70 | std::array eid2aid_map; 71 | 72 | // Size: Number of gpu threads 73 | std::array gid2eid_map; 74 | // Size: Number of gpu threads 75 | std::array fid2eid_map; 76 | // Size: Number of analysis threads (fixed) 77 | std::array aid2eid_map; 78 | 79 | }; 80 | 81 | } // end namespace pipeline 82 | } // end namespace gltracesim 83 | 84 | #endif // __GLTRACESIM_PIPELINE_PIPELINE_HH__ 85 | -------------------------------------------------------------------------------- /gltracesim/src/generator/stop_timer.cc: -------------------------------------------------------------------------------- 1 | #include "debug_impl.hh" 2 | #include "generator/stop_timer.hh" 3 | 4 | namespace gltracesim { 5 | 6 | VOID 7 | StopTimer::_thread(VOID *_this) { 8 | // 9 | ((StopTimer*) _this)->thread(); 10 | } 11 | 12 | StopTimer::StopTimer(uint64_t seconds) : 13 | seconds(seconds), start(std::chrono::system_clock::now()) 14 | { 15 | // 16 | tid = PIN_SpawnInternalThread( 17 | _thread, (void*) this, 0, NULL 18 | ); 19 | 20 | // 21 | if (tid == INVALID_THREADID) { 22 | fprintf(stderr, "Faild to create filter thread."); 23 | exit(EXIT_FAILURE); 24 | } 25 | 26 | // 27 | DPRINTF(Init, "StopTimer [tid: %u, time: %lus].\n", tid, seconds); 28 | } 29 | 30 | StopTimer::~StopTimer() 31 | { 32 | 33 | } 34 | 35 | void 36 | StopTimer::thread() 37 | { 38 | 39 | // 40 | DPRINTF(Init, "StopTimer will trigger in %lus.\n", seconds); 41 | 42 | while (true) { 43 | // 44 | PIN_Sleep(1000); 45 | 46 | // 47 | if (PIN_IsProcessExiting()) { 48 | return; 49 | } 50 | 51 | // 52 | std::chrono::time_point now = 53 | std::chrono::system_clock::now(); 54 | 55 | // 56 | std::chrono::duration duration = now - start; 57 | 58 | if (duration.count() > seconds) { 59 | // 60 | DPRINTF(Init, "StopTimer triggered. Exiting...\n"); 61 | // Exit 62 | PIN_ExitApplication(EXIT_SUCCESS); 63 | // 64 | exit(EXIT_SUCCESS); 65 | } 66 | } 67 | 68 | } 69 | 70 | } // end namespace gltracesim 71 | 72 | -------------------------------------------------------------------------------- /gltracesim/src/generator/stop_timer.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STOP_TIMER_HH__ 2 | #define __GLTRACESIM_STOP_TIMER_HH__ 3 | 4 | #include "pin.H" 5 | #include 6 | #include 7 | 8 | namespace gltracesim { 9 | 10 | class StopTimer { 11 | 12 | public: 13 | 14 | /** 15 | * @brief StopTimer 16 | */ 17 | StopTimer(uint64_t seconds); 18 | 19 | /** 20 | * @brief ~StopTimer 21 | */ 22 | virtual ~StopTimer(); 23 | 24 | private: 25 | 26 | /** 27 | * @brief thread 28 | */ 29 | void thread(); 30 | 31 | /** 32 | * @brief _thread 33 | * @param _this 34 | */ 35 | static void _thread(void *_this); 36 | 37 | /** 38 | * @brief tid 39 | */ 40 | unsigned tid; 41 | 42 | /** 43 | * @brief seconds 44 | */ 45 | uint64_t seconds; 46 | 47 | // 48 | typedef std::chrono::time_point time_point_t; 49 | // 50 | time_point_t start; 51 | }; 52 | 53 | } // end namespace gltracesim 54 | 55 | #endif // __GLTRACESIM_STOP_TIMER_HH__ 56 | -------------------------------------------------------------------------------- /gltracesim/src/gltracesim.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "resource.proto"; 4 | 5 | package gltracesim.proto; 6 | 7 | message SimulationStats { 8 | // Filter cache miss accesses 9 | double duration = 1; 10 | // Tot mops 11 | uint64 tot_mops = 2; 12 | // Resource mops 13 | uint64 dev_mops = 3; 14 | // Offcore Memory Ops 15 | uint64 offcore_mops = 4; 16 | // 17 | uint64 opengl_calls = 5; 18 | } 19 | 20 | message Frame { 21 | // Frame number 22 | uint32 id = 1; 23 | 24 | // In fast forward mode 25 | bool fast_forwarded = 2; 26 | 27 | // 28 | SimulationStats sim_stats = 3; 29 | 30 | // 31 | repeated ResourceStats resource_stats = 4; 32 | } 33 | -------------------------------------------------------------------------------- /gltracesim/src/gltracesim_analyzer.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_TRACE_ANALYZER_HH__ 2 | #define __GLTRACESIM_TRACE_ANALYZER_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "device.hh" 14 | #include "analyzer.hh" 15 | 16 | #include "analyzer/schedular/base.hh" 17 | #include "analyzer/trace_manager.hh" 18 | 19 | #include "gem5/trace.hh" 20 | #include "gem5/protoio.hh" 21 | #include "gem5/packet.pb.h" 22 | 23 | namespace gltracesim { 24 | 25 | namespace analyzer { 26 | class CPU; 27 | class GPU; 28 | } 29 | 30 | /** 31 | * 32 | */ 33 | class GlTraceSimAnalyzer 34 | { 35 | 36 | public: 37 | 38 | /** 39 | * @brief The conf_t struct 40 | */ 41 | struct conf_t { 42 | 43 | /** 44 | * @brief use_global_sync 45 | */ 46 | bool use_global_sync; 47 | 48 | /** 49 | * @brief use_rsc_sync 50 | */ 51 | bool use_rsc_sync; 52 | 53 | /** 54 | * @brief num_gpu_cores 55 | */ 56 | size_t num_gpu_cores; 57 | 58 | /** 59 | * @brief batch_size 60 | */ 61 | size_t batch_size; 62 | 63 | } conf; 64 | 65 | public: 66 | 67 | /** 68 | * @brief VirtualMemoryManager 69 | * @param name 70 | */ 71 | GlTraceSimAnalyzer(const std::string &output_dir); 72 | 73 | /** 74 | * @brief ~VirtualMemoryManager 75 | */ 76 | ~GlTraceSimAnalyzer(); 77 | 78 | public: 79 | 80 | /** 81 | * @brief run 82 | */ 83 | void run(); 84 | 85 | public: 86 | 87 | /** 88 | * @brief handle_new_scene 89 | */ 90 | void handle_new_scene(); 91 | 92 | /** 93 | * @brief handle_end_scene 94 | */ 95 | void handle_end_scene(); 96 | 97 | /** 98 | * @brief handle_new_frame 99 | */ 100 | void handle_new_frame(); 101 | 102 | /** 103 | * @brief handle_end_frame 104 | */ 105 | void handle_end_frame(); 106 | 107 | /** 108 | * @brief send_packet 109 | * @param pkt 110 | */ 111 | void send_packet(packet_t &pkt); 112 | 113 | /** 114 | * @brief stop_timer_loop 115 | * @param seconds 116 | */ 117 | void stop_timer_loop(uint64_t seconds); 118 | 119 | private: 120 | 121 | /** 122 | * @brief stop_timer 123 | */ 124 | std::thread *stop_timer; 125 | 126 | /** 127 | * @brief The simulation_ctr_t struct 128 | */ 129 | struct simulation_ctrl_t { 130 | // Start epoch 131 | int start; 132 | // Stop epoch 133 | int stop; 134 | } sim_ctrl; 135 | 136 | /** 137 | * @brief The proto_t struct 138 | */ 139 | struct proto_t { 140 | // 141 | ProtoOutputStream *stats; 142 | } pb; 143 | 144 | // Current frame 145 | FramePtr current_frame; 146 | 147 | /** 148 | * Analyzers that will be analyzed 149 | */ 150 | std::vector analyzers; 151 | 152 | /** 153 | * @brief cpu 154 | */ 155 | analyzer::CPU *cpu; 156 | 157 | /** 158 | * @brief gpu 159 | */ 160 | analyzer::GPU *gpu; 161 | 162 | /** 163 | * @brief schedular 164 | */ 165 | analyzer::schedular::SchedularPtr schedular; 166 | 167 | }; 168 | 169 | 170 | } // end namespace gltracesim 171 | 172 | #endif // __GLTRACESIM_TRACE_ANALYZER_HH__ 173 | -------------------------------------------------------------------------------- /gltracesim/src/job.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_JOB_HH__ 2 | #define __GLTRACESIM_JOB_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "job.pb.h" 11 | #include "gltracesim.pb.h" 12 | #include "device.hh" 13 | #include "util/addr_range.hh" 14 | #include "util/timer.hh" 15 | 16 | #include "gem5/trace.hh" 17 | 18 | #include "stats/distribution.hh" 19 | #include "stats/distribution_impl.hh" 20 | 21 | namespace gltracesim { 22 | 23 | class GpuJob : public Timer 24 | { 25 | 26 | public: 27 | 28 | /** 29 | * @brief The inst_t union 30 | */ 31 | union inst_t { 32 | struct { 33 | uint32_t opcode; 34 | uint32_t width; 35 | }; 36 | uint64_t id; 37 | }; 38 | 39 | /** 40 | * @brief The basic_blk_t struct 41 | */ 42 | struct basic_blk_t { 43 | /** 44 | * @brief insts 45 | */ 46 | std::vector insts; 47 | }; 48 | 49 | /** 50 | * @brief The stats_t struct 51 | */ 52 | struct stats_t 53 | { 54 | // 55 | stats_t(); 56 | 57 | // 58 | uint64_t reads; 59 | uint64_t writes; 60 | 61 | // 62 | std::unordered_map basic_blk_count; 63 | 64 | // 65 | void reset(); 66 | }; 67 | 68 | public: 69 | 70 | enum Type { 71 | MISC_JOB = 0, 72 | DRAW_JOB = 1, 73 | TILE_JOB = 2, 74 | }; 75 | 76 | protected: 77 | 78 | /** 79 | * @brief GpuJob 80 | * @param type 81 | * @param dev 82 | */ 83 | GpuJob( 84 | uint64_t id, 85 | uint16_t frame_id, 86 | uint16_t scene_id, 87 | Type type, 88 | dev::HardwareDevice dev 89 | ); 90 | 91 | /** 92 | * 93 | */ 94 | ~GpuJob(); 95 | 96 | public: 97 | 98 | /** 99 | * @brief id 100 | */ 101 | uint64_t id; 102 | 103 | /** 104 | * @brief scene_id 105 | */ 106 | uint16_t scene_id; 107 | 108 | /** 109 | * @brief frame_id 110 | */ 111 | uint16_t frame_id; 112 | 113 | /** 114 | * @brief id 115 | */ 116 | Type type; 117 | 118 | /** 119 | * @brief id 120 | */ 121 | uint8_t dev; 122 | 123 | public: 124 | 125 | /** 126 | * @brief core_id 127 | */ 128 | int core_id; 129 | 130 | public: 131 | 132 | /** 133 | * @brief x 134 | */ 135 | int x; 136 | 137 | /** 138 | * @brief y 139 | */ 140 | int y; 141 | 142 | public: 143 | 144 | /** 145 | * @brief frame_stats 146 | */ 147 | stats_t stats; 148 | 149 | public: 150 | 151 | /** 152 | * @brief configure_trace_generator 153 | */ 154 | void configure_trace_generator(); 155 | 156 | /** 157 | * @brief trace 158 | */ 159 | gem5::TraceGenerator *trace; 160 | 161 | public: 162 | 163 | /** 164 | * @brief load_trace 165 | */ 166 | void load_trace(); 167 | 168 | /** 169 | * @brief pkts 170 | */ 171 | std::deque pkts; 172 | 173 | public: 174 | 175 | /** 176 | * @brief dump_info 177 | * @param job_stats 178 | */ 179 | virtual void dump_info(gltracesim::proto::JobInfo *job_info); 180 | 181 | /** 182 | * @brief dump_stats 183 | * @param job_stats 184 | */ 185 | virtual void dump_stats(gltracesim::proto::JobStats *job_stats); 186 | 187 | /** 188 | * @brief reset_stats 189 | */ 190 | void reset_stats(); 191 | 192 | }; 193 | 194 | class GpuMiscJob : public GpuJob { 195 | 196 | public: 197 | 198 | /** 199 | * @brief GpuJob 200 | * @param dev 201 | */ 202 | GpuMiscJob(uint64_t id, uint16_t scene_id, uint16_t frame_id, dev::HardwareDevice dev) : 203 | GpuJob(id, scene_id, frame_id, MISC_JOB, dev) {} 204 | }; 205 | 206 | class GpuDrawJob : public GpuJob { 207 | 208 | public: 209 | 210 | /** 211 | * @brief GpuJob 212 | * @param dev 213 | */ 214 | GpuDrawJob(uint64_t id, uint16_t scene_id, uint16_t frame_id) : 215 | GpuJob(id, scene_id, frame_id, DRAW_JOB, dev::GPU) {} 216 | }; 217 | 218 | class GpuTileJob : public GpuJob { 219 | 220 | public: 221 | 222 | /** 223 | * @brief GpuJob 224 | * @param dev 225 | */ 226 | GpuTileJob(uint64_t id, uint16_t scene_id, uint16_t frame_id, int x, int y) 227 | : GpuJob(id, scene_id, frame_id, TILE_JOB, dev::GPU) 228 | { 229 | this->x = x; 230 | this->y = y; 231 | } 232 | }; 233 | 234 | // 235 | typedef std::shared_ptr GpuJobPtr; 236 | 237 | } // end namespace gltracesim 238 | 239 | 240 | #endif // __GLTRACESIM_JOB_HH__ 241 | -------------------------------------------------------------------------------- /gltracesim/src/job.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | enum JobType { 6 | MISC_JOB = 0; 7 | DRAW_JOB = 1; 8 | TILE_JOB = 2; 9 | } 10 | 11 | message JobInfo { 12 | // Resource ID 13 | uint32 id = 1; 14 | // Device ID [ CPU, GPU ] 15 | uint32 dev_id = 2; 16 | // Type 17 | JobType type = 3; 18 | // Frame ID 19 | uint32 frame_id = 4; 20 | // Scene ID 21 | uint32 scene_id = 5; 22 | // X-coord 23 | uint32 x = 6; 24 | // Y-coord 25 | uint32 y = 7; 26 | } 27 | 28 | message ComputationStats { 29 | // Instructions ID [XED Op Code] 30 | uint32 opcode = 1; 31 | // Instruction output width (bits) 32 | uint32 width = 2; 33 | // Number of invocations 34 | uint64 count = 3; 35 | } 36 | 37 | message JobStats { 38 | // Resource ID 39 | uint32 id = 1; 40 | // Executed Instructions 41 | uint64 insts = 2; 42 | // Number of read operations 43 | uint64 reads = 3; 44 | // Number of write operations 45 | uint64 writes = 4; 46 | // Detailed computation stats 47 | repeated ComputationStats computation_stats = 5; 48 | } 49 | -------------------------------------------------------------------------------- /gltracesim/src/opengl.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message OpenglCallInfo { 6 | // 7 | uint64 id = 1; 8 | // 9 | string name = 2; 10 | } 11 | -------------------------------------------------------------------------------- /gltracesim/src/packet.cc: -------------------------------------------------------------------------------- 1 | #include "packet.hh" 2 | 3 | namespace gltracesim { 4 | 5 | } // end namespace gltracesim 6 | -------------------------------------------------------------------------------- /gltracesim/src/packet.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_PACKET_HH__ 2 | #define __GLTRACESIM_PACKET_HH__ 3 | 4 | #include 5 | 6 | #include "device.hh" 7 | #include "resource.hh" 8 | 9 | namespace gltracesim { 10 | 11 | enum AccessType { 12 | // CPU 13 | READ = 0, 14 | WRITE, 15 | WRITEBACK, 16 | SYNC, 17 | NEW_JOB, 18 | END_JOB, 19 | MV_TO_CPU, 20 | MV_TO_GPU, 21 | NEW_SCENE, 22 | END_SCENE, 23 | NEW_FRAME, 24 | NEW_RESOURCE, 25 | END_RESOURCE, 26 | OPENGL_CALL, 27 | // 28 | NUM_ACCESS_TYPES 29 | }; 30 | 31 | // 32 | struct packet_t 33 | { 34 | // 35 | packet_t() 36 | : inst(0x0), 37 | vaddr(0x0), 38 | paddr(0x0), 39 | length(0), 40 | cmd(READ), 41 | tid(0), 42 | job_id(-1), 43 | dev_id(dev::CPU) 44 | { 45 | // Do nothing 46 | } 47 | 48 | // 49 | void* inst; 50 | // 51 | uint64_t vaddr; 52 | // 53 | uint64_t paddr; 54 | // 55 | uint8_t length; 56 | // 57 | uint8_t cmd; 58 | // 59 | uint8_t tid; 60 | // 61 | int job_id; 62 | // 63 | int rsc_id; 64 | // 65 | uint8_t dev_id; 66 | }; 67 | 68 | } // end namespace gltracesim 69 | 70 | #endif // __GLTRACESIM_PACKET_HH__ 71 | -------------------------------------------------------------------------------- /gltracesim/src/resource_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_RESOURCE_IMPL_HH__ 2 | #define __GLTRACESIM_RESOURCE_IMPL_HH__ 3 | 4 | #include "resource.hh" 5 | 6 | namespace gltracesim { 7 | 8 | inline size_t 9 | GpuResource::size() const 10 | { 11 | return addr_range.size(); 12 | } 13 | 14 | inline size_t 15 | GpuResource::get_blk_idx(uint64_t addr) const 16 | { 17 | return (addr - addr_range.start) / blk_size; 18 | } 19 | 20 | inline size_t 21 | GpuResource::get_width() const 22 | { 23 | return lpr.base.width0; 24 | } 25 | 26 | inline size_t 27 | GpuResource::get_height() const 28 | { 29 | return lpr.base.height0; 30 | } 31 | 32 | inline uint64_t 33 | GpuResource::get_addr(struct llvmpipe_resource *lpr) 34 | { 35 | if (llvmpipe_resource_is_texture(&lpr->base)) { 36 | return uint64_t(lpr->tex_data); 37 | } else { 38 | return uint64_t(lpr->data); 39 | } 40 | } 41 | 42 | inline uint64_t 43 | GpuResource::get_size(struct llvmpipe_resource *lpr) 44 | { 45 | if (llvmpipe_resource_is_texture(&lpr->base)) { 46 | return lpr->total_alloc_size; 47 | } else { 48 | return lpr->base.width0; 49 | } 50 | } 51 | 52 | inline const char* 53 | GpuResource::get_target_name() const { 54 | return target_names[lpr.base.target]; 55 | } 56 | 57 | } // end namespace gltracesim 58 | 59 | #endif // __GLTRACESIM_RESOURCE_IMPL_HH__ 60 | -------------------------------------------------------------------------------- /gltracesim/src/resource_jpeg.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace gltracesim { 7 | 8 | void 9 | dump_jpeg_image_wrapper( 10 | const char *filename, uint8_t *data, size_t width, size_t height) 11 | { 12 | struct jpeg_compress_struct cinfo; 13 | struct jpeg_error_mgr jerr; 14 | 15 | cinfo.err = jpeg_std_error(&jerr); 16 | jpeg_create_compress(&cinfo); 17 | 18 | // 19 | FILE *outfile = NULL; 20 | 21 | // 22 | outfile = fopen(filename, "wb"); 23 | // 24 | assert(outfile); 25 | 26 | jpeg_stdio_dest(&cinfo, outfile); 27 | 28 | cinfo.image_width = width; 29 | cinfo.image_height = height; 30 | cinfo.input_components = 3; 31 | cinfo.in_color_space = JCS_RGB; 32 | 33 | jpeg_set_defaults(&cinfo); 34 | jpeg_set_quality(&cinfo, 7, true); 35 | jpeg_start_compress(&cinfo, true); 36 | 37 | JSAMPROW row_pointer[1]; 38 | int row_stride = width * 3; 39 | 40 | while (cinfo.next_scanline < cinfo.image_height) { 41 | row_pointer[0] = &data[cinfo.next_scanline * row_stride]; 42 | jpeg_write_scanlines(&cinfo, row_pointer, 1); 43 | } 44 | 45 | // 46 | jpeg_finish_compress(&cinfo); 47 | // 48 | fclose(outfile); 49 | // 50 | jpeg_destroy_compress(&cinfo); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /gltracesim/src/resource_tracker.cc: -------------------------------------------------------------------------------- 1 | #include "resource_tracker.hh" 2 | 3 | namespace gltracesim { 4 | 5 | ResourceTracker::ResourceTracker() 6 | { 7 | 8 | } 9 | 10 | ResourceTracker::~ResourceTracker() 11 | { 12 | 13 | } 14 | 15 | } // end namespace gltracesim 16 | 17 | -------------------------------------------------------------------------------- /gltracesim/src/resource_tracker.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_RESOURCE_TRACKER_HH__ 2 | #define __GLTRACESIM_RESOURCE_TRACKER_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "resource.hh" 9 | #include "util/addr_range_map.hh" 10 | 11 | namespace gltracesim { 12 | 13 | class ResourceTracker { 14 | 15 | public: 16 | 17 | // 18 | typedef AddrRangeMap AddrMap; 19 | // 20 | typedef std::unordered_map IdMap; 21 | // 22 | typedef std::vector Vector; 23 | 24 | 25 | public: 26 | 27 | /** 28 | * @brief Analyzer 29 | */ 30 | ResourceTracker(); 31 | 32 | /** 33 | * @brief ~Analyzer 34 | */ 35 | virtual ~ResourceTracker(); 36 | 37 | /** 38 | * @brief add 39 | * @param gpu_resource 40 | */ 41 | void add(GpuResourcePtr gpu_resource) 42 | { 43 | // 44 | alive_addr_map.insert(gpu_resource->addr_range, gpu_resource); 45 | 46 | // 47 | id_map[gpu_resource->id] = gpu_resource; 48 | } 49 | 50 | /** 51 | * @brief add_to_map 52 | * @param gpu_resource 53 | */ 54 | void map(GpuResourcePtr gpu_resource) 55 | { 56 | // 57 | id_map[gpu_resource->id] = gpu_resource; 58 | } 59 | 60 | /** 61 | * @brief add 62 | * @param gpu_resource 63 | */ 64 | void destroy(GpuResourcePtr gpu_resource) 65 | { 66 | // 67 | AddrMap::iterator it = alive_addr_map.find( 68 | gpu_resource->addr_range.start 69 | ); 70 | 71 | assert(it != alive_addr_map.end()); 72 | 73 | // 74 | alive_addr_map.erase(it); 75 | 76 | // 77 | gpu_resource->dead = true; 78 | 79 | // 80 | dead_vector.push_back(gpu_resource); 81 | } 82 | 83 | /** 84 | * @brief resurrect 85 | * @param gpu_resource 86 | */ 87 | void resurrect(GpuResourcePtr gpu_resource) { 88 | // 89 | gpu_resource->zombie = true; 90 | 91 | // 92 | zombie_vector.push_back(gpu_resource); 93 | } 94 | 95 | /** 96 | * @brief add 97 | * @param gpu_resource 98 | */ 99 | GpuResourcePtr find_addr(uint64_t addr) 100 | { 101 | // 102 | AddrMap::iterator it = alive_addr_map.find(addr); 103 | 104 | if (_u(it == alive_addr_map.end())) { 105 | return null_ptr; 106 | } else { 107 | return it->second; 108 | } 109 | } 110 | 111 | /** 112 | * @brief add 113 | * @param gpu_resource 114 | */ 115 | GpuResourcePtr find_id(uint64_t id) 116 | { 117 | // 118 | IdMap::iterator it = id_map.find(id); 119 | 120 | if (_u(it == id_map.end())) { 121 | return null_ptr; 122 | } else { 123 | // 124 | return it->second; 125 | } 126 | } 127 | 128 | /** 129 | * @brief get_dead 130 | * @return 131 | */ 132 | AddrMap& get_alive() { 133 | return alive_addr_map; 134 | } 135 | 136 | /** 137 | * @brief get_dead 138 | * @return 139 | */ 140 | Vector& get_dead() { 141 | return dead_vector; 142 | } 143 | 144 | /** 145 | * @brief clear_dead 146 | * @return 147 | */ 148 | void clear_dead() { 149 | dead_vector.clear(); 150 | } 151 | 152 | /** 153 | * @brief get_dead 154 | * @return 155 | */ 156 | Vector& get_zombies() { 157 | return zombie_vector; 158 | } 159 | 160 | /** 161 | * @brief clear_dead 162 | * @return 163 | */ 164 | void clear_zombies() { 165 | // Kill it again for next frame. 166 | for (auto &gpu_resource: zombie_vector) { 167 | gpu_resource->zombie = false; 168 | } 169 | 170 | zombie_vector.clear(); 171 | } 172 | 173 | private: 174 | // 175 | GpuResourcePtr null_ptr; 176 | 177 | // Addr -> Resource 178 | AddrMap alive_addr_map; 179 | 180 | // Addr -> Resource 181 | Vector dead_vector; 182 | 183 | // Addr -> Resource 184 | Vector zombie_vector; 185 | 186 | // ID -> Resource 187 | IdMap id_map; 188 | 189 | }; 190 | 191 | // 192 | typedef std::unique_ptr ResourceTrackerPtr; 193 | 194 | } // end namespace gltracesim 195 | 196 | #endif // __GLTRACESIM_RESOURCE_TRACKER_HH__ 197 | -------------------------------------------------------------------------------- /gltracesim/src/resource_tracker_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_RESOURCE_TRACKER_IMPL_HH__ 2 | #define __GLTRACESIM_RESOURCE_TRACKER_IMPL_HH__ 3 | 4 | #include "resource_tracker.hh" 5 | 6 | namespace gltracesim { 7 | 8 | 9 | } // end namespace gltracesim 10 | 11 | #endif // __GLTRACESIM_RESOURCE_TRACKER_IMPL_HH__ 12 | -------------------------------------------------------------------------------- /gltracesim/src/scene.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "scene.hh" 5 | 6 | #include "debug.hh" 7 | #include "debug_impl.hh" 8 | 9 | namespace gltracesim { 10 | 11 | Scene::Scene(uint16_t id, uint16_t frame_id) 12 | : id(id), frame_id(frame_id), global_id(0), width(0), height(0) 13 | { 14 | 15 | } 16 | 17 | Scene::~Scene() 18 | { 19 | 20 | } 21 | 22 | void 23 | Scene::dump_info(gltracesim::proto::SceneInfo *info) 24 | { 25 | // 26 | info->set_frame_id(frame_id); 27 | info->set_id(id); 28 | info->set_width(width); 29 | info->set_height(height); 30 | // 31 | for (auto job_id: jobs) { 32 | info->add_job(job_id); 33 | } 34 | 35 | // 36 | for (auto call_id: opengl_calls) { 37 | info->add_opengl_call(call_id); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /gltracesim/src/scene.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_SCENE_HH__ 2 | #define __GLTRACESIM_SCENE_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "job.pb.h" 9 | #include "scene.pb.h" 10 | #include "device.hh" 11 | 12 | #include "util/timer.hh" 13 | 14 | namespace gltracesim { 15 | 16 | class Scene : public Timer 17 | { 18 | 19 | public: 20 | 21 | /** 22 | * @brief GpuJob 23 | * @param type 24 | * @param dev 25 | * @param x 26 | * @param y 27 | */ 28 | Scene(uint16_t id, uint16_t frame_id); 29 | 30 | /** 31 | * 32 | */ 33 | ~Scene(); 34 | 35 | public: 36 | 37 | /** 38 | * @brief set_global_id 39 | * @param id 40 | */ 41 | void set_global_id(uint32_t id) { 42 | global_id = id; 43 | } 44 | 45 | /** 46 | * @brief inc_width 47 | * @param new_width 48 | */ 49 | void inc_width(uint16_t new_width) { 50 | width = std::max(width, new_width); 51 | } 52 | 53 | /** 54 | * @brief inc_height 55 | * @param new_height 56 | */ 57 | void inc_height(uint16_t new_height) { 58 | height = std::max(height, new_height); 59 | } 60 | 61 | /** 62 | * @brief add_job 63 | * @param job_id 64 | */ 65 | void add_job(size_t job_id) { 66 | jobs.push_back(job_id); 67 | } 68 | 69 | /** 70 | * @brief add_opengl_call 71 | * @param call 72 | */ 73 | void add_opengl_call(uint32_t call_id) { 74 | opengl_calls.push_back(call_id); 75 | } 76 | 77 | public: 78 | 79 | /** 80 | * @brief id within frame 81 | */ 82 | uint16_t id; 83 | 84 | /** 85 | * @brief frame_id 86 | */ 87 | uint16_t frame_id; 88 | 89 | /** 90 | * @brief id from start 91 | */ 92 | uint32_t global_id; 93 | 94 | /** 95 | * @brief width 96 | */ 97 | uint16_t width; 98 | 99 | /** 100 | * @brief height 101 | */ 102 | uint16_t height; 103 | 104 | /** 105 | * @brief jobs 106 | */ 107 | std::vector jobs; 108 | 109 | /** 110 | * @brief opengl_calls 111 | */ 112 | std::vector opengl_calls; 113 | 114 | public: 115 | 116 | /** 117 | * @brief dump_info 118 | * @param info 119 | */ 120 | virtual void dump_info(gltracesim::proto::SceneInfo *info); 121 | 122 | }; 123 | 124 | // 125 | typedef std::shared_ptr ScenePtr; 126 | 127 | } // end namespace gltracesim 128 | 129 | 130 | #endif // __GLTRACESIM_SCENE_HH__ 131 | -------------------------------------------------------------------------------- /gltracesim/src/scene.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message SceneInfo { 6 | // Scene ID 7 | uint32 id = 1; 8 | // Frame ID 9 | uint32 frame_id = 2; 10 | // Width [tiles] 11 | uint32 width = 3; 12 | // Height [tiles] 13 | uint32 height = 4; 14 | // Job ids 15 | repeated uint32 job = 5; 16 | // Job ids 17 | repeated uint64 opengl_call = 6; 18 | } 19 | -------------------------------------------------------------------------------- /gltracesim/src/stats/SConscript: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | # 4 | Import('simulator') 5 | Import('analyzer') 6 | 7 | _env = {} 8 | 9 | # 10 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 11 | 'cache.cc', 12 | 'distribution.cc', 13 | 'variable_distribution.cc', 14 | ]]) 15 | 16 | # 17 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 18 | 'cache.cc', 19 | 'distribution.cc', 20 | 'variable_distribution.cc', 21 | ]]) 22 | 23 | PROTO_SOURCES = [ 24 | 'cache.proto', 25 | 'distribution.proto', 26 | 'variable_distribution.proto', 27 | ] 28 | 29 | _env['proto'] = [ 30 | simulator.File(x) for x in PROTO_SOURCES 31 | ] 32 | 33 | # 34 | Return('_env') 35 | 36 | -------------------------------------------------------------------------------- /gltracesim/src/stats/cache.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "stats/cache.hh" 3 | #include "stats/cache_impl.hh" 4 | 5 | namespace gltracesim { 6 | namespace stats { 7 | 8 | Cache::Cache() 9 | { 10 | reset(); 11 | } 12 | 13 | Cache::~Cache() 14 | { 15 | 16 | } 17 | 18 | Cache& 19 | Cache::operator +=(const Cache &other) 20 | { 21 | gpuside += other.gpuside; 22 | memside += other.memside; 23 | hits += other.hits; 24 | misses += other.misses; 25 | 26 | intra_frame_hits += other.intra_frame_hits; 27 | intra_scene_hits += other.intra_scene_hits; 28 | intra_job_hits += other.intra_job_hits; 29 | intra_rsc_hits += other.intra_rsc_hits; 30 | 31 | writebacks += other.writebacks; 32 | evictions += other.evictions; 33 | 34 | return *this; 35 | } 36 | 37 | void 38 | Cache::reset() 39 | { 40 | gpuside.reset(); 41 | memside.reset(); 42 | hits.reset(); 43 | misses.reset(); 44 | 45 | intra_frame_hits.reset(); 46 | intra_scene_hits.reset(); 47 | intra_job_hits.reset(); 48 | intra_rsc_hits.reset(); 49 | 50 | writebacks = 0; 51 | evictions = 0; 52 | } 53 | 54 | void 55 | Cache::dump(gltracesim::proto::CacheStats *cache_stats) 56 | { 57 | cache_stats->mutable_gpuside()->set_read(gpuside[READ]); 58 | cache_stats->mutable_gpuside()->set_write(gpuside[WRITE]); 59 | 60 | cache_stats->mutable_memside()->set_read(memside[READ]); 61 | cache_stats->mutable_memside()->set_write(memside[WRITE]); 62 | 63 | cache_stats->mutable_hits()->set_read(hits[READ]); 64 | cache_stats->mutable_hits()->set_write(hits[WRITE]); 65 | 66 | cache_stats->mutable_misses()->set_read(misses[READ]); 67 | cache_stats->mutable_misses()->set_write(misses[WRITE]); 68 | 69 | cache_stats->set_writebacks(writebacks); 70 | cache_stats->set_evictions(evictions); 71 | 72 | cache_stats->mutable_intra_frame_hits()->set_read(intra_frame_hits[READ]); 73 | cache_stats->mutable_intra_frame_hits()->set_write(intra_frame_hits[WRITE]); 74 | 75 | cache_stats->mutable_intra_scene_hits()->set_read(intra_scene_hits[READ]); 76 | cache_stats->mutable_intra_scene_hits()->set_write(intra_scene_hits[WRITE]); 77 | 78 | cache_stats->mutable_intra_job_hits()->set_read(intra_job_hits[READ]); 79 | cache_stats->mutable_intra_job_hits()->set_write(intra_job_hits[WRITE]); 80 | 81 | cache_stats->mutable_intra_rsc_hits()->set_read(intra_rsc_hits[READ]); 82 | cache_stats->mutable_intra_rsc_hits()->set_write(intra_rsc_hits[WRITE]); 83 | } 84 | 85 | } // end namespace stats 86 | } // end namespace gltracesim 87 | 88 | -------------------------------------------------------------------------------- /gltracesim/src/stats/cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_CACHE_HH_ 2 | #define __GLTRACESIM_STATS_CACHE_HH_ 3 | 4 | #include 5 | #include 6 | 7 | #include "packet.hh" 8 | #include "stats/cache.pb.h" 9 | #include "stats/vector_impl.hh" 10 | 11 | namespace gltracesim { 12 | namespace stats { 13 | 14 | class Cache 15 | { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Cache 21 | */ 22 | Cache(); 23 | 24 | /** 25 | * @brief Cache 26 | */ 27 | ~Cache(); 28 | 29 | /** 30 | * @brief operator + 31 | * @param other 32 | */ 33 | Cache& operator+=(const Cache &other); 34 | 35 | /** 36 | * @brief reset 37 | */ 38 | void reset(); 39 | 40 | /** 41 | * @brief dump 42 | * @param cache_stats 43 | */ 44 | void dump(gltracesim::proto::CacheStats *cache_stats); 45 | 46 | public: 47 | 48 | typedef stats::IntVector stats_vector_t; 49 | 50 | stats_vector_t gpuside; 51 | stats_vector_t memside; 52 | stats_vector_t hits; 53 | stats_vector_t misses; 54 | 55 | uint64_t writebacks; 56 | uint64_t evictions; 57 | 58 | stats_vector_t intra_frame_hits; 59 | stats_vector_t intra_scene_hits; 60 | stats_vector_t intra_job_hits; 61 | stats_vector_t intra_rsc_hits; 62 | }; 63 | 64 | } // end namespace stats 65 | } // end namespace gltracesim 66 | 67 | #endif // __GLTRACESIM_STATS_CACHE_HH_ 68 | -------------------------------------------------------------------------------- /gltracesim/src/stats/cache.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message AccessTypeStats { 6 | uint64 read = 1; 7 | uint64 write = 2; 8 | uint64 prefetch = 3; 9 | } 10 | 11 | message CacheStats { 12 | // Cache ID 13 | uint32 id = 1; 14 | 15 | AccessTypeStats gpuside = 2; 16 | AccessTypeStats memside = 3; 17 | 18 | AccessTypeStats hits = 4; 19 | AccessTypeStats misses = 5; 20 | 21 | uint64 writebacks = 6; 22 | uint64 evictions = 7; 23 | 24 | AccessTypeStats intra_frame_hits = 8; 25 | AccessTypeStats intra_scene_hits = 9; 26 | AccessTypeStats intra_job_hits = 10; 27 | AccessTypeStats intra_rsc_hits = 11; 28 | } 29 | -------------------------------------------------------------------------------- /gltracesim/src/stats/cache_impl.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uart/gltracesim/79708f503047922538ca2983392c0e9f99a4345a/gltracesim/src/stats/cache_impl.hh -------------------------------------------------------------------------------- /gltracesim/src/stats/distribution.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "stats/distribution.hh" 4 | #include "stats/distribution_impl.hh" 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | Distribution::Distribution() 10 | { 11 | // Do nothing 12 | } 13 | 14 | Distribution::Distribution(size_t min, size_t max, size_t bucket_size) 15 | { 16 | init(min, max, bucket_size); 17 | } 18 | 19 | Distribution::~Distribution() 20 | { 21 | 22 | } 23 | 24 | void 25 | Distribution::init(size_t min, size_t max, size_t bucket_size) 26 | { 27 | this->min = min; 28 | this->max = max; 29 | this->bucket_size = bucket_size; 30 | // 31 | no_buckets = std::ceil((max - min + 1.0) / bucket_size); 32 | // 33 | data.resize(no_buckets); 34 | // 35 | reset(); 36 | } 37 | 38 | void 39 | Distribution::reset() 40 | { 41 | no_samples = 0; 42 | no_underflows = 0; 43 | no_overflows = 0; 44 | 45 | for (size_t i = 0; i < data.size(); ++i) { 46 | data[i] = 0; 47 | } 48 | } 49 | 50 | void 51 | Distribution::dump(gltracesim::proto::Distribution *dist) 52 | { 53 | dist->set_samples(no_samples); 54 | dist->set_underflows(no_underflows); 55 | dist->set_overflows(no_overflows); 56 | 57 | for (size_t i = 0; i < data.size(); ++i) { 58 | dist->add_dist(data[i]); 59 | } 60 | } 61 | 62 | } // end namespace stats 63 | } // end namespace gltracesim 64 | -------------------------------------------------------------------------------- /gltracesim/src/stats/distribution.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_DISTRIBUTION_HH__ 2 | #define __GLTRACESIM_STATS_DISTRIBUTION_HH__ 3 | 4 | #include 5 | #include "stats/distribution.pb.h" 6 | 7 | namespace gltracesim { 8 | namespace stats { 9 | 10 | class Distribution { 11 | 12 | public: 13 | 14 | /** 15 | * @brief Analyzer 16 | */ 17 | Distribution(); 18 | 19 | /** 20 | * @brief Analyzer 21 | */ 22 | Distribution(size_t min, size_t max, size_t bucket_size); 23 | 24 | /** 25 | * @brief ~Analyzer 26 | */ 27 | virtual ~Distribution(); 28 | 29 | /** 30 | * @brief Analyzer 31 | */ 32 | void init(size_t min, size_t max, size_t bucket_size); 33 | 34 | /** 35 | * @brief reset 36 | */ 37 | void reset(); 38 | 39 | /** 40 | * @brief dump 41 | * @param cache_stats 42 | */ 43 | void dump(gltracesim::proto::Distribution *dist); 44 | 45 | /** 46 | * @brief sample 47 | * @param idx 48 | * @param count 49 | */ 50 | void sample(size_t idx, int count = 1); 51 | 52 | private: 53 | 54 | /** 55 | * @brief min 56 | */ 57 | size_t min; 58 | 59 | /** 60 | * @brief max 61 | */ 62 | size_t max; 63 | 64 | /** 65 | * @brief bucket_size 66 | */ 67 | size_t bucket_size; 68 | 69 | /** 70 | * @brief no_buckets 71 | */ 72 | size_t no_buckets; 73 | 74 | private: 75 | 76 | /** 77 | * @brief samples 78 | */ 79 | uint64_t no_samples; 80 | 81 | /** 82 | * @brief samples 83 | */ 84 | uint64_t no_underflows; 85 | 86 | /** 87 | * @brief samples 88 | */ 89 | uint64_t no_overflows; 90 | 91 | /** 92 | * @brief dist 93 | */ 94 | std::vector data; 95 | 96 | }; 97 | 98 | } // end namespace stats 99 | } // end namespace gltracesim 100 | 101 | #endif // __GLTRACESIM_STATS_DISTRIBUTION_HH__ 102 | -------------------------------------------------------------------------------- /gltracesim/src/stats/distribution.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message Distribution { 6 | // Number of samples 7 | uint64 samples = 1; 8 | // Number of underflows 9 | uint64 underflows = 2; 10 | // Number of overflows 11 | uint64 overflows = 3; 12 | // Distribution 13 | repeated uint64 dist = 4; 14 | } 15 | -------------------------------------------------------------------------------- /gltracesim/src/stats/distribution_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_DISTRIBUTION_IMPL_HH__ 2 | #define __GLTRACESIM_STATS_DISTRIBUTION_IMPL_HH__ 3 | 4 | #include "stats/distribution.hh" 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | inline void 10 | Distribution::sample(size_t idx, int count) 11 | { 12 | if (idx < min) { 13 | ++no_underflows; 14 | } else if (idx > max) { 15 | ++no_overflows; 16 | } else { 17 | // 18 | data[(double(idx - min) / (max - min)) * (no_buckets - 1)] += count; 19 | } 20 | ++no_samples; 21 | } 22 | 23 | } // end namespace stats 24 | } // end namespace gltracesim 25 | 26 | #endif // __GLTRACESIM_STATS_DISTRIBUTION_IMPL_HH__ 27 | -------------------------------------------------------------------------------- /gltracesim/src/stats/histogram.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uart/gltracesim/79708f503047922538ca2983392c0e9f99a4345a/gltracesim/src/stats/histogram.cc -------------------------------------------------------------------------------- /gltracesim/src/stats/histogram.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uart/gltracesim/79708f503047922538ca2983392c0e9f99a4345a/gltracesim/src/stats/histogram.hh -------------------------------------------------------------------------------- /gltracesim/src/stats/histogram_impl.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uart/gltracesim/79708f503047922538ca2983392c0e9f99a4345a/gltracesim/src/stats/histogram_impl.hh -------------------------------------------------------------------------------- /gltracesim/src/stats/variable_distribution.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "stats/variable_distribution.hh" 4 | #include "stats/variable_distribution_impl.hh" 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | VariableDistribution::VariableDistribution() 10 | { 11 | // Do nothing 12 | } 13 | 14 | VariableDistribution::VariableDistribution( 15 | size_t min_count, size_t filter_count, size_t filter_size) 16 | { 17 | init(min_count, filter_count, filter_size); 18 | } 19 | 20 | VariableDistribution::~VariableDistribution() 21 | { 22 | 23 | } 24 | 25 | void 26 | VariableDistribution::init( 27 | size_t min_count, size_t filter_count, size_t filter_size) 28 | { 29 | this->min_count = min_count; 30 | this->filter_count = filter_count; 31 | this->filter_size = filter_size; 32 | // 33 | reset(); 34 | } 35 | 36 | void 37 | VariableDistribution::reset() 38 | { 39 | no_samples = 0; 40 | no_overflows = 0; 41 | 42 | // Clear count 43 | for (auto &e: filter.patterns) { 44 | e.second.count = 0; 45 | } 46 | 47 | // 48 | data.clear(); 49 | } 50 | 51 | void 52 | VariableDistribution::dump(gltracesim::proto::VariableDistribution *dist) 53 | { 54 | dist->set_samples(no_samples); 55 | 56 | for (auto &e: data) { 57 | auto d = dist->add_dist(); 58 | if (e.second >= min_count) { 59 | d->set_entry(e.first); 60 | d->set_samples(e.second); 61 | } else { 62 | no_overflows += e.second; 63 | } 64 | } 65 | 66 | dist->set_overflows(no_overflows); 67 | } 68 | 69 | void 70 | VariableDistribution::sample(int64_t pattern, int count) 71 | { 72 | auto it = data.find(pattern); 73 | 74 | if (it == data.end()) { 75 | 76 | // Insert new prefetch into history filter. 77 | filter.queue.push_back(pattern); 78 | 79 | // Update potentially important strides 80 | auto filter_it = filter.patterns.find(pattern); 81 | if (filter_it == filter.patterns.end()) { 82 | // 83 | filter.patterns[pattern].count = count; 84 | filter.patterns[pattern].ref_count = 1; 85 | } else { 86 | // 87 | filter_it->second.count += count; 88 | filter_it->second.ref_count++; 89 | 90 | // mv filter to data 91 | if (filter_it->second.count >= filter_count) { 92 | data[pattern] = filter_it->second.count; 93 | } 94 | } 95 | 96 | // Remove oldest stride 97 | if (filter.queue.size() == filter_size) { 98 | // 99 | int64_t old_pattern = filter.queue.front(); 100 | 101 | // 102 | auto old_filter_it = filter.patterns.find(old_pattern); 103 | 104 | // 105 | assert(old_filter_it != filter.patterns.end()); 106 | 107 | // 108 | old_filter_it->second.ref_count--; 109 | 110 | // No entry in list matches that pattern, filter it. 111 | if (old_filter_it->second.ref_count == 0) { 112 | // 113 | if (data.count(old_pattern) == 0) { 114 | no_overflows += old_filter_it->second.count; 115 | } 116 | // 117 | filter.patterns.erase(old_filter_it); 118 | } 119 | 120 | // 121 | filter.queue.pop_front(); 122 | } 123 | } else { 124 | it->second += count; 125 | } 126 | 127 | // 128 | assert(filter.patterns.size() <= filter.queue.size()); 129 | 130 | ++no_samples; 131 | } 132 | 133 | } // end namespace stats 134 | } // end namespace gltracesim 135 | -------------------------------------------------------------------------------- /gltracesim/src/stats/variable_distribution.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_HH__ 2 | #define __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_HH__ 3 | 4 | #include 5 | #include 6 | #include "stats/variable_distribution.pb.h" 7 | 8 | namespace gltracesim { 9 | namespace stats { 10 | 11 | class VariableDistribution { 12 | 13 | public: 14 | 15 | /** 16 | * @brief Analyzer 17 | */ 18 | VariableDistribution(); 19 | 20 | /** 21 | * @brief Analyzer 22 | */ 23 | VariableDistribution( 24 | size_t min_count, size_t filter_count, size_t filter_size 25 | ); 26 | 27 | /** 28 | * @brief ~Analyzer 29 | */ 30 | virtual ~VariableDistribution(); 31 | 32 | /** 33 | * @brief Analyzer 34 | */ 35 | void init(size_t min_count, size_t filter_count, size_t filter_size); 36 | 37 | /** 38 | * @brief reset 39 | */ 40 | void reset(); 41 | 42 | /** 43 | * @brief dump 44 | * @param cache_stats 45 | */ 46 | void dump(gltracesim::proto::VariableDistribution *dist); 47 | 48 | /** 49 | * @brief sample 50 | * @param idx 51 | * @param count 52 | */ 53 | void sample(int64_t idx, int count = 1); 54 | 55 | private: 56 | 57 | /** 58 | * @brief min 59 | */ 60 | size_t min_count; 61 | 62 | /** 63 | * @brief min 64 | */ 65 | size_t filter_count; 66 | 67 | /** 68 | * @brief max 69 | */ 70 | size_t filter_size; 71 | 72 | private: 73 | 74 | /** 75 | * @brief samples 76 | */ 77 | uint64_t no_samples; 78 | 79 | /** 80 | * @brief samples 81 | */ 82 | uint64_t no_overflows; 83 | 84 | /** 85 | * @brief The prefetch_history_t struct 86 | */ 87 | struct filter_t 88 | { 89 | 90 | struct count_t { 91 | uint64_t count; 92 | int ref_count; 93 | }; 94 | 95 | /** 96 | * @brief filter 97 | */ 98 | std::map patterns; 99 | 100 | /** 101 | * @brief filter 102 | */ 103 | std::deque queue; 104 | 105 | } filter; 106 | 107 | /** 108 | * @brief data 109 | */ 110 | std::map data; 111 | 112 | }; 113 | 114 | } // end namespace stats 115 | } // end namespace gltracesim 116 | 117 | #endif // __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_HH__ 118 | -------------------------------------------------------------------------------- /gltracesim/src/stats/variable_distribution.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gltracesim.proto; 4 | 5 | message VariableDistribution { 6 | 7 | // 8 | message Entry { 9 | 10 | // 11 | int64 entry = 1; 12 | // 13 | uint64 samples = 2; 14 | 15 | } 16 | 17 | // 18 | uint64 samples = 1; 19 | // 20 | uint64 overflows = 2; 21 | // 22 | repeated Entry dist = 3; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /gltracesim/src/stats/variable_distribution_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_IMPL_HH__ 2 | #define __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_IMPL_HH__ 3 | 4 | #include "stats/variable_distribution.hh" 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | } // end namespace stats 10 | } // end namespace gltracesim 11 | 12 | #endif // __GLTRACESIM_STATS_VARIABLE_DISTRIBUTION_IMPL_HH__ 13 | -------------------------------------------------------------------------------- /gltracesim/src/stats/vector.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uart/gltracesim/79708f503047922538ca2983392c0e9f99a4345a/gltracesim/src/stats/vector.cc -------------------------------------------------------------------------------- /gltracesim/src/stats/vector.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_VECTOR_HH__ 2 | #define __GLTRACESIM_STATS_VECTOR_HH__ 3 | 4 | #include 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | template 10 | class Vector : public std::array 11 | { 12 | 13 | // 14 | typedef std::array BaseClass; 15 | 16 | public: 17 | 18 | // 19 | Vector(); 20 | // 21 | Vector& operator+=(const Vector &other); 22 | // 23 | void reset(); 24 | 25 | }; 26 | 27 | template 28 | class IntVector : public Vector 29 | { 30 | 31 | }; 32 | 33 | template 34 | class FloatVector : public Vector 35 | { 36 | 37 | }; 38 | 39 | 40 | } // end namespace stats 41 | } // end namespace gltracesim 42 | 43 | #endif // __GLTRACESIM_STATS_VECTOR_HH__ 44 | -------------------------------------------------------------------------------- /gltracesim/src/stats/vector_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_STATS_VECTOR_IMPL_HH__ 2 | #define __GLTRACESIM_STATS_VECTOR_IMPL_HH__ 3 | 4 | #include "stats/vector.hh" 5 | 6 | namespace gltracesim { 7 | namespace stats { 8 | 9 | template 10 | Vector::Vector() : BaseClass() 11 | { 12 | 13 | } 14 | 15 | template 16 | Vector& 17 | Vector::operator+=(const Vector &other) 18 | { 19 | for (size_t i = 0; i < N; ++i) { 20 | (*this)[i] += other[i]; 21 | } 22 | return *this; 23 | } 24 | 25 | template 26 | void 27 | Vector::reset() 28 | { 29 | for (size_t i = 0; i < N; ++i) { 30 | (*this)[i] = 0; 31 | } 32 | } 33 | 34 | } // end namespace stats 35 | } // end namespace gltracesim 36 | 37 | #endif // __GLTRACESIM_STATS_VECTOR_IMPL_HH__ 38 | -------------------------------------------------------------------------------- /gltracesim/src/system.cc: -------------------------------------------------------------------------------- 1 | #include "system.hh" 2 | 3 | namespace gltracesim { 4 | 5 | // 6 | SystemPtr system; 7 | 8 | System::System(const Json::Value &config) : 9 | config(config), 10 | frame_nbr(0), 11 | scene_nbr(0), 12 | global_scene_idx(0), 13 | job_nbr(0), 14 | blk_size(64), 15 | tsc(0) 16 | { 17 | // Do nothing 18 | } 19 | 20 | System::~System() 21 | { 22 | // Do nothing 23 | } 24 | 25 | } // end namespace gltracesim 26 | 27 | -------------------------------------------------------------------------------- /gltracesim/src/util/SConscript: -------------------------------------------------------------------------------- 1 | # 2 | Import('simulator') 3 | Import('analyzer') 4 | 5 | _env = {} 6 | 7 | # 8 | simulator["objs"].extend([ simulator.SharedObject(x) for x in [ 9 | 'threads.cc', 10 | 'timer.cc', 11 | ]]) 12 | 13 | # 14 | analyzer["objs"].extend([ analyzer.Object(x) for x in [ 15 | 'threads.cc', 16 | 'timer.cc', 17 | ]]) 18 | 19 | 20 | # 21 | Return('_env') 22 | 23 | -------------------------------------------------------------------------------- /gltracesim/src/util/addr_range.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ADDR_RANGE_HH__ 2 | #define __GLTRACESIM_ADDR_RANGE_HH__ 3 | 4 | namespace gltracesim { 5 | 6 | struct AddrRange { 7 | uint64_t start; 8 | uint64_t end; 9 | 10 | AddrRange(uint64_t start = 0) 11 | : start(start), end(start + 1) 12 | { 13 | 14 | } 15 | 16 | AddrRange(uint64_t start, uint64_t end) 17 | : start(start), end(end) 18 | { 19 | 20 | } 21 | 22 | uint64_t size() const { 23 | return (end - start + 1); 24 | } 25 | 26 | bool operator<(const AddrRange& r) const { 27 | return start < r.start; 28 | } 29 | 30 | bool operator==(const AddrRange& r) const { 31 | if (start != r.start) return false; 32 | if (end != r.end) return false; 33 | return true; 34 | } 35 | 36 | bool contains(const uint64_t a) const { 37 | return (start <= a && a <= end); 38 | } 39 | }; 40 | 41 | } // end namespace gltracesim 42 | 43 | #endif // __GLTRACESIM_ADDR_RANGE_HH__ 44 | -------------------------------------------------------------------------------- /gltracesim/src/util/addr_range_map.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_ADDR_RANGE_MAP_HH__ 2 | #define __GLTRACESIM_ADDR_RANGE_MAP_HH__ 3 | 4 | #include 5 | #include "util/cflags.hh" 6 | 7 | namespace gltracesim { 8 | 9 | template 10 | struct AddrRangeMap 11 | { 12 | // 13 | typedef std::map RangeMap; 14 | // 15 | typedef typename RangeMap::iterator iterator; 16 | typedef typename RangeMap::const_iterator const_iterator; 17 | 18 | // 19 | RangeMap map; 20 | 21 | iterator find(uint64_t addr) 22 | { 23 | if (_u(map.empty())) { 24 | return map.end(); 25 | } 26 | 27 | iterator it = map.upper_bound(AddrRange(addr)); 28 | 29 | if (it == map.begin()) { 30 | if (it->first.contains(addr)) { 31 | return it; 32 | } else { 33 | return map.end(); 34 | } 35 | } 36 | 37 | --it; 38 | 39 | if (_l(it->first.contains(addr))) 40 | return it; 41 | 42 | return map.end(); 43 | } 44 | 45 | void insert(const AddrRange &r, const V& d) { 46 | map.insert(std::make_pair(r, d)); 47 | } 48 | 49 | void erase(iterator p) { 50 | map.erase(p); 51 | } 52 | 53 | void clear() { 54 | map.clear(); 55 | } 56 | 57 | const_iterator begin() const { 58 | return map.begin(); 59 | } 60 | 61 | iterator begin() { 62 | return map.begin(); 63 | } 64 | 65 | const_iterator end() const { 66 | return map.end(); 67 | } 68 | 69 | iterator end() { 70 | return map.end(); 71 | } 72 | 73 | std::size_t size() const { 74 | return map.size(); 75 | } 76 | 77 | bool empty() const { 78 | return map.empty(); 79 | } 80 | }; 81 | 82 | } // end namespace gltracesim 83 | 84 | #endif // __GLTRACESIM_ADDR_RANGE_MAP_HH__ 85 | -------------------------------------------------------------------------------- /gltracesim/src/util/cache.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_UTIL_CACHE_HH__ 2 | #define __GLTRACESIM_UTIL_CACHE_HH__ 3 | 4 | #include 5 | #include 6 | 7 | namespace gltracesim { 8 | 9 | // 10 | struct cache_entry_t 11 | { 12 | /** 13 | * @brief valid 14 | */ 15 | bool valid; 16 | 17 | /** 18 | * @brief dirty 19 | */ 20 | bool dirty; 21 | 22 | /** 23 | * @brief The Anonymous:1 union 24 | */ 25 | union 26 | { 27 | uint64_t addr; 28 | uint64_t tag; 29 | }; 30 | 31 | /** 32 | * @brief tsc 33 | */ 34 | uint64_t last_tsc; 35 | 36 | /** 37 | * @brief gpu_resource 38 | */ 39 | int32_t rsc_id; 40 | 41 | /** 42 | * @brief gpu_resource 43 | */ 44 | int32_t job_id; 45 | 46 | /** 47 | * @brief gpu_resource 48 | */ 49 | uint8_t dev_id; 50 | }; 51 | 52 | // 53 | struct cache_params_t 54 | { 55 | /** 56 | * @brief size 57 | */ 58 | uint64_t size; 59 | 60 | /** 61 | * @brief associativity 62 | */ 63 | uint64_t associativity; 64 | 65 | /** 66 | * @brief blk_size 67 | */ 68 | uint64_t blk_size; 69 | 70 | /** 71 | * @brief sub_blk_size 72 | */ 73 | uint64_t sub_blk_size; 74 | 75 | }; 76 | 77 | template 78 | class Cache 79 | { 80 | 81 | public: 82 | 83 | /** 84 | * @brief params 85 | */ 86 | params_t params; 87 | 88 | /** 89 | * @brief data_t 90 | */ 91 | typedef std::vector data_t; 92 | 93 | public: 94 | 95 | /** 96 | * @brief Cache 97 | * @param p 98 | */ 99 | Cache(params_t *p); 100 | 101 | public: 102 | 103 | /** 104 | * @brief Set index. 105 | */ 106 | uint64_t get_set_idx(uint64_t addr) const; 107 | 108 | /** 109 | * @brief Set index. 110 | */ 111 | uint64_t get_sub_blk_idx(uint64_t addr) const; 112 | 113 | /** 114 | * @brief get_no_sub_blk 115 | */ 116 | uint64_t get_no_sub_blks() const; 117 | 118 | /** 119 | * @brief get_set_addr 120 | * @param addr 121 | * @return 122 | */ 123 | uint64_t get_blk_addr(uint64_t addr) const; 124 | 125 | /** 126 | * @brief find 127 | * @param addr 128 | * @return 129 | */ 130 | void find(uint64_t addr, entry_t* &hit, entry_t* &evict); 131 | 132 | /** 133 | * @brief get_data 134 | * @return 135 | */ 136 | data_t* get_data(); 137 | 138 | public: 139 | 140 | /** 141 | * @brief data 142 | */ 143 | data_t data; 144 | 145 | /** 146 | * @brief addr 147 | */ 148 | uint64_t no_sets; 149 | 150 | /** 151 | * @brief addr 152 | */ 153 | uint64_t no_blks; 154 | 155 | /** 156 | * @brief addr 157 | */ 158 | uint64_t no_sub_blks; 159 | 160 | /** 161 | * @brief addr 162 | */ 163 | uint64_t set_idx_mask; 164 | 165 | /** 166 | * @brief addr 167 | */ 168 | uint64_t blk_size_log2; 169 | 170 | /** 171 | * @brief addr 172 | */ 173 | uint64_t blk_addr_umask; 174 | 175 | }; 176 | 177 | } // end namespace gltracesim 178 | 179 | #endif // __GLTRACESIM_UTIL_CACHE_HH__ 180 | -------------------------------------------------------------------------------- /gltracesim/src/util/cache_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_UTIL_CACHE_IMPL_HH__ 2 | #define __GLTRACESIM_UTIL_CACHE_IMPL_HH__ 3 | 4 | #include 5 | #include "util/cache.hh" 6 | #include "util/cflags.hh" 7 | 8 | namespace gltracesim { 9 | 10 | template 11 | Cache::Cache(params_t *p) : params(*p) 12 | { 13 | no_sets = params.size / (params.associativity * params.blk_size); 14 | no_blks = no_sets * params.associativity; 15 | no_sub_blks = params.blk_size / params.sub_blk_size; 16 | 17 | // Build data structure 18 | 19 | data.reserve(no_blks); 20 | data.resize(no_blks); 21 | for (size_t blk_idx = 0; blk_idx < no_blks; ++blk_idx) 22 | { 23 | // 24 | entry_t &ce = data[blk_idx]; 25 | 26 | // 27 | ce.valid = false; 28 | ce.addr = 0; 29 | } 30 | 31 | // 32 | set_idx_mask = (no_sets - 1); 33 | blk_size_log2 = uint64_t(log2(params.blk_size)); 34 | blk_addr_umask = ~(params.blk_size - 1); 35 | } 36 | 37 | template 38 | uint64_t 39 | Cache::get_set_idx(uint64_t addr) const 40 | { 41 | return (addr >> blk_size_log2) & set_idx_mask; 42 | } 43 | 44 | template 45 | uint64_t 46 | Cache::get_sub_blk_idx(uint64_t addr) const 47 | { 48 | return (addr & ~blk_addr_umask) / params.sub_blk_size; 49 | } 50 | 51 | template 52 | uint64_t 53 | Cache::get_no_sub_blks() const 54 | { 55 | return no_sub_blks; 56 | } 57 | 58 | template 59 | uint64_t 60 | Cache::get_blk_addr(uint64_t addr) const 61 | { 62 | return (addr & blk_addr_umask); 63 | } 64 | 65 | template 66 | void 67 | Cache::find(uint64_t addr, entry_t* &hit, entry_t* &evict) 68 | { 69 | uint64_t blk_addr = get_blk_addr(addr); 70 | uint64_t set_idx = get_set_idx(addr) * params.associativity; 71 | 72 | uint64_t lru_tsc = ~uint64_t(0); 73 | int lru_idx = set_idx; 74 | 75 | hit = NULL; 76 | evict = NULL; 77 | 78 | // For each way 79 | for (size_t w = set_idx; w < (set_idx + params.associativity); ++w) { 80 | // Hit 81 | if (_u(data[w].valid && (data[w].addr == blk_addr))) { 82 | // 83 | hit = &data[w]; 84 | 85 | // Replacement not needed 86 | return; 87 | } 88 | 89 | // Check invalid 90 | if (_u(data[w].valid == false)) { 91 | evict = &data[w]; 92 | } 93 | 94 | // Check LRU 95 | if (_u(data[w].last_tsc < lru_tsc)) { 96 | lru_tsc = data[w].last_tsc; 97 | lru_idx = w; 98 | } 99 | } 100 | 101 | // No invalid entry, use LRU. 102 | if (evict == NULL) { 103 | evict = &data[lru_idx]; 104 | } 105 | } 106 | 107 | template 108 | typename Cache::data_t* 109 | Cache::get_data() 110 | { 111 | return &data; 112 | } 113 | 114 | } // end namespace gltracesim 115 | 116 | #endif // __GLTRACESIM_UTIL_CACHE_IMPL_HH__ 117 | -------------------------------------------------------------------------------- /gltracesim/src/util/cflags.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_CFLAGS_HH__ 2 | #define __GLTRACESIM_CFLAGS_HH__ 3 | 4 | #ifndef _l 5 | #define _l(x) __builtin_expect(!!(x), 1) 6 | #endif 7 | 8 | #ifndef _u 9 | #define _u(x) __builtin_expect(!!(x), 0) 10 | #endif 11 | 12 | #endif // __GLTRACESIM_CFLAGS_HH__ 13 | -------------------------------------------------------------------------------- /gltracesim/src/util/mkdir.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_UTIL_MKDIR_HH__ 2 | #define __GLTRACESIM_UTIL_MKDIR_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "debug.hh" 9 | 10 | namespace gltracesim { 11 | 12 | /** 13 | * 14 | */ 15 | inline void mkdir(const char *fmt, ...) { 16 | va_list args; 17 | va_start(args, fmt); 18 | 19 | 20 | std::stringstream d; 21 | while (*fmt != '\0') { 22 | if (strncmp(fmt, "/", 1) == 0) { 23 | d << *fmt; 24 | fmt += 1; 25 | } else if (strncmp(fmt, "%u64", 4) == 0) { 26 | int32_t i = va_arg(args, int32_t); 27 | d << i; 28 | fmt += 4; 29 | continue; 30 | } else if (strncmp(fmt, "%s", 2) == 0) { 31 | const char *c = va_arg(args, char*); 32 | d << c; 33 | fmt += 2; 34 | continue; 35 | } else if (strncmp(fmt, "%", 1) == 0) { 36 | DPRINTF(Error, "mkdir %s invalid format: %s", d.str().c_str(), fmt); 37 | assert(0); 38 | } else { 39 | d << *fmt; 40 | fmt += 1; 41 | continue; 42 | } 43 | 44 | // 45 | int ret = ::mkdir( 46 | d.str().c_str(), 47 | S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH 48 | ); 49 | 50 | switch (ret) { 51 | case -1: continue; 52 | case 0: continue; 53 | case EEXIST: continue; 54 | default: { 55 | DPRINTF(Error, "mkdir %s failed[%i]: %s", d.str().c_str(), ret, strerror(ret)); 56 | assert(0); 57 | } 58 | } 59 | } 60 | 61 | va_end(args); 62 | } 63 | 64 | } // end namespace gltracesim 65 | 66 | #endif // __GLTRACESIM_UTIL_MKDIR_HH__ 67 | 68 | -------------------------------------------------------------------------------- /gltracesim/src/util/sat_counter.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_SATURATION_COUNTER_HH__ 2 | #define __GLTRACESIM_SATURATION_COUNTER_HH__ 3 | 4 | namespace gltracesim { 5 | 6 | template 7 | class SatCounter { 8 | 9 | public: 10 | 11 | /** 12 | * @brief SatCounter 13 | * @param min 14 | * @param max 15 | */ 16 | SatCounter(T min = 0, T max = 1); 17 | 18 | /** 19 | * @brief min 20 | * @return 21 | */ 22 | T min() const; 23 | 24 | /** 25 | * @brief set_min 26 | * @return 27 | */ 28 | void set_min(T min); 29 | 30 | /** 31 | * @brief max 32 | * @return 33 | */ 34 | T max() const; 35 | 36 | /** 37 | * @brief set_max 38 | * @return 39 | */ 40 | void set_max(T max); 41 | 42 | /** 43 | * @brief is_max 44 | * @return 45 | */ 46 | bool is_max() const; 47 | 48 | /** 49 | * @brief is_min 50 | * @return 51 | */ 52 | bool is_min() const; 53 | 54 | /** 55 | * @brief value 56 | * @return 57 | */ 58 | T value() const; 59 | 60 | /** 61 | * @brief reset 62 | */ 63 | void set(T value); 64 | 65 | /** 66 | * @brief reset 67 | */ 68 | void reset(); 69 | 70 | /** 71 | * @brief operator < 72 | * @param r 73 | * @return 74 | */ 75 | bool operator<(const SatCounter& r) const; 76 | 77 | /** 78 | * @brief operator == 79 | * @param r 80 | * @return 81 | */ 82 | bool operator==(const SatCounter& r) const; 83 | 84 | /** 85 | * @brief operator -- 86 | */ 87 | void operator--(int); 88 | 89 | /** 90 | * @brief operator ++ 91 | */ 92 | void operator++(int); 93 | 94 | /** 95 | * @brief operator -= 96 | */ 97 | SatCounter& operator-=(const SatCounter& r); 98 | 99 | /** 100 | * @brief operator += 101 | */ 102 | SatCounter& operator+=(const SatCounter& r); 103 | 104 | private: 105 | 106 | /** 107 | * @brief min_val 108 | */ 109 | T min_val; 110 | 111 | /** 112 | * @brief max_val 113 | */ 114 | T max_val; 115 | 116 | /** 117 | * @brief val 118 | */ 119 | T val; 120 | 121 | }; 122 | 123 | } // end namespace gltracesim 124 | 125 | #include "util/sat_counter_impl.hh" 126 | 127 | #endif // __GLTRACESIM_SATURATION_COUNTER_HH__ 128 | -------------------------------------------------------------------------------- /gltracesim/src/util/sat_counter_impl.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_SATURATION_COUNTER_IMPL_HH__ 2 | #define __GLTRACESIM_SATURATION_COUNTER_IMPL_HH__ 3 | 4 | namespace gltracesim { 5 | 6 | template 7 | SatCounter::SatCounter(T min, T max) : 8 | min_val(min), max_val(max), val(min) 9 | { 10 | 11 | } 12 | 13 | template 14 | T 15 | SatCounter::min() const 16 | { 17 | return min_val; 18 | } 19 | 20 | template 21 | void 22 | SatCounter::set_min(T min) 23 | { 24 | min_val = min; 25 | } 26 | 27 | template 28 | T 29 | SatCounter::max() const 30 | { 31 | return max_val; 32 | } 33 | 34 | template 35 | void 36 | SatCounter::set_max(T max) 37 | { 38 | max_val = max; 39 | } 40 | 41 | template 42 | bool 43 | SatCounter::is_min() const 44 | { 45 | return (val == min_val); 46 | } 47 | 48 | template 49 | bool 50 | SatCounter::is_max() const 51 | { 52 | return (val == max_val); 53 | } 54 | 55 | 56 | template 57 | T 58 | SatCounter::value() const 59 | { 60 | return val; 61 | } 62 | 63 | template 64 | void 65 | SatCounter::set(T value) 66 | { 67 | if (value < min_val) { 68 | val = min_val; 69 | } else if (value > max_val) { 70 | val = max_val; 71 | } else { 72 | val = value; 73 | } 74 | } 75 | 76 | template 77 | void 78 | SatCounter::reset() 79 | { 80 | val = min_val; 81 | } 82 | 83 | template 84 | bool 85 | SatCounter::operator<(const SatCounter& r) const 86 | { 87 | return (val < r.val); 88 | } 89 | 90 | template 91 | bool 92 | SatCounter::operator==(const SatCounter& r) const 93 | { 94 | return (val == r.val); 95 | } 96 | 97 | template 98 | void 99 | SatCounter::operator--(int) 100 | { 101 | auto t = val - 1; 102 | if (t >= min_val) 103 | val = t; 104 | } 105 | 106 | template 107 | void 108 | SatCounter::operator++(int) 109 | { 110 | auto t = val + 1; 111 | if (t <= max_val) 112 | val = t; 113 | } 114 | 115 | template 116 | SatCounter& 117 | SatCounter::operator-=(const SatCounter& r) 118 | { 119 | auto t = val - r.val; 120 | if (t > min_val) 121 | val = t; 122 | return *this; 123 | } 124 | 125 | template 126 | SatCounter& 127 | SatCounter::operator+=(const SatCounter& r) 128 | { 129 | auto t = val + r.val; 130 | if (t < max_val) 131 | val = t; 132 | 133 | return *this; 134 | } 135 | 136 | } // end namespace gltracesim 137 | 138 | #endif // __GLTRACESIM_SATURATION_COUNTER_IMPL_HH__ 139 | -------------------------------------------------------------------------------- /gltracesim/src/util/threads.cc: -------------------------------------------------------------------------------- 1 | #include "util/threads.hh" 2 | 3 | namespace gltracesim { 4 | 5 | Mutex::Mutex() 6 | { 7 | #ifdef __USING_PIN__ 8 | assert(PIN_MutexInit(&mtx)); 9 | #else 10 | 11 | #endif 12 | 13 | } 14 | 15 | Mutex::~Mutex() 16 | { 17 | #ifdef __USING_PIN__ 18 | PIN_MutexFini(&mtx); 19 | #else 20 | 21 | #endif 22 | } 23 | 24 | 25 | RWRMutex::RWRMutex() 26 | { 27 | #ifdef __USING_PIN__ 28 | assert(PIN_RWMutexInit(&mtx)); 29 | #else 30 | 31 | #endif 32 | 33 | } 34 | 35 | RWRMutex::~RWRMutex() 36 | { 37 | #ifdef __USING_PIN__ 38 | PIN_RWMutexFini(&mtx); 39 | #else 40 | 41 | #endif 42 | } 43 | 44 | Semaphore::Semaphore() 45 | { 46 | #ifdef __USING_PIN__ 47 | assert(PIN_SemaphoreInit(&sem)); 48 | #else 49 | 50 | #endif 51 | } 52 | 53 | Semaphore::~Semaphore() 54 | { 55 | #ifdef __USING_PIN__ 56 | PIN_SemaphoreFini(&sem); 57 | #else 58 | 59 | #endif 60 | } 61 | 62 | } // end namespace gltracesim 63 | 64 | -------------------------------------------------------------------------------- /gltracesim/src/util/threads.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_THREADS_HH__ 2 | #define __GLTRACESIM_THREADS_HH__ 3 | 4 | #include 5 | 6 | #ifdef __USING_PIN__ 7 | #include "pin.H" 8 | #else 9 | #include 10 | #include 11 | #endif 12 | 13 | namespace gltracesim { 14 | 15 | class Mutex { 16 | 17 | public: 18 | 19 | /** 20 | * @brief Mutex 21 | */ 22 | Mutex(); 23 | 24 | /** 25 | * @brief ~Mutex 26 | */ 27 | virtual ~Mutex(); 28 | 29 | /** 30 | * @brief lock 31 | */ 32 | void lock() { 33 | #ifdef __USING_PIN__ 34 | PIN_MutexLock(&mtx); 35 | #else 36 | mtx.lock(); 37 | #endif 38 | } 39 | 40 | /** 41 | * @brief unlock 42 | */ 43 | void unlock() { 44 | #ifdef __USING_PIN__ 45 | PIN_MutexUnlock(&mtx); 46 | #else 47 | mtx.unlock(); 48 | #endif 49 | } 50 | 51 | private: 52 | 53 | #ifdef __USING_PIN__ 54 | PIN_MUTEX mtx; 55 | #else 56 | std::mutex mtx; 57 | #endif 58 | 59 | }; 60 | 61 | class RWRMutex { 62 | 63 | public: 64 | 65 | /** 66 | * @brief Mutex 67 | */ 68 | RWRMutex(); 69 | 70 | /** 71 | * @brief ~Mutex 72 | */ 73 | virtual ~RWRMutex(); 74 | 75 | /** 76 | * @brief lock 77 | */ 78 | void lock() { 79 | #ifdef __USING_PIN__ 80 | PIN_RWMutexWriteLock(&mtx); 81 | #else 82 | mtx.lock(); 83 | #endif 84 | } 85 | 86 | /** 87 | * @brief rlock 88 | */ 89 | void rlock() { 90 | #ifdef __USING_PIN__ 91 | PIN_RWMutexReadLock(&mtx); 92 | #else 93 | mtx.lock(); 94 | #endif 95 | } 96 | 97 | /** 98 | * @brief unlock 99 | */ 100 | void unlock() { 101 | #ifdef __USING_PIN__ 102 | PIN_RWMutexUnlock(&mtx); 103 | #else 104 | mtx.unlock(); 105 | #endif 106 | } 107 | 108 | private: 109 | 110 | #ifdef __USING_PIN__ 111 | PIN_RWMUTEX mtx; 112 | #else 113 | std::mutex mtx; 114 | #endif 115 | 116 | }; 117 | 118 | class Semaphore { 119 | 120 | public: 121 | 122 | /** 123 | * @brief Mutex 124 | */ 125 | Semaphore(); 126 | 127 | /** 128 | * @brief ~Mutex 129 | */ 130 | virtual ~Semaphore(); 131 | 132 | /** 133 | * @brief lock 134 | */ 135 | void set() { 136 | #ifdef __USING_PIN__ 137 | PIN_SemaphoreSet(&sem); 138 | #else 139 | assert(0); 140 | #endif 141 | } 142 | 143 | /** 144 | * @brief unlock 145 | */ 146 | void clear() { 147 | #ifdef __USING_PIN__ 148 | PIN_SemaphoreClear(&sem); 149 | #else 150 | assert(0); 151 | #endif 152 | } 153 | 154 | /** 155 | * @brief unlock 156 | */ 157 | void wait() { 158 | #ifdef __USING_PIN__ 159 | PIN_SemaphoreWait(&sem); 160 | #else 161 | assert(0); 162 | #endif 163 | } 164 | 165 | /** 166 | * @brief unlock 167 | */ 168 | bool wait(int timeout) { 169 | #ifdef __USING_PIN__ 170 | return PIN_SemaphoreTimedWait(&sem, timeout); 171 | #else 172 | assert(0); 173 | #endif 174 | } 175 | 176 | private: 177 | 178 | #ifdef __USING_PIN__ 179 | PIN_SEMAPHORE sem; 180 | #else 181 | 182 | #endif 183 | 184 | }; 185 | 186 | 187 | 188 | } // end namespace gltracesim 189 | 190 | #endif // __GLTRACESIM_THREADS_HH__ 191 | -------------------------------------------------------------------------------- /gltracesim/src/util/timer.cc: -------------------------------------------------------------------------------- 1 | #include "util/timer.hh" 2 | 3 | namespace gltracesim { 4 | 5 | Timer::Timer() 6 | { 7 | 8 | } 9 | 10 | void 11 | Timer::start() 12 | { 13 | // 14 | start_time = std::chrono::system_clock::now(); 15 | } 16 | 17 | void 18 | Timer::stop() 19 | { 20 | // 21 | stop_time = std::chrono::system_clock::now(); 22 | } 23 | 24 | double 25 | Timer::duration() 26 | { 27 | // 28 | std::chrono::duration d = stop_time - start_time; 29 | // 30 | return d.count(); 31 | } 32 | 33 | } // end namespace gltracesim 34 | 35 | -------------------------------------------------------------------------------- /gltracesim/src/util/timer.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_TIMER_HH__ 2 | #define __GLTRACESIM_TIMER_HH__ 3 | 4 | #include 5 | 6 | namespace gltracesim { 7 | 8 | class Timer { 9 | 10 | public: 11 | 12 | Timer(); 13 | 14 | public: 15 | 16 | /** 17 | * @brief start 18 | */ 19 | void start(); 20 | 21 | /** 22 | * @brief stop 23 | */ 24 | void stop(); 25 | 26 | /** 27 | * @brief duration 28 | * @return 29 | */ 30 | double duration(); 31 | 32 | protected: 33 | 34 | /** 35 | * @brief time_point_t 36 | */ 37 | typedef std::chrono::time_point time_point_t; 38 | 39 | /** 40 | * @brief start 41 | */ 42 | time_point_t start_time; 43 | 44 | /** 45 | * @brief stop 46 | */ 47 | time_point_t stop_time; 48 | 49 | }; 50 | 51 | } // end namespace gltracesim 52 | 53 | #endif // __GLTRACESIM_TIMER_HH__ 54 | -------------------------------------------------------------------------------- /gltracesim/src/vmemory.hh: -------------------------------------------------------------------------------- 1 | #ifndef __GLTRACESIM_VMEMORY_HH__ 2 | #define __GLTRACESIM_VMEMORY_HH__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "util/addr_range.hh" 13 | #include "util/addr_range_map.hh" 14 | 15 | namespace gltracesim { 16 | 17 | class VirtualMemoryManager; 18 | 19 | /** 20 | * @brief 21 | */ 22 | typedef std::unique_ptr VirtualMemoryManagerPtr; 23 | 24 | /** 25 | * @brief The VirtualMemoryManager class 26 | * 27 | * Reverse memory allocator, given a virtual address, allocate a fake physical 28 | * address. 29 | * 30 | */ 31 | class VirtualMemoryManager 32 | { 33 | 34 | public: 35 | 36 | /** 37 | * @brief VirtualMemoryManager 38 | * @param name 39 | */ 40 | VirtualMemoryManager(const Json::Value ¶ms); 41 | 42 | /** 43 | * @brief ~VirtualMemoryManager 44 | */ 45 | ~VirtualMemoryManager(); 46 | 47 | public: 48 | 49 | /** 50 | * @brief get_name 51 | * @return 52 | */ 53 | uint64_t translate(uint64_t vaddr); 54 | 55 | /** 56 | * @brief get_name 57 | * @return 58 | */ 59 | void alloc(const AddrRange &vaddr_range); 60 | 61 | /** 62 | * @brief get_name 63 | * @return 64 | */ 65 | void free(const AddrRange &vaddr_range); 66 | 67 | private: 68 | 69 | /** 70 | * @brief get_free_page 71 | * @param i 72 | * @param j 73 | */ 74 | void find_free_page(size_t &i, size_t &j); 75 | 76 | /** 77 | * @brief get_num_free_pages 78 | * @return 79 | */ 80 | size_t get_num_free_pages() const; 81 | 82 | /** 83 | * @brief get_page_addr 84 | * @param addr 85 | * @return 86 | */ 87 | uint64_t get_page_addr(uint64_t addr) const 88 | { 89 | return (addr & page_addr_umask); 90 | } 91 | 92 | /** 93 | * @brief get_page_offset 94 | * @param addr 95 | * @return 96 | */ 97 | uint64_t get_page_offset(uint64_t addr) const 98 | { 99 | return (addr & ~page_addr_umask); 100 | } 101 | 102 | private: 103 | 104 | /** 105 | * @brief base_addr 106 | */ 107 | uint64_t base_addr; 108 | 109 | /** 110 | * @brief page_size 111 | */ 112 | uint64_t page_size; 113 | 114 | /** 115 | * @brief page_addr_umask 116 | */ 117 | uint64_t page_addr_umask; 118 | 119 | /** 120 | * @brief fragmented 121 | */ 122 | bool fragmented; 123 | 124 | /** 125 | * @brief rand_engine 126 | */ 127 | std::mt19937 rand_engine; 128 | 129 | /** 130 | * @brief translation_t 131 | */ 132 | typedef AddrRangeMap translation_t; 133 | 134 | /** 135 | * @brief translation 136 | */ 137 | translation_t translation; 138 | 139 | #define STATE_T_SIZE 256 140 | 141 | /** 142 | * @brief state_t 143 | * 144 | * 256 * 4kB page == 1MB state; 145 | * 146 | */ 147 | typedef std::bitset state_t; 148 | 149 | /** 150 | * @brief free_list 151 | */ 152 | std::vector free_list; 153 | 154 | /** 155 | * @brief allocated 156 | */ 157 | size_t allocated; 158 | 159 | }; 160 | 161 | } // end namespace gltracesim 162 | 163 | #endif // __GLTRACESIM_VMEMORY_HH__ 164 | -------------------------------------------------------------------------------- /tools/frame-print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, io 4 | import packet_pb2 as packet 5 | import frame_pb2 as frame 6 | import stream 7 | 8 | # Example from https://developers.google.com/protocol-buffers/docs/pythontutorial 9 | if len(sys.argv) != 2: 10 | print "Usage:", sys.argv[0], "frames.pb.gz" 11 | sys.exit(-1) 12 | 13 | # Open the file and discard the header 14 | istream = stream.open(sys.argv[1], "rb") 15 | 16 | for msg in istream: 17 | hdr = packet.PacketHeader() 18 | hdr.ParseFromString(msg) 19 | print hdr 20 | break 21 | 22 | for msg in istream: 23 | frameinfo = frame.FrameInfo() 24 | frameinfo.ParseFromString(msg) 25 | print frameinfo 26 | 27 | # Close the file 28 | istream.close() 29 | -------------------------------------------------------------------------------- /tools/job-print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, io 4 | import packet_pb2 as packet 5 | import job_pb2 as job 6 | import stream 7 | 8 | # Example from https://developers.google.com/protocol-buffers/docs/pythontutorial 9 | if len(sys.argv) != 2: 10 | print "Usage:", sys.argv[0], "jobs.pb.gz" 11 | sys.exit(-1) 12 | 13 | # Open the file and discard the header 14 | istream = stream.open(sys.argv[1], "rb") 15 | 16 | for msg in istream: 17 | hdr = packet.PacketHeader() 18 | hdr.ParseFromString(msg) 19 | print hdr 20 | #break 21 | 22 | for msg in istream: 23 | jobinfo = job.JobInfo() 24 | jobinfo.ParseFromString(msg) 25 | print jobinfo 26 | 27 | # Close the file 28 | istream.close() 29 | 30 | -------------------------------------------------------------------------------- /tools/scene-print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, io 4 | import packet_pb2 as packet 5 | import scene_pb2 as scene 6 | import stream 7 | 8 | # Example from https://developers.google.com/protocol-buffers/docs/pythontutorial 9 | if len(sys.argv) != 2: 10 | print "Usage:", sys.argv[0], "scenes.pb.gz" 11 | sys.exit(-1) 12 | 13 | # Open the file and discard the header 14 | istream = stream.open(sys.argv[1], "rb") 15 | 16 | for msg in istream: 17 | hdr = packet.PacketHeader() 18 | hdr.ParseFromString(msg) 19 | print hdr 20 | break 21 | 22 | for msg in istream: 23 | sceneinfo = scene.SceneInfo() 24 | sceneinfo.ParseFromString(msg) 25 | print sceneinfo 26 | 27 | # Close the file 28 | istream.close() 29 | 30 | -------------------------------------------------------------------------------- /tools/stats-print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, io 4 | import packet_pb2 as packet 5 | import stats.cache_pb2 as cache 6 | import stream 7 | 8 | # Example from https://developers.google.com/protocol-buffers/docs/pythontutorial 9 | if len(sys.argv) != 2: 10 | print "Usage:", sys.argv[0], "stats.pb.gz" 11 | sys.exit(-1) 12 | 13 | # Open the file and discard the header 14 | istream = stream.open(sys.argv[1], "rb") 15 | 16 | for msg in istream: 17 | hdr = packet.PacketHeader() 18 | hdr.ParseFromString(msg) 19 | print hdr 20 | break 21 | 22 | for msg in istream: 23 | cachestats = cache.CacheStats() 24 | cachestats.ParseFromString(msg) 25 | print cachestats 26 | 27 | # Close the file 28 | istream.close() 29 | 30 | -------------------------------------------------------------------------------- /tools/stream/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | """ 4 | stream 5 | ~~~~~~~~ 6 | 7 | Python implementation of stream library. See README file for more 8 | information. 9 | 10 | :copyright: (c) 2016 by Ali Ghaffaari. 11 | :license: MIT, see LICENSE for more details. 12 | """ 13 | 14 | from .stream import open # noqa pylint: disable=redefined-builtin 15 | from .stream import Stream # noqa 16 | from . import release # noqa 17 | -------------------------------------------------------------------------------- /tools/stream/release.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | """Include release information of the 'pystream-protobuf' package.""" 4 | 5 | # CONSTANTS #################################################################### 6 | # Development statuses: 7 | DS_PLANNING = 1 8 | DS_PREALPHA = 2 9 | DS_ALPHA = 3 10 | DS_BETA = 4 11 | DS_STABLE = 5 12 | DS_MATURE = 6 13 | DS_INACTIVE = 7 14 | DS_STRING = { 15 | DS_PLANNING: "Development Status :: 1 - Planning", 16 | DS_PREALPHA: "Development Status :: 2 - Pre-Alpha", 17 | DS_ALPHA: "Development Status :: 3 - Alpha", 18 | DS_BETA: "Development Status :: 4 - Beta", 19 | DS_STABLE: "Development Status :: 5 - Production/Stable", 20 | DS_MATURE: "Development Status :: 6 - Mature", 21 | DS_INACTIVE: "Development Status :: 7 - Inactive" 22 | } 23 | ################################################################################ 24 | 25 | # Package release information. 26 | __title__ = "stream" 27 | __description__ = "Python implementation of stream library" 28 | __author__ = "Ali Ghaffaari" 29 | __email__ = "ali.ghaffaari@mpi-inf.mpg.de" 30 | __license__ = "MIT" 31 | 32 | # Release 33 | __version__ = "1.3.4" 34 | __status__ = DS_BETA 35 | 36 | # PyPI-related information 37 | __keywords__ = ['protobuf', 'stream', 'protocol buffer'] 38 | __classifiers__ = [ 39 | # Development status 40 | DS_STRING[__status__], 41 | 42 | # License 43 | 'License :: OSI Approved :: MIT License', 44 | 45 | # Supported Python versions. 46 | 'Programming Language :: Python :: 3.3', 47 | 'Programming Language :: Python :: 3.4', 48 | 'Programming Language :: Python :: 3.5', 49 | 50 | # Intended Audience and Topic 51 | 'Intended Audience :: Developers', 52 | ] 53 | __requires__ = ['protobuf>=3.0.0'] 54 | __tests_require__ = [] 55 | __extras_require__ = { 56 | 'test': ['nose'], 57 | } 58 | -------------------------------------------------------------------------------- /traces/GET_TRACES: -------------------------------------------------------------------------------- 1 | You can download and get some apitrace pre-generated OpenGL call traces from 2 | 3 | https://www.dropbox.com/sh/a9khvc51krx8h6t/AAB3UUDLbHh_FONua-z-2xuta 4 | 5 | Extract them in traces/ 6 | 7 | --------------------------------------------------------------------------------