• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can
5  * be found in the LICENSE file.
6  *
7  */
8 
9 //
10 //
11 //
12 
13 #include <stdlib.h>
14 
15 //
16 //
17 //
18 
19 #include "runtime_cl_12.h"
20 #include "config_cl.h"
21 
22 //
23 //
24 //
25 
26 #define SKC_RUNTIME_HOST_CACHELINE_SIZE  64
27 
28 #define SKC_ALIGNED_MALLOC(size,alignment) _aligned_malloc(size,alignment)
29 #define SKC_ALIGNED_FREE(p)                _aligned_free(p)
30 
31 //
32 // PERM
33 //
34 
35 void *
skc_runtime_host_perm_alloc(struct skc_runtime * const runtime,skc_mem_flags_e const flags,size_t const size)36 skc_runtime_host_perm_alloc(struct skc_runtime * const runtime,
37                             skc_mem_flags_e      const flags,
38                             size_t               const size)
39 {
40   return SKC_ALIGNED_MALLOC(SKC_ROUND_UP(size,SKC_RUNTIME_HOST_CACHELINE_SIZE),
41                             SKC_RUNTIME_HOST_CACHELINE_SIZE);
42 }
43 
44 void
skc_runtime_host_perm_free(struct skc_runtime * const runtime,void * const mem)45 skc_runtime_host_perm_free(struct skc_runtime * const runtime,
46                            void               * const mem)
47 {
48   SKC_ALIGNED_FREE(mem);
49 }
50 
51 //
52 // TEMP
53 //
54 
55 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)56 skc_runtime_host_temp_alloc(struct skc_runtime * const runtime,
57                             skc_mem_flags_e      const flags,
58                             size_t               const size,
59                             skc_subbuf_id_t    * const subbuf_id,
60                             size_t             * const subbuf_size)
61 {
62   if (size == 0)
63     {
64       *subbuf_id = (skc_subbuf_id_t)-1;
65 
66       if (subbuf_size != NULL)
67         *subbuf_size = 0;
68 
69       return NULL;
70     }
71 
72   return runtime->allocator.host.temp.extent +
73     skc_suballocator_subbuf_alloc(&runtime->allocator.host.temp.suballocator,
74                                   runtime->scheduler,
75                                   size,subbuf_id,subbuf_size);
76 }
77 
78 
79 void
skc_runtime_host_temp_free(struct skc_runtime * const runtime,void * const mem,skc_subbuf_id_t const subbuf_id)80 skc_runtime_host_temp_free(struct skc_runtime * const runtime,
81                            void               * const mem,
82                            skc_subbuf_id_t      const subbuf_id)
83 {
84   if (mem == NULL)
85     return;
86 
87   skc_suballocator_subbuf_free(&runtime->allocator.host.temp.suballocator,subbuf_id);
88 }
89 
90 //
91 //
92 //
93 
94 void
skc_allocator_host_create(struct skc_runtime * const runtime)95 skc_allocator_host_create(struct skc_runtime * const runtime)
96 {
97   skc_suballocator_create(runtime,
98                           &runtime->allocator.host.temp.suballocator,
99                           "HOST  ",
100                           runtime->config->suballocator.host.subbufs,
101                           SKC_RUNTIME_HOST_CACHELINE_SIZE,
102                           runtime->config->suballocator.host.size);
103 
104   runtime->allocator.host.temp.extent =
105     skc_runtime_host_perm_alloc(runtime,
106                                 SKC_MEM_FLAGS_READ_WRITE,
107                                 runtime->config->suballocator.host.size);
108 }
109 
110 void
skc_allocator_host_dispose(struct skc_runtime * const runtime)111 skc_allocator_host_dispose(struct skc_runtime * const runtime)
112 {
113   skc_suballocator_dispose(runtime,&runtime->allocator.host.temp.suballocator);
114 
115   skc_runtime_host_perm_free(runtime,runtime->allocator.host.temp.extent);
116 }
117 
118 //
119 //
120 //
121