Skip to content

Commit

Permalink
Fix issue on Intel MPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Sep 16, 2023
1 parent 9cfdad0 commit d3e2463
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/nnc/mps/ccv_nnc_mps.m
Original file line number Diff line number Diff line change
Expand Up @@ -1148,13 +1148,15 @@ MPSGraphTensorNamedDataLayout ccv_nnc_mps_tensor_data_layout(const int format)
uint16_t half_bytes;
ccv_float_to_half_precision(&val, &half_bytes, 1);
#ifdef __x86_64__
buffer = [ccv_nnc_default_device() newBufferWithBytes:&half_bytes length:sizeof(uint16_t) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModePrivate | MTLResourceHazardTrackingModeTracked];
buffer = [ccv_nnc_default_device() newBufferWithLength:sizeof(uint16_t) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModePrivate | MTLResourceHazardTrackingModeTracked];
mpmemcpy(buffer, 0, CCV_TENSOR_GPU_MEMORY, &half_bytes, 0, CCV_TENSOR_CPU_MEMORY, sizeof(uint16_t));
#else
buffer = [ccv_nnc_default_device() newBufferWithBytes:&half_bytes length:sizeof(uint16_t) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModeShared | MTLResourceHazardTrackingModeTracked];
#endif
} else {
#ifdef __x86_64__
buffer = [ccv_nnc_default_device() newBufferWithBytes:&val length:sizeof(float) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModePrivate | MTLResourceHazardTrackingModeTracked];
buffer = [ccv_nnc_default_device() newBufferWithLength:sizeof(float) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModePrivate | MTLResourceHazardTrackingModeTracked];
mpmemcpy(buffer, 0, CCV_TENSOR_GPU_MEMORY, &val, 0, CCV_TENSOR_CPU_MEMORY, sizeof(float));
#else
buffer = [ccv_nnc_default_device() newBufferWithBytes:&val length:sizeof(float) options:MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModeShared | MTLResourceHazardTrackingModeTracked];
#endif
Expand Down

0 comments on commit d3e2463

Please sign in to comment.