(git:39fe4c4)
Loading...
Searching...
No Matches
dbm_multiply_gpu.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#ifndef DBM_MULTIPLY_GPU_H
8#define DBM_MULTIPLY_GPU_H
9
10#include "../offload/offload_runtime.h"
11#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
12
13#include "dbm_internal.h"
14#include "dbm_shard.h"
15
16/*******************************************************************************
17 * \brief Internal struct for storing per shard gpu objects.
18 * \author Ole Schuett
19 ******************************************************************************/
20typedef struct {
21 double *data; // on the device
22 int data_size;
23 int data_allocated;
24 offloadStream_t stream;
25 offloadEvent_t event;
26} dbm_shard_gpu_t;
27
28// Separate from dbm_pack_t because device allocation lifetime differs from the
29// host pack (which is reallocated each tick); tracks device capacity
30// explicitly.
31typedef struct {
32 double *data; // on the device
33 int data_allocated;
34} dbm_pack_gpu_t;
35
36/*******************************************************************************
37 * \brief Internal struct for storing the gpu backend's context.
38 * \author Ole Schuett
39 ******************************************************************************/
40typedef struct {
41 offloadStream_t main_stream;
42 offloadEvent_t upload_event;
43
44 int nshards;
45 dbm_shard_gpu_t *shards_c_dev;
46
47 dbm_pack_gpu_t pack_a_dev;
48 dbm_pack_gpu_t pack_b_dev;
49
50 int max_batch_size;
51 dbm_task_t *batches_dev;
52} dbm_multiply_gpu_context_t;
53
54/*******************************************************************************
55 * \brief Internal routine for initializing the gpu backend.
56 * \author Ole Schuett
57 ******************************************************************************/
58void dbm_multiply_gpu_start(const int max_batch_size, const int nshards,
59 dbm_shard_t *shards_c_host,
60 dbm_multiply_gpu_context_t *ctx);
61
62/*******************************************************************************
63 * \brief Internal routine for uploading newly arrived packs onto the device.
64 * \author Ole Schuett and Hans Pabst
65 ******************************************************************************/
66bool dbm_multiply_gpu_upload_packs(const dbm_pack_t *pack_a,
67 const dbm_pack_t *pack_b,
68 dbm_multiply_gpu_context_t *ctx);
69
70/*******************************************************************************
71 * \brief Internal routine for executing the tasks in given batch on the GPU.
72 * \author Ole Schuett
73 ******************************************************************************/
74void dbm_multiply_gpu_process_batch(const int ntasks, const dbm_task_t *batch,
75 const double alpha, dbm_shard_t *shard_c,
76 const int kshard, const bool finish,
77 dbm_multiply_gpu_context_t *ctx);
78
79/*******************************************************************************
80 * \brief Internal routine for shutting down the gpu backend.
81 * \author Ole Schuett
82 ******************************************************************************/
83void dbm_multiply_gpu_stop(dbm_multiply_gpu_context_t *ctx);
84
85#endif // defined(__OFFLOAD) && !defined(__NO_OFFLOAD_DBM)
86#endif
87
88// EOF
Internal struct for storing a pack - essentially a shard for MPI.
Internal struct for storing a matrix shard.
Definition dbm_shard.h:30
Internal struct for storing a task, ie. a single block multiplication.