summaryrefslogtreecommitdiff
path: root/src/gpgpu-sim/shader.cc
diff options
context:
space:
mode:
authormkhairy <[email protected]>2021-05-19 17:51:00 -0400
committerGitHub <[email protected]>2021-05-19 17:51:00 -0400
commit2b2b6a2916e4ed833c707be887bf927167a71fa6 (patch)
tree526646c9ac3f182e9fd7103255e3680f2fcc7adc /src/gpgpu-sim/shader.cc
parent0e4f12ae3fefd6bad6175014411a6587a3898ac8 (diff)
parent1875132a20422404ea75d04fc7be58a1bbca48f3 (diff)
Merge pull request #15 from JRPan/adaptive-cache
Adaptive cache
Diffstat (limited to 'src/gpgpu-sim/shader.cc')
-rw-r--r--src/gpgpu-sim/shader.cc94
1 files changed, 55 insertions, 39 deletions
diff --git a/src/gpgpu-sim/shader.cc b/src/gpgpu-sim/shader.cc
index 22bd8e9..3d352c9 100644
--- a/src/gpgpu-sim/shader.cc
+++ b/src/gpgpu-sim/shader.cc
@@ -3320,50 +3320,66 @@ unsigned int shader_core_config::max_cta(const kernel_info_t &k) const {
if (adaptive_cache_config && !k.cache_config_set) {
// For more info about adaptive cache, see
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared-memory-7-x
- unsigned total_shmed = kernel_info->smem * result;
- assert(total_shmed >= 0 && total_shmed <= gpgpu_shmem_size);
- // assert(gpgpu_shmem_size == 98304); //Volta has 96 KB shared
- // assert(m_L1D_config.get_nset() == 4); //Volta L1 has four sets
- if (total_shmed < gpgpu_shmem_size) {
- switch (adaptive_cache_config) {
- case FIXED:
- break;
- case ADAPTIVE_VOLTA: {
- // For Volta, we assign the remaining shared memory to L1 cache
- // For more info about adaptive cache, see
- // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared-memory-7-x
- // assert(gpgpu_shmem_size == 98304); //Volta has 96 KB shared
-
- // To Do: make it flexible and not tuned to 9KB share memory
- unsigned max_assoc = m_L1D_config.get_max_assoc();
- if (total_shmed == 0)
- m_L1D_config.set_assoc(max_assoc); // L1 is 128KB and shd=0
- else if (total_shmed > 0 && total_shmed <= 8192)
- m_L1D_config.set_assoc(0.9375 *
- max_assoc); // L1 is 120KB and shd=8KB
- else if (total_shmed > 8192 && total_shmed <= 16384)
- m_L1D_config.set_assoc(0.875 *
- max_assoc); // L1 is 112KB and shd=16KB
- else if (total_shmed > 16384 && total_shmed <= 32768)
- m_L1D_config.set_assoc(0.75 * max_assoc); // L1 is 96KB and
- // shd=32KB
- else if (total_shmed > 32768 && total_shmed <= 65536)
- m_L1D_config.set_assoc(0.5 * max_assoc); // L1 is 64KB and shd=64KB
- else if (total_shmed > 65536 && total_shmed <= gpgpu_shmem_size)
- m_L1D_config.set_assoc(0.25 * max_assoc); // L1 is 32KB and
- // shd=96KB
- else
- assert(0);
- break;
+ std::vector<unsigned> shmem_list;
+ for (unsigned i = 0; i < strlen(gpgpu_shmem_option); i++) {
+ char option[4];
+ int j = 0;
+ while (gpgpu_shmem_option[i] != ',' && i < strlen(gpgpu_shmem_option)) {
+ if (gpgpu_shmem_option[i] == ' ') {
+ // skip spaces
+ i++;
+ } else {
+ if (!isdigit(gpgpu_shmem_option[i])) {
+ // check for non digits, which should not be here
+ assert(0 && "invalid config: -gpgpu_shmem_option");
+ }
+ option[j] = gpgpu_shmem_option[i];
+ j++;
+ i++;
}
- default:
- assert(0);
}
+ // convert KB -> B
+ shmem_list.push_back((unsigned)atoi(option) * 1024);
+ }
+
+ unsigned total_shmem = kernel_info->smem * result;
+ // Unified cache config is in KB. Converting to B
+ unsigned total_unified = m_L1D_config.m_unified_cache_size * 1024;
+ std::sort(shmem_list.begin(), shmem_list.end());
+
+ assert(total_shmem >= 0 && total_shmem <= shmem_list.back());
+ switch (adaptive_cache_config) {
+ case FIXED:
+ break;
+ case ADAPTIVE_CACHE: {
+ // For more info about adaptive cache, see
+ bool l1d_configured = false;
+ unsigned max_assoc = m_L1D_config.get_max_assoc();
- printf("GPGPU-Sim: Reconfigure L1 cache to %uKB\n",
- m_L1D_config.get_total_size_inKB());
+ if (total_shmem == 0) {
+ m_L1D_config.set_assoc(max_assoc);
+ l1d_configured = true;
+ } else {
+ for (std::vector<unsigned>::iterator it = shmem_list.begin();
+ it < shmem_list.end() - 1; it++) {
+ if (total_shmem > *it && total_shmem <= *(it + 1)) {
+ float l1_ratio = 1 - (float) *(it + 1) / total_unified;
+ m_L1D_config.set_assoc(max_assoc * l1_ratio);
+ l1d_configured = true;
+ break;
+ }
+ }
+ }
+ assert(l1d_configured && "no shared memory option found");
+ break;
+ }
+ default:
+ assert(0);
}
+ printf("GPGPU-Sim: Reconfigure L1 cache to %uKB\n",
+ m_L1D_config.get_total_size_inKB());
+
k.cache_config_set = true;
}