aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compute/skc/allocator_host.c
blob: dbdcba0f518c1a6b1836ae02dc70682fac755565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 *
 */

//
//
//

#include <stdlib.h>

//
//
//

#include "runtime_cl_12.h"
#include "config_cl.h"

//
//
//

#define SKC_RUNTIME_HOST_CACHELINE_SIZE  64

#define SKC_ALIGNED_MALLOC(size,alignment) _aligned_malloc(size,alignment)
#define SKC_ALIGNED_FREE(p)                _aligned_free(p)

//
// PERM
//

void *
skc_runtime_host_perm_alloc(struct skc_runtime * const runtime, 
                            skc_mem_flags_e      const flags,
                            size_t               const size)
{
  return SKC_ALIGNED_MALLOC(SKC_ROUND_UP(size,SKC_RUNTIME_HOST_CACHELINE_SIZE),
                            SKC_RUNTIME_HOST_CACHELINE_SIZE);
}

void
skc_runtime_host_perm_free(struct skc_runtime * const runtime, 
                           void               * const mem)
{
  SKC_ALIGNED_FREE(mem);
}

//
// TEMP
//

void *
skc_runtime_host_temp_alloc(struct skc_runtime * const runtime,
                            skc_mem_flags_e      const flags,
                            size_t               const size,
                            skc_subbuf_id_t    * const subbuf_id,
                            size_t             * const subbuf_size)
{
  if (size == 0)
    {
      *subbuf_id = (skc_subbuf_id_t)-1;

      if (subbuf_size != NULL)
        *subbuf_size = 0;
      
      return NULL;
    }

  return runtime->allocator.host.temp.extent + 
    skc_suballocator_subbuf_alloc(&runtime->allocator.host.temp.suballocator,
                                  runtime->scheduler,
                                  size,subbuf_id,subbuf_size);
}


void
skc_runtime_host_temp_free(struct skc_runtime * const runtime,
                           void               * const mem,
                           skc_subbuf_id_t      const subbuf_id)
{
  if (mem == NULL)
    return;

  skc_suballocator_subbuf_free(&runtime->allocator.host.temp.suballocator,subbuf_id);
}

//
//
//

void
skc_allocator_host_create(struct skc_runtime * const runtime)
{
  skc_suballocator_create(runtime,
                          &runtime->allocator.host.temp.suballocator,
                          "HOST  ",
                          runtime->config->suballocator.host.subbufs,
                          SKC_RUNTIME_HOST_CACHELINE_SIZE,
                          runtime->config->suballocator.host.size);

  runtime->allocator.host.temp.extent = 
    skc_runtime_host_perm_alloc(runtime,
                                SKC_MEM_FLAGS_READ_WRITE,
                                runtime->config->suballocator.host.size);
}

void
skc_allocator_host_dispose(struct skc_runtime * const runtime)
{
  skc_suballocator_dispose(runtime,&runtime->allocator.host.temp.suballocator);

  skc_runtime_host_perm_free(runtime,runtime->allocator.host.temp.extent);
}

//
//
//