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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>CUDA Grid Visualizer</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg-color: #121212;
|
| 10 |
+
--text-color: #e0e0e0;
|
| 11 |
+
--input-bg: #2a2a2a;
|
| 12 |
+
--input-text: #ffffff;
|
| 13 |
+
--grid-bg: #1e272e;
|
| 14 |
+
--thread-bg: #34495e;
|
| 15 |
+
--thread-hover: #3498db;
|
| 16 |
+
--info-bg: #1a2327;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 21 |
+
display: flex;
|
| 22 |
+
flex-direction: column;
|
| 23 |
+
align-items: center;
|
| 24 |
+
padding: 20px;
|
| 25 |
+
background-color: var(--bg-color);
|
| 26 |
+
color: var(--text-color);
|
| 27 |
+
transition: all 0.3s ease;
|
| 28 |
+
min-height: 100vh;
|
| 29 |
+
margin: 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
h1 {
|
| 33 |
+
margin-bottom: 20px;
|
| 34 |
+
font-size: 2.5em;
|
| 35 |
+
text-align: center;
|
| 36 |
+
color: #3498db;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
#controls {
|
| 40 |
+
display: flex;
|
| 41 |
+
flex-wrap: wrap;
|
| 42 |
+
gap: 20px;
|
| 43 |
+
margin-bottom: 30px;
|
| 44 |
+
justify-content: center;
|
| 45 |
+
background-color: var(--input-bg);
|
| 46 |
+
padding: 20px;
|
| 47 |
+
border-radius: 10px;
|
| 48 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.input-group {
|
| 52 |
+
display: flex;
|
| 53 |
+
flex-direction: column;
|
| 54 |
+
align-items: center;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
label {
|
| 58 |
+
margin-bottom: 8px;
|
| 59 |
+
font-size: 1em;
|
| 60 |
+
color: #3498db;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
input {
|
| 64 |
+
width: 70px;
|
| 65 |
+
padding: 10px;
|
| 66 |
+
border: none;
|
| 67 |
+
border-radius: 5px;
|
| 68 |
+
background-color: var(--input-bg);
|
| 69 |
+
color: var(--input-text);
|
| 70 |
+
text-align: center;
|
| 71 |
+
font-size: 1.1em;
|
| 72 |
+
transition: all 0.3s ease;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
input:focus {
|
| 76 |
+
outline: none;
|
| 77 |
+
box-shadow: 0 0 0 2px #3498db;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
#grid-container {
|
| 81 |
+
display: flex;
|
| 82 |
+
flex-wrap: wrap;
|
| 83 |
+
gap: 2px;
|
| 84 |
+
background-color: var(--grid-bg);
|
| 85 |
+
padding: 4px;
|
| 86 |
+
border-radius: 10px;
|
| 87 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
|
| 88 |
+
max-width: 90vw;
|
| 89 |
+
justify-content: flex-start;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.thread {
|
| 93 |
+
width: 30px;
|
| 94 |
+
height: 30px;
|
| 95 |
+
display: flex;
|
| 96 |
+
justify-content: center;
|
| 97 |
+
align-items: center;
|
| 98 |
+
font-size: 0.9em;
|
| 99 |
+
cursor: pointer;
|
| 100 |
+
border-radius: 4px;
|
| 101 |
+
transition: all 0.2s ease;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.thread:hover {
|
| 105 |
+
transform: scale(1.1);
|
| 106 |
+
z-index: 1;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
#info-panel {
|
| 110 |
+
margin-top: 30px;
|
| 111 |
+
padding: 20px;
|
| 112 |
+
background-color: var(--info-bg);
|
| 113 |
+
border-radius: 10px;
|
| 114 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 115 |
+
max-width: 350px;
|
| 116 |
+
width: 100%;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#info-panel p {
|
| 120 |
+
margin: 10px 0;
|
| 121 |
+
font-size: 1em;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
#info-panel strong {
|
| 125 |
+
color: #3498db;
|
| 126 |
+
}
|
| 127 |
+
</style>
|
| 128 |
+
</head>
|
| 129 |
+
<body>
|
| 130 |
+
<h1>CUDA Grid Visualizer</h1>
|
| 131 |
+
<div id="controls">
|
| 132 |
+
<div class="input-group">
|
| 133 |
+
<label for="num-blocks">Number of Blocks</label>
|
| 134 |
+
<input type="number" id="num-blocks" value="4" min="1" max="64">
|
| 135 |
+
</div>
|
| 136 |
+
<div class="input-group">
|
| 137 |
+
<label for="num-threads">Threads per Block</label>
|
| 138 |
+
<input type="number" id="num-threads" value="16" min="1" max="1024">
|
| 139 |
+
</div>
|
| 140 |
+
<div class="input-group">
|
| 141 |
+
<label for="grid-width">Grid Width (threads)</label>
|
| 142 |
+
<input type="number" id="grid-width" value="32" min="1" max="256">
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
<div id="grid-container"></div>
|
| 146 |
+
<div id="info-panel"></div>
|
| 147 |
+
|
| 148 |
+
<script>
|
| 149 |
+
function updateGrid() {
|
| 150 |
+
const numBlocks = parseInt(document.getElementById('num-blocks').value);
|
| 151 |
+
const numThreads = parseInt(document.getElementById('num-threads').value);
|
| 152 |
+
const gridWidth = parseInt(document.getElementById('grid-width').value);
|
| 153 |
+
|
| 154 |
+
const gridContainer = document.getElementById('grid-container');
|
| 155 |
+
gridContainer.innerHTML = '';
|
| 156 |
+
gridContainer.style.width = `${gridWidth * 32}px`; // 30px thread width + 2px gap
|
| 157 |
+
|
| 158 |
+
// Generate a list of distinct colors for blocks
|
| 159 |
+
const blockColors = generateBlockColors(numBlocks);
|
| 160 |
+
|
| 161 |
+
for (let blockIdx = 0; blockIdx < numBlocks; blockIdx++) {
|
| 162 |
+
for (let threadIdx = 0; threadIdx < numThreads; threadIdx++) {
|
| 163 |
+
const thread = document.createElement('div');
|
| 164 |
+
thread.className = 'thread';
|
| 165 |
+
thread.textContent = threadIdx;
|
| 166 |
+
thread.style.backgroundColor = blockColors[blockIdx];
|
| 167 |
+
thread.addEventListener('mouseover', () => showInfo(blockIdx, threadIdx, numThreads));
|
| 168 |
+
thread.addEventListener('mouseout', clearInfo);
|
| 169 |
+
gridContainer.appendChild(thread);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function generateBlockColors(numBlocks) {
|
| 175 |
+
const colors = [];
|
| 176 |
+
for (let i = 0; i < numBlocks; i++) {
|
| 177 |
+
const hue = (i * 137.5) % 360; // Use golden angle approximation for distribution
|
| 178 |
+
colors.push(`hsl(${hue}, 70%, 60%)`);
|
| 179 |
+
}
|
| 180 |
+
return colors;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function showInfo(blockIdx, threadIdx, numThreads) {
|
| 184 |
+
const globalThreadId = blockIdx * numThreads + threadIdx;
|
| 185 |
+
|
| 186 |
+
const infoPanel = document.getElementById('info-panel');
|
| 187 |
+
infoPanel.innerHTML = `
|
| 188 |
+
<p><strong>Block Index:</strong> ${blockIdx}</p>
|
| 189 |
+
<p><strong>Thread Index in Block:</strong> ${threadIdx}</p>
|
| 190 |
+
<p><strong>Global Thread ID:</strong> ${globalThreadId}</p>
|
| 191 |
+
`;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function clearInfo() {
|
| 195 |
+
document.getElementById('info-panel').innerHTML = '';
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function debounce(func, wait) {
|
| 199 |
+
let timeout;
|
| 200 |
+
return function executedFunction(...args) {
|
| 201 |
+
const later = () => {
|
| 202 |
+
clearTimeout(timeout);
|
| 203 |
+
func(...args);
|
| 204 |
+
};
|
| 205 |
+
clearTimeout(timeout);
|
| 206 |
+
timeout = setTimeout(later, wait);
|
| 207 |
+
};
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
const debouncedUpdateGrid = debounce(updateGrid, 300);
|
| 211 |
+
|
| 212 |
+
document.querySelectorAll('input').forEach(input => {
|
| 213 |
+
input.addEventListener('input', debouncedUpdateGrid);
|
| 214 |
+
});
|
| 215 |
+
|
| 216 |
+
updateGrid();
|
| 217 |
+
</script>
|
| 218 |
+
</body>
|
| 219 |
+
</html>
|