Commit ea973ca1 authored by Nicolas Denoyelle's avatar Nicolas Denoyelle Committed by Swann Perarnau
Browse files

[fix] Remove scratchpads from library

This building block needs a serious redesign, in part because areas, tilings, and dmas have changed so much. By the time we had iterators and allocators to the library, this building block will just need to be completely refactored.
parent f76e154b
......@@ -37,7 +37,6 @@ AML currently implements the following abstractions:
* :doc:`Layout <pages/layout>`, a description of data structure organization,
* :doc:`Tiling <pages/tilings>`, a description of data blocking (decomposition)
* :doc:`DMA <pages/dmas>`, an engine to asynchronously move data structures between areas,
* :doc:`Scratchpad <pages/scratchs>`, a stage-in, stage-out abstraction for prefetching.
Each of these abstractions has several implementations. For instance, areas
may refer to the usual DRAM or its subset, to GPU memory, or to non-volatile memory.
......@@ -136,4 +135,3 @@ for more info.
pages/tilings
pages/layout
pages/dmas
pages/scratchs
Scratchpad Parallel Implementation API
======================================
.. doxygengroup:: aml_scratch_par
Scratchpad Sequential Implementation API
========================================
.. doxygengroup:: aml_scratch_seq
Scratchpads: Staging data in and out
====================================
.. doxygengroup:: aml_scratch
Implementations
---------------
.. toctree::
scratch_seq_api
scratch_par_api
......@@ -15,11 +15,6 @@ include_aml_dma_HEADERS = \
aml/dma/linux-seq.h \
aml/dma/linux-par.h
include_aml_scratchdir=$(includedir)/aml/scratch
include_aml_scratch_HEADERS = \
aml/scratch/seq.h \
aml/scratch/par.h
include_aml_tilingdir=$(includedir)/aml/tiling
include_aml_tiling_HEADERS = \
aml/tiling/native.h \
......
......@@ -1077,211 +1077,6 @@ int aml_copy_layout_transform_generic(struct aml_layout *dst,
////////////////////////////////////////////////////////////////////////////////
/**
* @}
* @defgroup aml_scratch "AML Scratchpad"
* @brief Stage-in, Stage-out High Level Abstraction.
*
* Scratchpad in an abstraction fro moving data back and forth from
* a data representation in an area to another data representation in another
* areas. This is especially usefull from moving to user data representation
* to an architecure optimized representation for heavy computational work,
* then returning the to user representation.
* Data movement is performed with two dma engines from one area and tiling to
* another area and tiling.
*
* @image html scratch.png width=600
* @see aml_dma
* @{
**/
////////////////////////////////////////////////////////////////////////////////
/**
* Scratch is mainly used to asynchronously move data back and forth between
* two areas. aml_scratch_request is an opaque structure containing information
* about ongoing requests for data movement.
**/
struct aml_scratch_request;
/**
* Opaque handle implemented by each scratches implementation.
* Should not be used by end users.
**/
struct aml_scratch_data;
/**
* Scratchpad request types.
* Invalid request type. Used for marking inactive requests in the vector.
**/
#define AML_SCRATCH_REQUEST_TYPE_INVALID -1
/**
* Scratchpad request types.
* Push from the scratchpad to regular memory.
**/
#define AML_SCRATCH_REQUEST_TYPE_PUSH 0
/**
* Scratchpad request types.
* Pull from regular memory to the scratchpad.
**/
#define AML_SCRATCH_REQUEST_TYPE_PULL 1
/**
* Scratchpad request types.
* No-op/empty request
**/
#define AML_SCRATCH_REQUEST_TYPE_NOOP 2
/**
* aml_scratch_ops contain a scratch implementation specific operations.
* These operations implementation may vary depending on the source and
* destination of data, and thus scratch implementations use different
* operations.
* Aware users may create or modify implementation by assembling
* appropriate operations in such a structure.
* @see struct aml_scratch
**/
struct aml_scratch_ops {
/**
* \todo Doc
**/
int (*create_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request **req, int type,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid);
/**
* \todo Doc
**/
int (*destroy_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request *req);
/**
* \todo Doc
**/
int (*wait_request)(struct aml_scratch_data *scratch,
struct aml_scratch_request *req);
/**
* \todo Doc
**/
int (*release)(struct aml_scratch_data *scratch, int scratchid);
};
/**
* An aml_scratch is abstraction aimed toward temporary use of a data structures
* in a different area than the one where data currently resides. Scratches in
* AML take care of asynchornously allocating and moving the data back and forth
* between areas.
**/
struct aml_scratch {
/** @see aml_scratch_ops **/
struct aml_scratch_ops *ops;
/** @see aml_scratch_data **/
struct aml_scratch_data *data;
};
/**
* Requests a synchronous pull from regular memory to the scratchpad.
* @param scratch: an initialized scratchpad structure.
* @param dest: destination layout (on the scratch)
* @param scratchid: an argument of type int*; gets filled with the scratch tile
* identifier where the data will be pulled into.
* @param src: the source layout.
* @param srcid: an argument of type int; the source tile identifier.
* @see aml_scratch_baseptr()
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_pull(struct aml_scratch *scratch,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid);
/**
* Requests a pull from regular memory to the scratchpad. This is an
* asynchronous version of aml_scratch_pull().
* @param scratch: an initialized scratchpad structure.
* @param req: an address where the pointer to the newly assigned scratch
* request will be stored.
* @param scratch_layout: the layout on the scratch
* @param scratchid: an argument of type int*; gets filled with the scratch tile
* identifier where the data will be pulled into.
* @param src_layout: the source layout to pull.
* @param srcid: an argument of type int; the source tile identifier.
* @return 0 if successful; an error code otherwise.
* @see aml_scratch_pull()
**/
int aml_scratch_async_pull(struct aml_scratch *scratch,
struct aml_scratch_request **req,
struct aml_layout **scratch_layout, int *scratchid,
struct aml_layout *src_layout, int srcid);
/**
* Requests a synchronous push from the scratchpad to regular memory.
* @param scratch: an initialized scratchpad structure.
* @param dest_layout: the destination layout
* @param destid: an argument of type int*; gets filled with the destination
* tile identifier where the data will be pushed into (and where it was pulled
* from in the first place).
* @param scratch_layout: the source layout on the scratch
* @param scratchid: an argument of type int; the scratchpad tile identifier.
* @return 0 if successful; an error code otherwise.
* @see aml_scratch_baseptr()
**/
int aml_scratch_push(struct aml_scratch *scratch,
struct aml_layout **dest_layout, int *destid,
struct aml_layout *scratch_layout, int scratchid);
/**
* Requests a push from the scratchpad to regular memory. This is an
* asynchronous version of aml_scratch_push().
* @param scratch: an initialized scratchpad structure.
* @param req: an address where the pointer to the newly assigned scratch
* request will be stored.
* @param dest_layout: the destination layout
* @param destid: an argument of type int*; gets filled with the destination
* tile identifier where the data will be pushed into (and where it was pulled
* from in the first place).
* @param scratch_layout: the source layout on the scratch
* @param scratchid: an argument of type int; the scratchpad tile identifier.
* @return 0 if successful; an error code otherwise.
* @see aml_scratch_push()
**/
int aml_scratch_async_push(struct aml_scratch *scratch,
struct aml_scratch_request **req,
struct aml_layout **dest_layout, int *destid,
struct aml_layout *scratch_layout, int scratchid);
/**
* Waits for an asynchronous scratch request to complete.
* @param scratch: an initialized scratchpad structure.
* @param req: a scratch request obtained using aml_scratch_async_*() calls.
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_wait(struct aml_scratch *scratch,
struct aml_scratch_request *req);
/**
* Tears down an asynchronous scratch request before it completes.
* @param scratch: an initialized scratchpad structure.
* @param req: a scratch request obtained using aml_scratch_async_*() calls.
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_cancel(struct aml_scratch *scratch,
struct aml_scratch_request *req);
/**
* Provides the location of the scratchpad.
* @param scratch: an initialized scratchpad structure.
* @return a base pointer to the scratchpad memory buffer.
**/
void *aml_scratch_baseptr(const struct aml_scratch *scratch);
/**
* Release a scratch tile for immediate reuse.
* @param scratch: an initialized scratchpad structure.
* @param scratchid: a scratchpad tile identifier.
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_release(struct aml_scratch *scratch, int scratchid);
////////////////////////////////////////////////////////////////////////////////
/**
* @}
**/
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#ifndef AML_SCRATCH_PAR_H
#define AML_SCRATCH_PAR_H 1
/**
* @defgroup aml_scratch_par "AML Parallel Scaratchpad"
* @brief Parallel Scratchpad implementation.
*
* Scratchpad creates one thread to trigger synchronous dma movements.
* @{
**/
/**
* Default table of scratchpad operations for linux
* parallel dma.
**/
extern struct aml_scratch_ops aml_scratch_par_ops;
/** Inside of a parallel scratch request with linux dma. **/
struct aml_scratch_request_par {
/**
* The type of scratchpad request
* @see <aml.h>
**/
int type;
/** The source pointer of the data movement **/
struct aml_layout *src;
/** The tile identifier in source pointer **/
int srcid;
/** The destination pointer of the data movement **/
struct aml_layout *dst;
/** The tile identifier in destination pointer **/
int dstid;
/** The scratchpad handling this request **/
struct aml_scratch_par *scratch;
/** The thread in charge of scratch request progress **/
pthread_t thread;
};
/**
* Inner data of the parallel scratchpad implementation
* \todo This is the same as struct aml_scratch_seq_data. Could be factorized
**/
struct aml_scratch_par_data {
struct aml_tiling *src_tiling;
struct aml_tiling *scratch_tiling;
/** The dma engine in charge of the transfer **/
struct aml_dma *dma;
/** The tilings involved in ongoing scratch requests **/
struct aml_vector *tilemap;
/** The set of dma requests submitted to the dma to mode data **/
struct aml_vector *requests;
/** A lock to submit concurrent dma requests via the scratchpad **/
pthread_mutex_t lock;
};
/** The set of operation embeded in the parallel scratchpad **/
struct aml_scratch_par_inner_ops {
/**
* Function to submit asynchronously scratchpad request.
* @param data: Argument of the thread starting the request,
* i.e a struct aml_scratch_request_par.
* @return Unspecified value.
**/
void *(*do_thread)(void *data);
};
/** Parallel implementation of a scratchpad **/
struct aml_scratch_par {
/** Set of operations embeded in the scratchpad **/
struct aml_scratch_par_inner_ops ops;
/** Data embeded in the scratchpad **/
struct aml_scratch_par_data data;
};
/**
* Allocates and initializes a new parallel scratchpad.
*
* @param scratch an address where the pointer to the newly allocated scratchpad
* structure will be stored.
*
* @param dma the DMA that will be used for migrating data to and from
* the scratchpad.
* @param src_tiling the tiling to use on the source data structure
* @param scratch_tiling the tiling to use on the scratch
* @param nbreqs the initial number of slots for asynchronous request that
* are in-flight (will be increased automatically if necessary).
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_par_create(struct aml_scratch **scratch,
struct aml_dma *dma, struct aml_tiling *src_tiling,
struct aml_tiling *scratch_tiling, size_t nbreqs);
/**
* Tears down an initialized parallel scratchpad.
*
* @param scratch an initialized scratchpad structure. NULL on return.
*/
void aml_scratch_par_destroy(struct aml_scratch **scratch);
/**
* @}
**/
#endif // AML_SCRATCH_PAR_H
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#ifndef AML_SCRATCH_SEQ_H
#define AML_SCRATCH_SEQ_H 1
/**
* @defgroup aml_scratch_seq "AML Sequential Scaratchpad"
* @brief Sequential Scratchpad implementation.
*
* Scratchpad uses calling thread to trigger asynchronous dma movements.
* @{
**/
/**
* Default table of scratchpad operations for linux
* sequential dma.
**/
extern struct aml_scratch_ops aml_scratch_seq_ops;
/** Inside of a sequential scratch request with linux dma. **/
struct aml_scratch_request_seq {
/**
* The type of scratchpad request
* @see <aml.h>
**/
int type;
/** The source layout of the data movement **/
struct aml_layout *src;
int srcid;
/** The destination pointer of the data movement **/
struct aml_layout *dst;
int dstid;
/** The request used for movement **/
struct aml_dma_request *dma_req;
};
/** Inner data of the sequential scratchpad implementation **/
struct aml_scratch_seq_data {
struct aml_tiling *src_tiling;
struct aml_tiling *scratch_tiling;
/** The dma engine in charge of the transfer **/
struct aml_dma *dma;
/** Map of tiles src layouts to scratch ids **/
struct aml_vector *tilemap;
/** The set of dma requests submitted to the dma to mode data **/
struct aml_vector *requests;
/** A lock to submit concurrent dma requests via the scratchpad **/
pthread_mutex_t lock;
};
/** The set of operation embeded in the sequential scratchpad **/
struct aml_scratch_seq_inner_ops {
/**
* Function to submit a scratchpad request.
* @param scratch: The scratchpad used for the request
* @param req: The request to execute.
**/
int (*doit)(struct aml_scratch_seq_data *scratch,
struct aml_scratch_request_seq *req);
};
/** Sequential implementation of a scratchpad **/
struct aml_scratch_seq {
/** Set of operations embeded in the scratchpad **/
struct aml_scratch_seq_inner_ops ops;
/** Data embeded in the scratchpad **/
struct aml_scratch_seq_data data;
};
/**
* Allocates and initializes a new sequential scratchpad.
*
* @param scratch an address where the pointer to the newly allocated scratchpad
* structure will be stored.
*
* @param dma the DMA that will be used for migrating data to and from
* the scratchpad.
* @param src_tiling the tiling on the source memory
* @param scratch_tiling the tiling to use on the scratch
* @param nbreqs the initial number of slots for asynchronous request that
* are in-flight (will be increased automatically if necessary).
* @return 0 if successful; an error code otherwise.
**/
int aml_scratch_seq_create(struct aml_scratch **scratch,
struct aml_dma *dma, struct aml_tiling *src_tiling,
struct aml_tiling *scratch_tiling, size_t nbreqs);
/**
* Tears down an initialized sequential scratchpad.
*
* @param scratch an initialized scratchpad structure. NULL on return.
*/
void aml_scratch_seq_destroy(struct aml_scratch **scratch);
/**
* @}
**/
#endif // AML_SCRATCH_SEQ_H
......@@ -26,11 +26,6 @@ DMA_SOURCES = \
dma/dma_linux_par.c \
dma/dma_linux_seq.c
SCRATCH_SOURCES = \
scratch/scratch.c \
scratch/scratch_par.c \
scratch/scratch_seq.c
TILING_SOURCES = \
tiling/tiling.c \
tiling/tiling_pad.c \
......@@ -47,7 +42,6 @@ UTILS_SOURCES = \
LIB_SOURCES = \
$(AREA_SOURCES) \
$(DMA_SOURCES) \
$(SCRATCH_SOURCES) \
$(TILING_SOURCES) \
$(LAYOUT_SOURCES) \
$(UTILS_SOURCES) \
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
/*******************************************************************************
* Generic Scratchpad API:
* Most of the stuff is dispatched to a different layer, using type-specific
* functions.
*
* As for DMA, the API is slightly different than the functions below, as we
* abstract the request creation after this layer.
******************************************************************************/
int aml_scratch_pull(struct aml_scratch *scratch,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid)
{
struct aml_scratch_request *req;
int ret;
if (scratch == NULL || dest == NULL || scratchid == NULL
|| src == NULL)
return -AML_EINVAL;
ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PULL,
dest, scratchid, src, srcid);
if (ret)
return ret;
return scratch->ops->wait_request(scratch->data, req);
}
int aml_scratch_async_pull(struct aml_scratch *scratch,
struct aml_scratch_request **req,
struct aml_layout **dest, int *scratchid,
struct aml_layout *src, int srcid)
{
if (scratch == NULL || dest == NULL || scratchid == NULL
|| src == NULL)
return -AML_EINVAL;
return scratch->ops->create_request(scratch->data, req,
AML_SCRATCH_REQUEST_TYPE_PULL,
dest, scratchid, src, srcid);
}
int aml_scratch_push(struct aml_scratch *scratch,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid)
{
struct aml_scratch_request *req;
int ret;
if (scratch == NULL || dest == NULL || destid == NULL
|| src == NULL)
return -AML_EINVAL;
ret = scratch->ops->create_request(scratch->data, &req,
AML_SCRATCH_REQUEST_TYPE_PUSH,
dest, destid, src, srcid);
if (ret)
return ret;
return scratch->ops->wait_request(scratch->data, req);
}
int aml_scratch_async_push(struct aml_scratch *scratch,
struct aml_scratch_request **req,
struct aml_layout **dest, int *destid,
struct aml_layout *src, int srcid)
{
if (scratch == NULL || dest == NULL || destid == NULL
|| src == NULL)
return -AML_EINVAL;
return scratch->ops->create_request(scratch->data, req,
AML_SCRATCH_REQUEST_TYPE_PUSH,
dest, destid, src, srcid);
}
int aml_scratch_cancel(struct aml_scratch *scratch,
struct aml_scratch_request *req)
{
if (scratch == NULL || req == NULL)
return -AML_EINVAL;
return scratch->ops->destroy_request(scratch->data, req);
}
int aml_scratch_wait(struct aml_scratch *scratch,
struct aml_scratch_request *req)
{
if (scratch == NULL || req == NULL)
return -AML_EINVAL;
return scratch->ops->wait_request(scratch->data, req);
}
int aml_scratch_release(struct aml_scratch *scratch, int scratchid)
{
if (scratch == NULL)
return -AML_EINVAL;
return scratch->ops->release(scratch->data, scratchid);
}
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"