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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>GPU Pooling Algorithm</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+Pro:wght@300;400;600&family=Source+Sans+Pro:wght@400;500;600&display=swap');
|
| 15 |
+
|
| 16 |
+
body {
|
| 17 |
+
background: #ffffff;
|
| 18 |
+
color: #000000;
|
| 19 |
+
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
|
| 20 |
+
min-height: 100vh;
|
| 21 |
+
display: flex;
|
| 22 |
+
flex-direction: column;
|
| 23 |
+
align-items: center;
|
| 24 |
+
padding: 20px;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.container {
|
| 28 |
+
max-width: 800px;
|
| 29 |
+
width: 100%;
|
| 30 |
+
padding: 0 10px;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.title {
|
| 34 |
+
text-align: center;
|
| 35 |
+
font-size: 1.8rem;
|
| 36 |
+
margin-bottom: 20px;
|
| 37 |
+
color: #000000;
|
| 38 |
+
font-family: 'Source Serif Pro', Georgia, serif;
|
| 39 |
+
font-weight: 400;
|
| 40 |
+
letter-spacing: 0.5px;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.section {
|
| 44 |
+
margin: 15px 0;
|
| 45 |
+
position: relative;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.section-title {
|
| 49 |
+
text-align: center;
|
| 50 |
+
font-size: 1.1rem;
|
| 51 |
+
margin-bottom: 10px;
|
| 52 |
+
color: #000000;
|
| 53 |
+
font-family: 'Source Serif Pro', Georgia, serif;
|
| 54 |
+
font-weight: 400;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.array-container {
|
| 58 |
+
display: flex;
|
| 59 |
+
justify-content: center;
|
| 60 |
+
gap: 4px;
|
| 61 |
+
margin: 15px 0;
|
| 62 |
+
flex-wrap: wrap;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.array-element {
|
| 66 |
+
width: 50px;
|
| 67 |
+
height: 40px;
|
| 68 |
+
border: 2px solid #000000;
|
| 69 |
+
border-radius: 4px;
|
| 70 |
+
display: flex;
|
| 71 |
+
flex-direction: column;
|
| 72 |
+
align-items: center;
|
| 73 |
+
justify-content: center;
|
| 74 |
+
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 75 |
+
font-size: 10px;
|
| 76 |
+
font-weight: 500;
|
| 77 |
+
background: #ffffff;
|
| 78 |
+
transition: all 0.3s ease;
|
| 79 |
+
position: relative;
|
| 80 |
+
text-align: center;
|
| 81 |
+
line-height: 1;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.array-element .value {
|
| 85 |
+
font-size: 12px;
|
| 86 |
+
font-weight: 600;
|
| 87 |
+
margin-bottom: 2px;
|
| 88 |
+
font-feature-settings: 'tnum';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.array-element .label {
|
| 92 |
+
font-size: 8px;
|
| 93 |
+
color: #666;
|
| 94 |
+
font-weight: 400;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.array-element.highlight {
|
| 98 |
+
background: #f0f0f0;
|
| 99 |
+
border-color: #000000;
|
| 100 |
+
border-width: 3px;
|
| 101 |
+
transform: scale(1.05);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.array-element.processing {
|
| 105 |
+
background: #e0e0e0;
|
| 106 |
+
border-color: #666666;
|
| 107 |
+
border-width: 3px;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.block-container {
|
| 111 |
+
background: #f8f8f8;
|
| 112 |
+
border: 2px solid #000000;
|
| 113 |
+
border-radius: 6px;
|
| 114 |
+
padding: 15px;
|
| 115 |
+
margin: 20px 0;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.threads-container {
|
| 119 |
+
display: flex;
|
| 120 |
+
justify-content: center;
|
| 121 |
+
gap: 4px;
|
| 122 |
+
margin: 15px 0;
|
| 123 |
+
flex-wrap: wrap;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.thread {
|
| 127 |
+
width: 50px;
|
| 128 |
+
height: 40px;
|
| 129 |
+
border: 2px solid #666666;
|
| 130 |
+
border-radius: 4px;
|
| 131 |
+
display: flex;
|
| 132 |
+
align-items: center;
|
| 133 |
+
justify-content: center;
|
| 134 |
+
font-size: 11px;
|
| 135 |
+
background: #ffffff;
|
| 136 |
+
transition: all 0.3s ease;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.thread.active {
|
| 140 |
+
background: #d0d0d0;
|
| 141 |
+
border-color: #000000;
|
| 142 |
+
border-width: 3px;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.barrier {
|
| 146 |
+
width: 100%;
|
| 147 |
+
height: 2px;
|
| 148 |
+
background: repeating-linear-gradient(
|
| 149 |
+
90deg,
|
| 150 |
+
#000000 0px,
|
| 151 |
+
#000000 8px,
|
| 152 |
+
transparent 8px,
|
| 153 |
+
transparent 16px
|
| 154 |
+
);
|
| 155 |
+
margin: 15px 0;
|
| 156 |
+
position: relative;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.barrier::after {
|
| 160 |
+
content: "Barrier";
|
| 161 |
+
position: absolute;
|
| 162 |
+
right: 0;
|
| 163 |
+
top: -20px;
|
| 164 |
+
color: #000000;
|
| 165 |
+
font-size: 12px;
|
| 166 |
+
font-weight: 500;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.shared-memory {
|
| 170 |
+
background: #f0f0f0;
|
| 171 |
+
border: 2px solid #333333;
|
| 172 |
+
border-radius: 4px;
|
| 173 |
+
padding: 15px;
|
| 174 |
+
margin: 15px 0;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.memory-info {
|
| 178 |
+
text-align: center;
|
| 179 |
+
margin-bottom: 10px;
|
| 180 |
+
color: #000000;
|
| 181 |
+
font-weight: 500;
|
| 182 |
+
font-size: 12px;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
.memory-elements {
|
| 186 |
+
display: flex;
|
| 187 |
+
justify-content: center;
|
| 188 |
+
gap: 3px;
|
| 189 |
+
flex-wrap: wrap;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.memory-element {
|
| 193 |
+
width: 40px;
|
| 194 |
+
height: 30px;
|
| 195 |
+
border: 1px solid #666666;
|
| 196 |
+
border-radius: 3px;
|
| 197 |
+
display: flex;
|
| 198 |
+
align-items: center;
|
| 199 |
+
justify-content: center;
|
| 200 |
+
font-size: 9px;
|
| 201 |
+
background: #ffffff;
|
| 202 |
+
transition: all 0.3s ease;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.window-highlight {
|
| 206 |
+
background: #e0e0e0;
|
| 207 |
+
border-color: #000000;
|
| 208 |
+
border-width: 2px;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.window-info {
|
| 212 |
+
text-align: center;
|
| 213 |
+
margin: 8px 0;
|
| 214 |
+
color: #333333;
|
| 215 |
+
font-weight: 500;
|
| 216 |
+
font-size: 11px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.output-container {
|
| 220 |
+
border: 2px solid #000000;
|
| 221 |
+
border-radius: 6px;
|
| 222 |
+
padding: 20px;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.controls {
|
| 226 |
+
text-align: center;
|
| 227 |
+
margin: 30px 0;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.btn {
|
| 231 |
+
background: #000000;
|
| 232 |
+
border: 2px solid #000000;
|
| 233 |
+
padding: 12px 30px;
|
| 234 |
+
border-radius: 4px;
|
| 235 |
+
color: white;
|
| 236 |
+
font-size: 16px;
|
| 237 |
+
cursor: pointer;
|
| 238 |
+
margin: 0 10px;
|
| 239 |
+
transition: all 0.3s ease;
|
| 240 |
+
font-weight: 500;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
.btn:hover {
|
| 244 |
+
background: #333333;
|
| 245 |
+
transform: translateY(-1px);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
.btn:active {
|
| 249 |
+
transform: translateY(0);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
.connection-line {
|
| 253 |
+
position: absolute;
|
| 254 |
+
background: #000000;
|
| 255 |
+
height: 2px;
|
| 256 |
+
opacity: 0;
|
| 257 |
+
transition: opacity 0.5s ease;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.connection-line.show {
|
| 261 |
+
opacity: 1;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
.stats {
|
| 265 |
+
display: flex;
|
| 266 |
+
justify-content: space-around;
|
| 267 |
+
margin: 20px 0;
|
| 268 |
+
padding: 15px;
|
| 269 |
+
background: #f8f8f8;
|
| 270 |
+
border: 1px solid #cccccc;
|
| 271 |
+
border-radius: 6px;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
.stat {
|
| 275 |
+
text-align: center;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
.stat-value {
|
| 279 |
+
font-size: 1.5rem;
|
| 280 |
+
color: #000000;
|
| 281 |
+
font-weight: 600;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
.stat-label {
|
| 285 |
+
font-size: 0.9rem;
|
| 286 |
+
color: #666666;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
@keyframes pulse {
|
| 290 |
+
0%, 100% { opacity: 1; }
|
| 291 |
+
50% { opacity: 0.5; }
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
.processing {
|
| 295 |
+
animation: pulse 1s infinite;
|
| 296 |
+
}
|
| 297 |
+
</style>
|
| 298 |
+
</head>
|
| 299 |
+
<body>
|
| 300 |
+
<div class="container">
|
| 301 |
+
<h1 class="title">GPU Sum Pooling Algorithm</h1>
|
| 302 |
+
|
| 303 |
+
<div class="stats">
|
| 304 |
+
<div class="stat">
|
| 305 |
+
<div class="stat-value" id="window-size">3</div>
|
| 306 |
+
<div class="stat-label">Window Size</div>
|
| 307 |
+
</div>
|
| 308 |
+
<div class="stat">
|
| 309 |
+
<div class="stat-value" id="threads-count">8</div>
|
| 310 |
+
<div class="stat-label">Threads</div>
|
| 311 |
+
</div>
|
| 312 |
+
<div class="stat">
|
| 313 |
+
<div class="stat-value" id="current-step">0</div>
|
| 314 |
+
<div class="stat-label">Current Step</div>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
|
| 318 |
+
<div class="section">
|
| 319 |
+
<div class="section-title">Input Array (size=8)</div>
|
| 320 |
+
<div class="array-container" id="input-array">
|
| 321 |
+
<!-- Generated dynamically -->
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
+
<div class="block-container">
|
| 326 |
+
<div class="section-title">Block 0</div>
|
| 327 |
+
|
| 328 |
+
<div class="threads-container" id="threads">
|
| 329 |
+
<!-- Generated dynamically -->
|
| 330 |
+
</div>
|
| 331 |
+
|
| 332 |
+
<div class="barrier"></div>
|
| 333 |
+
|
| 334 |
+
<div class="shared-memory">
|
| 335 |
+
<div class="memory-info">
|
| 336 |
+
Shared Memory (TPB=8) • <span style="color: #333333; font-weight: 600;">Parallel Processing</span>
|
| 337 |
+
</div>
|
| 338 |
+
<div class="window-info">Sum Pooling (Window=3)</div>
|
| 339 |
+
<div class="memory-elements" id="shared-memory">
|
| 340 |
+
<!-- Generated dynamically -->
|
| 341 |
+
</div>
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
|
| 345 |
+
<div class="section output-container">
|
| 346 |
+
<div class="section-title">Output Array (size=8)</div>
|
| 347 |
+
<div class="array-container" id="output-array">
|
| 348 |
+
<!-- Generated dynamically -->
|
| 349 |
+
</div>
|
| 350 |
+
</div>
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
</div>
|
| 354 |
+
|
| 355 |
+
<script>
|
| 356 |
+
const ARRAY_SIZE = 8;
|
| 357 |
+
const WINDOW_SIZE = 3;
|
| 358 |
+
let currentStep = 0;
|
| 359 |
+
let animationInterval;
|
| 360 |
+
|
| 361 |
+
// Sample input data
|
| 362 |
+
const inputData = [1.2, 2.8, 0.5, 3.1, 1.9, 2.3, 0.8, 1.7];
|
| 363 |
+
|
| 364 |
+
function initializeVisualization() {
|
| 365 |
+
createInputArray();
|
| 366 |
+
createThreads();
|
| 367 |
+
createSharedMemory();
|
| 368 |
+
createOutputArray();
|
| 369 |
+
startLoopingAnimation();
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function createInputArray() {
|
| 373 |
+
const container = document.getElementById('input-array');
|
| 374 |
+
container.innerHTML = '';
|
| 375 |
+
|
| 376 |
+
for (let i = 0; i < ARRAY_SIZE; i++) {
|
| 377 |
+
const element = document.createElement('div');
|
| 378 |
+
element.className = 'array-element';
|
| 379 |
+
element.innerHTML = `<div class="value">${inputData[i]}</div><div class="label">a[${i}]</div>`;
|
| 380 |
+
element.id = `input-${i}`;
|
| 381 |
+
element.title = `a[${i}] = ${inputData[i]}`;
|
| 382 |
+
container.appendChild(element);
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function createThreads() {
|
| 387 |
+
const container = document.getElementById('threads');
|
| 388 |
+
container.innerHTML = '';
|
| 389 |
+
|
| 390 |
+
for (let i = 0; i < ARRAY_SIZE; i++) {
|
| 391 |
+
const thread = document.createElement('div');
|
| 392 |
+
thread.className = 'thread';
|
| 393 |
+
thread.textContent = `T${i}`;
|
| 394 |
+
thread.id = `thread-${i}`;
|
| 395 |
+
container.appendChild(thread);
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
function createSharedMemory() {
|
| 400 |
+
const container = document.getElementById('shared-memory');
|
| 401 |
+
container.innerHTML = '';
|
| 402 |
+
|
| 403 |
+
for (let i = 0; i < ARRAY_SIZE; i++) {
|
| 404 |
+
const element = document.createElement('div');
|
| 405 |
+
element.className = 'memory-element';
|
| 406 |
+
element.textContent = `data[${i}]`;
|
| 407 |
+
element.id = `memory-${i}`;
|
| 408 |
+
container.appendChild(element);
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
function createOutputArray() {
|
| 413 |
+
const container = document.getElementById('output-array');
|
| 414 |
+
container.innerHTML = '';
|
| 415 |
+
|
| 416 |
+
for (let i = 0; i < ARRAY_SIZE; i++) {
|
| 417 |
+
const element = document.createElement('div');
|
| 418 |
+
element.className = 'array-element';
|
| 419 |
+
element.textContent = `out[${i}]`;
|
| 420 |
+
element.id = `output-${i}`;
|
| 421 |
+
container.appendChild(element);
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
function clearHighlights() {
|
| 426 |
+
document.querySelectorAll('.highlight, .processing, .active, .window-highlight').forEach(el => {
|
| 427 |
+
el.classList.remove('highlight', 'processing', 'active', 'window-highlight');
|
| 428 |
+
});
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
function highlightWindow(threadId) {
|
| 432 |
+
clearHighlights();
|
| 433 |
+
|
| 434 |
+
// Highlight active thread
|
| 435 |
+
document.getElementById(`thread-${threadId}`).classList.add('active');
|
| 436 |
+
|
| 437 |
+
// Determine window start and end for current position
|
| 438 |
+
let windowStart, windowEnd;
|
| 439 |
+
|
| 440 |
+
if (threadId < WINDOW_SIZE) {
|
| 441 |
+
// Growing window: out[0]=data[0], out[1]=data[0:1], out[2]=data[0:2]
|
| 442 |
+
windowStart = 0;
|
| 443 |
+
windowEnd = threadId + 1;
|
| 444 |
+
} else {
|
| 445 |
+
// Sliding window of size 3: out[3]=data[1:3], out[4]=data[2:4], etc.
|
| 446 |
+
windowStart = threadId - WINDOW_SIZE + 1;
|
| 447 |
+
windowEnd = threadId + 1;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// Highlight input window
|
| 451 |
+
for (let i = windowStart; i < windowEnd; i++) {
|
| 452 |
+
document.getElementById(`input-${i}`).classList.add('highlight');
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
// Highlight memory window
|
| 456 |
+
for (let i = windowStart; i < windowEnd; i++) {
|
| 457 |
+
document.getElementById(`memory-${i}`).classList.add('window-highlight');
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
// Calculate sum of elements in window
|
| 461 |
+
let sum = 0;
|
| 462 |
+
for (let i = windowStart; i < windowEnd; i++) {
|
| 463 |
+
sum += inputData[i];
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
// Highlight output
|
| 467 |
+
const outputElement = document.getElementById(`output-${threadId}`);
|
| 468 |
+
outputElement.classList.add('processing');
|
| 469 |
+
setTimeout(() => {
|
| 470 |
+
outputElement.textContent = sum.toFixed(1);
|
| 471 |
+
outputElement.classList.remove('processing');
|
| 472 |
+
outputElement.classList.add('highlight');
|
| 473 |
+
}, 400);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
function stepAnimation() {
|
| 477 |
+
if (currentStep < ARRAY_SIZE) {
|
| 478 |
+
highlightWindow(currentStep);
|
| 479 |
+
document.getElementById('current-step').textContent = currentStep + 1;
|
| 480 |
+
currentStep++;
|
| 481 |
+
} else {
|
| 482 |
+
// Reset for next loop
|
| 483 |
+
resetAnimation();
|
| 484 |
+
currentStep = 0;
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
function startLoopingAnimation() {
|
| 489 |
+
// Clear any existing interval
|
| 490 |
+
if (animationInterval) {
|
| 491 |
+
clearInterval(animationInterval);
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
// Start the looping animation
|
| 495 |
+
animationInterval = setInterval(() => {
|
| 496 |
+
stepAnimation();
|
| 497 |
+
}, 1200);
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
function resetAnimation() {
|
| 501 |
+
document.getElementById('current-step').textContent = '0';
|
| 502 |
+
clearHighlights();
|
| 503 |
+
|
| 504 |
+
// Reset output array
|
| 505 |
+
for (let i = 0; i < ARRAY_SIZE; i++) {
|
| 506 |
+
document.getElementById(`output-${i}`).textContent = `out[${i}]`;
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
// Initialize on page load
|
| 511 |
+
window.addEventListener('load', initializeVisualization);
|
| 512 |
+
</script>
|
| 513 |
+
</body>
|
| 514 |
+
</html>
|