This repository was archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from kswiecicki/dml-mover
masync: add dml mover implementation
- Loading branch information
Showing
16 changed files
with
420 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.* | ||
!.gitignore | ||
!.gitattributes | ||
!.github/ | ||
!.travis.yml | ||
!.mailmap | ||
!.version | ||
build/ | ||
*~ | ||
*.swp | ||
~* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright 2021, Intel Corporation | ||
# | ||
|
||
project(miniasync-dml C) | ||
|
||
set(MINIASYNC_DML_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
add_cstyle(miniasync-dml | ||
${CMAKE_CURRENT_SOURCE_DIR}/*.[ch] | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) | ||
|
||
add_check_whitespace(miniasync-dml | ||
${CMAKE_CURRENT_SOURCE_DIR}/*.[ch] | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) | ||
|
||
set(DML_SOURCES | ||
vdm_dml.c | ||
) | ||
|
||
add_library(miniasync-dml STATIC ${DML_SOURCES}) | ||
|
||
target_include_directories(miniasync-dml PRIVATE . | ||
${MINIASYNC_DML_INCLUDE_DIR} | ||
${MINIASYNC_INCLUDE_DIR} | ||
${MINIASYNC_SOURCE_DIR}) | ||
|
||
set_target_properties(miniasync-dml PROPERTIES | ||
PUBLIC_HEADER ${MINIASYNC_DML_INCLUDE_DIR}/libminiasync-dml.h | ||
) | ||
|
||
install(TARGETS miniasync-dml | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
# Install headers included in public header | ||
install(DIRECTORY ${MINIASYNC_DML_INCLUDE_DIR}/libminiasync-dml | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
FILES_MATCHING PATTERN "*.h" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause */ | ||
/* Copyright 2021, Intel Corporation */ | ||
|
||
/* | ||
* libminiasync-dml.h -- definition of miniasync dml implementation | ||
*/ | ||
|
||
#ifndef MINIASYNC_DML_H | ||
#define MINIASYNC_DML_H 1 | ||
|
||
#include <stddef.h> | ||
#include <stdio.h> | ||
|
||
#include "libminiasync-dml/vdm_dml.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* MINIASYNC_DML memory flags */ | ||
#define MINIASYNC_DML_F_MEM_DURABLE (1U << 0) | ||
#define MINIASYNC_DML_F_MEM_VALID_FLAGS (MINIASYNC_DML_F_MEM_DURABLE) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* MINIASYNC_DML_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause */ | ||
/* Copyright 2021, Intel Corporation */ | ||
|
||
#ifndef VDM_DML_H | ||
#define VDM_DML_H 1 | ||
|
||
#include <dml/dml.h> | ||
#include <libminiasync.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct vdm_descriptor *vdm_descriptor_dml(void); | ||
struct vdm_descriptor *vdm_descriptor_dml_async(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* VDM_DML_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/* Copyright 2021, Intel Corporation */ | ||
|
||
#include <dml/dml.h> | ||
#include <libminiasync.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
|
||
#include "libminiasync-dml.h" | ||
#include "core/out.h" | ||
#include "core/util.h" | ||
|
||
/* | ||
* vdm_dml_translate_flags -- translate miniasync-dml flags into dml flags | ||
*/ | ||
static uint64_t | ||
vdm_dml_translate_flags(uint64_t flags) | ||
{ | ||
ASSERTeq((flags & ~MINIASYNC_DML_F_MEM_VALID_FLAGS), 0); | ||
|
||
uint64_t tflags = 0; | ||
for (uint64_t iflag = 1; flags > 0; iflag = iflag << 1) { | ||
if ((flags & iflag) == 0) | ||
continue; | ||
|
||
switch (iflag) { | ||
case MINIASYNC_DML_F_MEM_DURABLE: | ||
tflags |= DML_FLAG_DST1_DURABLE; | ||
break; | ||
default: /* shouldn't be possible */ | ||
ASSERT(0); | ||
} | ||
|
||
/* remove translated flag from the flags to be translated */ | ||
flags = flags & (~iflag); | ||
} | ||
|
||
return tflags; | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_job_new -- create a new memcpy job struct | ||
*/ | ||
static dml_job_t * | ||
vdm_dml_memcpy_job_new(void *dest, void *src, size_t n, uint64_t flags) | ||
{ | ||
dml_status_t status; | ||
uint32_t job_size; | ||
dml_job_t *dml_job = NULL; | ||
|
||
status = dml_get_job_size(DML_PATH_HW, &job_size); | ||
ASSERTeq(status, DML_STATUS_OK); | ||
|
||
dml_job = (dml_job_t *)malloc(job_size); | ||
|
||
status = dml_init_job(DML_PATH_HW, dml_job); | ||
ASSERTeq(status, DML_STATUS_OK); | ||
|
||
dml_job->operation = DML_OP_MEM_MOVE; | ||
dml_job->source_first_ptr = (uint8_t *)src; | ||
dml_job->destination_first_ptr = (uint8_t *)dest; | ||
dml_job->source_length = n; | ||
dml_job->destination_length = n; | ||
dml_job->flags = DML_FLAG_COPY_ONLY | flags; | ||
|
||
return dml_job; | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_job_delete -- delete job struct | ||
*/ | ||
static void | ||
vdm_dml_memcpy_job_delete(dml_job_t **dml_job) | ||
{ | ||
dml_finalize_job(*dml_job); | ||
free(*dml_job); | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_job_execute -- execute memcpy job (blocking) | ||
*/ | ||
static void * | ||
vdm_dml_memcpy_job_execute(dml_job_t *dml_job) | ||
{ | ||
dml_status_t status; | ||
status = dml_execute_job(dml_job); | ||
ASSERTeq(status, DML_STATUS_OK); | ||
|
||
return dml_job->destination_first_ptr; | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_job_submit -- submit memcpy job (nonblocking) | ||
*/ | ||
static void * | ||
vdm_dml_memcpy_job_submit(dml_job_t *dml_job) | ||
{ | ||
dml_status_t status; | ||
status = dml_submit_job(dml_job); | ||
ASSERTeq(status, DML_STATUS_OK); | ||
|
||
return dml_job->destination_first_ptr; | ||
} | ||
|
||
/* | ||
* vdm_dml_check -- check status of memcpy job executed synchronously | ||
*/ | ||
static enum future_state | ||
vdm_dml_check(struct future_context *context) | ||
{ | ||
struct vdm_memcpy_data *data = future_context_get_data(context); | ||
|
||
int complete; | ||
util_atomic_load64(&data->complete, &complete); | ||
|
||
return (complete) ? FUTURE_STATE_COMPLETE : FUTURE_STATE_RUNNING; | ||
} | ||
|
||
/* | ||
* vdm_dml_check_delete_job -- check status of memcpy job executed | ||
* asynchronously | ||
*/ | ||
static enum future_state | ||
vdm_dml_check_delete_job(struct future_context *context) | ||
{ | ||
struct vdm_memcpy_data *data = future_context_get_data(context); | ||
dml_job_t *dml_job = (dml_job_t *)data->extra; | ||
|
||
dml_status_t status = dml_check_job(dml_job); | ||
ASSERTne(status, DML_STATUS_JOB_CORRUPTED); | ||
|
||
enum future_state state = (status == DML_STATUS_OK) ? | ||
FUTURE_STATE_COMPLETE : FUTURE_STATE_RUNNING; | ||
|
||
if (state == FUTURE_STATE_COMPLETE) | ||
vdm_dml_memcpy_job_delete(&dml_job); | ||
|
||
return state; | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_sync -- execute dml synchronous memcpy operation | ||
*/ | ||
static void | ||
vdm_dml_memcpy_sync(void *runner, struct future_notifier *notifier, | ||
struct future_context *context) | ||
{ | ||
struct vdm_memcpy_data *data = future_context_get_data(context); | ||
struct vdm_memcpy_output *output = future_context_get_output(context); | ||
|
||
uint64_t tflags = vdm_dml_translate_flags(data->flags); | ||
dml_job_t *dml_job = vdm_dml_memcpy_job_new(data->dest, data->src, | ||
data->n, tflags); | ||
output->dest = vdm_dml_memcpy_job_execute(dml_job); | ||
vdm_dml_memcpy_job_delete(&dml_job); | ||
data->vdm_cb(context); | ||
} | ||
|
||
/* | ||
* dml_synchronous_descriptor -- dml synchronous memcpy descriptor | ||
*/ | ||
static struct vdm_descriptor dml_synchronous_descriptor = { | ||
.vdm_data_init = NULL, | ||
.vdm_data_fini = NULL, | ||
.memcpy = vdm_dml_memcpy_sync, | ||
.check = vdm_dml_check, | ||
}; | ||
|
||
/* | ||
* vdm_descriptor_dml -- return dml synchronous memcpy descriptor | ||
*/ | ||
struct vdm_descriptor * | ||
vdm_descriptor_dml(void) | ||
{ | ||
return &dml_synchronous_descriptor; | ||
} | ||
|
||
/* | ||
* vdm_dml_memcpy_async -- execute dml asynchronous memcpy operation | ||
*/ | ||
static void | ||
vdm_dml_memcpy_async(void *runner, struct future_notifier *notifier, | ||
struct future_context *context) | ||
{ | ||
struct vdm_memcpy_data *data = future_context_get_data(context); | ||
struct vdm_memcpy_output *output = future_context_get_output(context); | ||
|
||
uint64_t tflags = vdm_dml_translate_flags(data->flags); | ||
dml_job_t *dml_job = vdm_dml_memcpy_job_new(data->dest, data->src, | ||
data->n, tflags); | ||
data->extra = dml_job; | ||
output->dest = vdm_dml_memcpy_job_submit(dml_job); | ||
} | ||
|
||
/* | ||
* dml_synchronous_descriptor -- dml asynchronous memcpy descriptor | ||
*/ | ||
static struct vdm_descriptor dml_asynchronous_descriptor = { | ||
.vdm_data_init = NULL, | ||
.vdm_data_fini = NULL, | ||
.memcpy = vdm_dml_memcpy_async, | ||
.check = vdm_dml_check_delete_job, | ||
}; | ||
|
||
/* | ||
* vdm_descriptor_dml -- return dml asynchronous memcpy descriptor | ||
*/ | ||
struct vdm_descriptor * | ||
vdm_descriptor_dml_async(void) | ||
{ | ||
return &dml_asynchronous_descriptor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.