Skip to content

Commit 92f6d68

Browse files
authored
[SYCL][HIP] Support the SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE environment variable (#7887)
This PR tries to support the SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE environment variable with the HIP runtime APIs. Thank you for your review.
1 parent 13ddde5 commit 92f6d68

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ Note that conflicting configuration tuples in the same list will favor the last
163163
| -------------------- | ------ | ----------- |
164164
| `SYCL_PI_CUDA_MAX_LOCAL_MEM_SIZE` | Integer | Specifies the maximum size of a local memory allocation in bytes. If the value exceeds the device's capabilities then a `sycl::runtime_error` is thrown. In order for the full error message to be printed, `SYCL_RT_WARNING_LEVEL=2` must be set. The default value for `SYCL_PI_CUDA_MAX_LOCAL_MEM_SIZE` is determined by the hardware. |
165165

166+
## Controlling DPC++ HIP Plugin
167+
168+
| Environment variable | Values | Description |
169+
| -------------------- | ------ | ----------- |
170+
| `SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE` | Integer | Specifies the maximum size of a local memory allocation in bytes. If the value exceeds the device's capabilities then a `sycl::runtime_error` is thrown. In order for the full error message to be printed, `SYCL_RT_WARNING_LEVEL=2` must be set. The default value for `SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE` is determined by the hardware. |
171+
166172
## Tools variables
167173

168174
| Environment variable | Values | Description |

sycl/plugins/hip/pi_hip.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,27 @@ pi_result hip_piEnqueueKernelLaunch(
29292929
retImplEv->start();
29302930
}
29312931

2932+
// Set local mem max size if env var is present
2933+
static const char *local_mem_sz_ptr =
2934+
std::getenv("SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE");
2935+
2936+
if (local_mem_sz_ptr) {
2937+
int device_max_local_mem = 0;
2938+
retError = PI_CHECK_ERROR(hipDeviceGetAttribute(
2939+
&device_max_local_mem, hipDeviceAttributeMaxSharedMemoryPerBlock,
2940+
command_queue->get_device()->get()));
2941+
2942+
static const int env_val = std::atoi(local_mem_sz_ptr);
2943+
if (env_val <= 0 || env_val > device_max_local_mem) {
2944+
setErrorMessage("Invalid value specified for "
2945+
"SYCL_PI_HIP_MAX_LOCAL_MEM_SIZE",
2946+
PI_ERROR_PLUGIN_SPECIFIC_ERROR);
2947+
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
2948+
}
2949+
retError = PI_CHECK_ERROR(hipFuncSetAttribute(
2950+
hipFunc, hipFuncAttributeMaxDynamicSharedMemorySize, env_val));
2951+
}
2952+
29322953
retError = PI_CHECK_ERROR(hipModuleLaunchKernel(
29332954
hipFunc, blocksPerGrid[0], blocksPerGrid[1], blocksPerGrid[2],
29342955
threadsPerBlock[0], threadsPerBlock[1], threadsPerBlock[2],

0 commit comments

Comments
 (0)