Skip to content
Snippets Groups Projects
dispatch.c 95.9 KiB
Newer Older
    futhark_context_sync(fc);

    futhark_free_u8_2d(fc, fut_chunk_data);
    futhark_free_i64_1d(fc, fut_dimensions);
    futhark_free_u8_2d(fc, subdomain);
}

static void
set_active_domain_3d(struct dispatch_context *dc, struct futhark_context *fc, int dimensions[3], int y, int x, int z) {
    chunk_info_init(&dc->active_domain, dc->type, dimensions, y, x, z, true);

    int64_t dimensions64[3];
    dimensions64[0] = dimensions[0];
    dimensions64[1] = dimensions[1] * dc->type;
    dimensions64[2] = dimensions[2];

    struct futhark_u8_3d *fut_chunk_data = futhark_new_u8_3d(fc, dc->chunk_info->data, dimensions64[0],
                                                             dimensions64[1], dimensions64[2]);

    struct futhark_i64_1d *fut_dimensions = futhark_new_i64_1d(fc, dimensions64, 3);
    struct futhark_u8_3d *subdomain;

    futhark_context_sync(fc);
    futhark_entry_get_subdomain_3d(fc, &subdomain, fut_chunk_data, y, x * dc->type, z, fut_dimensions);

    futhark_context_sync(fc);
    futhark_values_u8_3d(fc, subdomain, dc->active_domain.data);
    futhark_context_sync(fc);

    futhark_free_u8_3d(fc, fut_chunk_data);
    futhark_free_i64_1d(fc, fut_dimensions);
    futhark_free_u8_3d(fc, subdomain);
}

extern void
set_active_domain(struct dispatch_context *dc, struct futhark_context *fc, int *dimensions, int y, int x, int z) {
    switch (dc->n_dimensions) {
        case 1:
            set_active_domain_1d(dc, fc, dimensions, x);
            break;
        case 2:
            set_active_domain_2d(dc, fc, dimensions, y, x);
            break;
        case 3:
            set_active_domain_3d(dc, fc, dimensions, y, x, z);
            break;
        default:
            break;
    }
}

extern void restore_active_domain(struct dispatch_context *dc) {
    chunk_info_free(&dc->active_domain);
    dc->active_domain = *dc->chunk_info;
}

baptiste.coudray's avatar
baptiste.coudray committed
static void side_envelope_free(side_envelope_t *side_envelope) {
    for (int i = 0; i < NB_CHUNKS; ++i) {
        chunk_info_free(&side_envelope->chunks[i]);
    }
}

baptiste.coudray's avatar
baptiste.coudray committed
extern void envelope_free(envelope_t *envelope) {
baptiste.coudray's avatar
baptiste.coudray committed
    for (int i = 0; i < NB_SIDES; ++i) {
        side_envelope_free(&envelope->sides[i]);
    }