@@ -925,6 +925,26 @@ __tgt_target_table *__tgt_rtl_load_binary(int32_t device_id,
925
925
return res;
926
926
}
927
927
928
+ static atmi_status_t atmi_calloc (void **ret_ptr, size_t size,
929
+ atmi_mem_place_t place) {
930
+ uint64_t rounded = 4 * ((size + 3 ) / 4 );
931
+ void *ptr;
932
+ atmi_status_t err = atmi_malloc (&ptr, rounded, place);
933
+ if (err != ATMI_STATUS_SUCCESS) {
934
+ return err;
935
+ }
936
+
937
+ hsa_status_t rc = hsa_amd_memory_fill (ptr, 0 , rounded / 4 );
938
+ if (rc != HSA_STATUS_SUCCESS) {
939
+ fprintf (stderr, " zero fill device_state failed with %u\n " , rc);
940
+ atmi_free (ptr);
941
+ return ATMI_STATUS_ERROR;
942
+ }
943
+
944
+ *ret_ptr = ptr;
945
+ return ATMI_STATUS_SUCCESS;
946
+ }
947
+
928
948
__tgt_target_table *__tgt_rtl_load_binary_locked (int32_t device_id,
929
949
__tgt_device_image *image) {
930
950
// This function loads the device image onto gpu[device_id] and does other
@@ -1024,7 +1044,7 @@ __tgt_target_table *__tgt_rtl_load_binary_locked(int32_t device_id,
1024
1044
assert (dss.second == 0 );
1025
1045
void *ptr = NULL ;
1026
1046
atmi_status_t err =
1027
- atmi_malloc (&ptr, device_State_bytes, get_gpu_mem_place (device_id));
1047
+ atmi_calloc (&ptr, device_State_bytes, get_gpu_mem_place (device_id));
1028
1048
if (err != ATMI_STATUS_SUCCESS) {
1029
1049
fprintf (stderr, " Failed to allocate device_state array\n " );
1030
1050
return NULL ;
@@ -1062,13 +1082,6 @@ __tgt_target_table *__tgt_rtl_load_binary_locked(int32_t device_id,
1062
1082
fprintf (stderr, " memcpy install of state_ptr failed\n " );
1063
1083
return NULL ;
1064
1084
}
1065
-
1066
- assert ((device_State_bytes & 0x3 ) == 0 ); // known >= 4 byte aligned
1067
- hsa_status_t rc = hsa_amd_memory_fill (ptr, 0 , device_State_bytes / 4 );
1068
- if (rc != HSA_STATUS_SUCCESS) {
1069
- fprintf (stderr, " zero fill device_state failed with %u\n " , rc);
1070
- return NULL ;
1071
- }
1072
1085
}
1073
1086
1074
1087
// TODO: Check with Guansong to understand the below comment more thoroughly.
0 commit comments