summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/stitch/data/cif/expected_C.txt
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/stitch/data/cif/expected_C.txt')
0 files changed, 0 insertions, 0 deletions
' href='#n86'>86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
/* Copyright 2022 Joshua Bakita
 * Starts two copies of configurable size in seperate contexts at the same time
 * (by default) and logs the times that pages are copied to the GPU. Supports
 * monitoring copy progress from either the GPU or the CPU. All output times are
 * converted to ns.
 * Some assumptions:
 * - GPU clock ticks at a constant rate
 * - GPU clock ticks even while GPU is idle
 * - Different contexts view the same underlying GPU clock

WARNING: By default, assumes that GPU and CPU clocks tick at the same rate.
 *
 */
#include "copy_testbench.h"
#include "../task_host_utilities.cu" // Just for GetHostDeviceTimeOffset()
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <cuda.h>
#include <pthread.h>
#include <argp.h>

// Data for the help text(s)
const char* maintainer = "<jbakita@cs.unc.edu>";
const char* version = "mon_cross_ctx_copies 2023.06";
const char* desc =
    "Copy data to, from, or between GPU(s) and log the time that each block "
    "of the copy completes. Data need not be transferred sequentially for "
    "transfer times to be properly recorded.";

const struct argp_option opts[] = {
    {"copy_size", 's', "NUM_PAGES", 0, "Number of 4KiB pages to copy"},
    {"gpu", 'g', /*"DIRECTION"*/0, 0, "Add a GPU-monitored copy thread (can be duplicated)"},
    {"cpu", 'c', /*"DIRECTION"*/0, 0, "Add a CPU-monitored copy thread (can be duplicated)"},
    {0}
};

// CPU-only monitoring can only go a fraction of the speed of GPU monitoring.
// This sets how much slower it should go.
// WARNING: Setting this too low will result in low clock resolution, but
//          setting this too high will result in low unique sample count.
static const int CPU_MON_DIVISOR = 50;
// A single GPU thread cannot log page times as fast as they can be copied, so
// spread the work across multiple threads.
// WARNING: Setting this too high will result in extra memory contention, but
//          setting this too low will result in inaccurate copy logs.
// Known working settings:
// | Chip:  | Num threads:
// | GV100  | 8
// | GV11b  | 32
static const int GPU_MON_THREADS = 32;
// If delay start is enabled on any thread, how great is the delay?
static const struct timespec DELAY_TIME = {0, 50*1000l*1000l}; // 50ms (use 30ms for GV100)
// Should each GPU-copy-monitoring thread check for GPU clock skew?
static const bool SKEW_CHECK = false;

// Size of each copy to the GPU, in bytes
static unsigned int COPY_SIZE;
// GPU time offset. CPU time = GPU time - offset
static uint64_t GPU_TIME_OFFSET;
// Copy start barrier
static unsigned int READY = 0;

typedef enum {
	CPU_MONITORING,
	GPU_MONITORING,
	DELAY_START,  // For DELAY_TIME as set above
} my_config_t;

typedef struct {
	int is_ready;
	my_config_t config;
} copy_thread_args_t;

// Repeatedly update a time counter in the last 8 bytes of every Nth page, where N is CPU_MON_DIVISOR
void cpu_copy_mon(int loops, char* cpu_mem) {
	struct timespec curr_time;
	uint64_t curr_time_64;

	for (int i = 0; i < loops; i++) {
		clock_gettime(CLOCK_MONOTONIC_RAW, &curr_time);
		curr_time_64 = s2ns(curr_time.tv_sec);
		curr_time_64 += curr_time.tv_nsec;
		// Updating pages is slower than the CE, so sparely timestamp
		for (int offset = 0; offset < COPY_SIZE; offset += PG_SZ * CPU_MON_DIVISOR - 8)
			*(uint64_t*)(cpu_mem + offset) = curr_time_64;
	}
}

// Run a single copy in it's own context (intended to be run as a thread)
void* copy_thread(void* args_raw) {
	CUcontext ctx;
	int dev, i;
	cudaError_t err;
	int *barrier;
	int *barrier_dev_ptr; // On Pascal+ this will be the same as *barrier