Establish the Mojo 1.0 integration gate
This commit is contained in:
@@ -13111,12 +13111,7 @@ static int ds4_gpu_stream_full_expert_addr_table_requested(void) {
|
||||
|
||||
static uint64_t ds4_gpu_buffer_address(id<MTLBuffer> buffer, NSUInteger inner) {
|
||||
if (!buffer) return 0;
|
||||
#if TARGET_OS_OSX
|
||||
if (@available(macOS 13.0, *)) {
|
||||
return (uint64_t)[buffer gpuAddress] + (uint64_t)inner;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
return (uint64_t)[buffer gpuAddress] + (uint64_t)inner;
|
||||
}
|
||||
|
||||
static int ds4_gpu_stream_compact_addr_ensure_buffers(uint32_t layer) {
|
||||
@@ -17286,50 +17281,42 @@ static DS4MetalQ4ExpertTable *ds4_gpu_q4_expert_address_table(
|
||||
n_total_expert];
|
||||
if (!expert_buffers) return nil;
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
if (@available(macOS 13.0, *)) {
|
||||
for (uint32_t first = 0; first < n_total_expert; first += table_group_size) {
|
||||
const uint32_t remaining = n_total_expert - first;
|
||||
const uint32_t group_n =
|
||||
remaining < table_group_size ? remaining : table_group_size;
|
||||
if ((uint64_t)first > UINT64_MAX / expert_bytes ||
|
||||
(uint64_t)group_n > UINT64_MAX / expert_bytes) {
|
||||
fprintf(stderr, "ds4: Metal Q4 expert address table group byte overflow\n");
|
||||
return nil;
|
||||
}
|
||||
const uint64_t rel = (uint64_t)first * expert_bytes;
|
||||
const uint64_t group_bytes = (uint64_t)group_n * expert_bytes;
|
||||
if (rel > UINT64_MAX - tensor_offset) {
|
||||
fprintf(stderr, "ds4: Metal Q4 expert address table group offset overflow\n");
|
||||
return nil;
|
||||
}
|
||||
uint64_t inner = 0;
|
||||
id<MTLBuffer> group_buf = nil;
|
||||
if (table_group_size > 1) {
|
||||
group_buf = ds4_gpu_wrap_model_range(model_map,
|
||||
model_size,
|
||||
tensor_offset + rel,
|
||||
group_bytes,
|
||||
&inner);
|
||||
} else {
|
||||
group_buf = ds4_gpu_wrap_model_exact_range_owned(model_map,
|
||||
model_size,
|
||||
tensor_offset + rel,
|
||||
expert_bytes,
|
||||
&inner);
|
||||
}
|
||||
if (!group_buf) return nil;
|
||||
const uint64_t base_address = (uint64_t)[group_buf gpuAddress] + inner;
|
||||
for (uint32_t j = 0; j < group_n; j++) {
|
||||
addresses[first + j] = base_address + (uint64_t)j * expert_bytes;
|
||||
}
|
||||
[expert_buffers addObject:group_buf];
|
||||
for (uint32_t first = 0; first < n_total_expert; first += table_group_size) {
|
||||
const uint32_t remaining = n_total_expert - first;
|
||||
const uint32_t group_n =
|
||||
remaining < table_group_size ? remaining : table_group_size;
|
||||
if ((uint64_t)first > UINT64_MAX / expert_bytes ||
|
||||
(uint64_t)group_n > UINT64_MAX / expert_bytes) {
|
||||
fprintf(stderr, "ds4: Metal Q4 expert address table group byte overflow\n");
|
||||
return nil;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "ds4: Metal GPU addresses require macOS 13 or newer\n");
|
||||
return nil;
|
||||
const uint64_t rel = (uint64_t)first * expert_bytes;
|
||||
const uint64_t group_bytes = (uint64_t)group_n * expert_bytes;
|
||||
if (rel > UINT64_MAX - tensor_offset) {
|
||||
fprintf(stderr, "ds4: Metal Q4 expert address table group offset overflow\n");
|
||||
return nil;
|
||||
}
|
||||
uint64_t inner = 0;
|
||||
id<MTLBuffer> group_buf = nil;
|
||||
if (table_group_size > 1) {
|
||||
group_buf = ds4_gpu_wrap_model_range(model_map,
|
||||
model_size,
|
||||
tensor_offset + rel,
|
||||
group_bytes,
|
||||
&inner);
|
||||
} else {
|
||||
group_buf = ds4_gpu_wrap_model_exact_range_owned(model_map,
|
||||
model_size,
|
||||
tensor_offset + rel,
|
||||
expert_bytes,
|
||||
&inner);
|
||||
}
|
||||
if (!group_buf) return nil;
|
||||
const uint64_t base_address = (uint64_t)[group_buf gpuAddress] + inner;
|
||||
for (uint32_t j = 0; j < group_n; j++) {
|
||||
addresses[first + j] = base_address + (uint64_t)j * expert_bytes;
|
||||
}
|
||||
[expert_buffers addObject:group_buf];
|
||||
}
|
||||
|
||||
[address_buffer didModifyRange:NSMakeRange(0,
|
||||
|
||||
Reference in New Issue
Block a user