]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - src/ti/linalg/ticblas/src/ticblas.c
Skip CBLAS DSP initializtion if OFFLOAD is disabled.
[dense-linear-algebra-libraries/linalg.git] / src / ti / linalg / ticblas / src / ticblas.c
1 /******************************************************************************\r
2  * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com\r
3  *   All rights reserved.\r
4  *\r
5  *   Redistribution and use in source and binary forms, with or without\r
6  *   modification, are permitted provided that the following conditions are met:\r
7  *       * Redistributions of source code must retain the above copyright\r
8  *         notice, this list of conditions and the following disclaimer.\r
9  *       * Redistributions in binary form must reproduce the above copyright\r
10  *         notice, this list of conditions and the following disclaimer in the\r
11  *         documentation and/or other materials provided with the distribution.\r
12  *       * Neither the name of Texas Instruments Incorporated nor the\r
13  *         names of its contributors may be used to endorse or promote products\r
14  *         derived from this software without specific prior written permission.\r
15  *\r
16  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
17  *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
18  *   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
19  *   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
20  *   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
21  *   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
22  *   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
23  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
24  *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
25  *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
26  *   THE POSSIBILITY OF SUCH DAMAGE.\r
27  *****************************************************************************/\r
28 #include <ti/libarch/libarch.h>\r
29 #include "../ticblas.h"\r
30 #include "blis.h"\r
31 \r
32 /*=============================================================================\r
33  * This file contains the CBLAS API Extension for TI-DSP. This extension is used\r
34  * in the OpenCL DSP layer for ARM+DSP CBLAS library. It may also be used directly\r
35  * by the user for DSP-only applications. \r
36  *===========================================================================*/\r
37 \r
38 /* Define memory descriptors for memory management */\r
39 lib_memdscr_t blas_mem_vfast;    /* memory descriptor for very fast scratch memory */\r
40 lib_memdscr_t blas_mem_fast;     /* memory descriptor for fast scratch memory */\r
41 lib_memdscr_t blas_mem_medium;   /* memory descriptor for medium speed scratch memory */\r
42 lib_memdscr_t blas_mem_slow;     /* memory descriptor for slow scratch memory */\r
43 \r
44 /* Define an array of memory descriptors by BLAS */\r
45 lib_memdscr_t * blas_memdscr_tab[LIB_MEMTYPE_N] = {\r
46     &blas_mem_vfast,\r
47     &blas_mem_fast,\r
48     &blas_mem_medium,\r
49     &blas_mem_slow\r
50 };\r
51 \r
52 /*==============================================================================\r
53  * This internal function returns the address of the memory descriptor array.\r
54  *============================================================================*/\r
55 void * blasGetMemHandle(void)\r
56 {\r
57     return((void *)&blas_memdscr_tab[0]);\r
58 } /* blasGetMemHandle */\r
59 \r
60 /*==============================================================================\r
61  * External API. Refer to ticblas.h for detailed documentation.\r
62  *============================================================================*/\r
63 void tiCblasGetSizes(size_t *smem_size_vfast,  size_t *smem_size_fast, \r
64                      size_t *smem_size_medium, size_t *smem_size_slow)\r
65 {   \r
66     /* get memory requirement information from BLIS */\r
67     bli_get_mem_sizes(smem_size_vfast, smem_size_fast, smem_size_medium, smem_size_slow);\r
68 } /* tiCblasGetSizes */\r
69 \r
70 /*==============================================================================\r
71  * External API. Refer to ticblas.h for detailed documentation.\r
72  *============================================================================*/\r
73 int tiCblasInit(void * mem_vfast_base,  size_t mem_vfast_size,\r
74                 void * mem_fast_base,   size_t mem_fast_size,\r
75                 void * mem_medium_base, size_t mem_medium_size,\r
76                 void * mem_slow_base,   size_t mem_slow_size)\r
77 {\r
78   size_t mem_vfast_size_req, mem_fast_size_req, mem_medium_size_req, mem_slow_size_req;\r
79   lib_memdscr_t **blas_mem_handle = blasGetMemHandle();\r
80 \r
81   /* Get the memory size requirements by BLIS */\r
82   bli_get_mem_sizes(&mem_vfast_size_req, &mem_fast_size_req, \r
83                     &mem_medium_size_req, &mem_slow_size_req);\r
84     \r
85   /* Verify supplied memory meet requirements */    \r
86   if(  ( (mem_vfast_base  == NULL) || (mem_vfast_size  < mem_vfast_size_req)  )\r
87      ||( (mem_fast_base   == NULL) || (mem_fast_size   < mem_fast_size_req)   )\r
88      ||( (mem_medium_base == NULL) || (mem_medium_size < mem_medium_size_req) )\r
89      ||( (mem_slow_base   == NULL) || (mem_slow_size   < mem_slow_size_req)   )\r
90     ) {\r
91     return(TICBLAS_ERROR_NOMEM);\r
92   }\r
93   else {\r
94     /* Initialize all 4 types of scratch heaps */\r
95     lib_smem_vinit(blas_mem_handle, mem_vfast_base,  mem_vfast_size);\r
96     lib_smem_finit(blas_mem_handle, mem_fast_base,   mem_fast_size);\r
97     lib_smem_minit(blas_mem_handle, mem_medium_base, mem_medium_size);\r
98     lib_smem_sinit(blas_mem_handle, mem_slow_base,   mem_slow_size);      \r
99     \r
100     /* Make a BLIS call to allocate scratch memory from very fast heap, \r
101      * fast heap and medium speed heap for BLIS. Slow memoris are allocated during \r
102      * BLIS compuation. Refer to blis/frame/base/bli_mem.c for detailed information. \r
103      */\r
104     if(bli_scratch_mem_alloc() == BLI_MEM_ALLOC_ERROR) {\r
105       return(TICBLAS_ERROR_MEMALLOC);\r
106     }\r
107     else {\r
108       return(TICBLAS_SUCCESS);\r
109     }\r
110   }\r
111 } /* tiCblasInit */\r
112 \r
113 /*==============================================================================\r
114  * External API. Refer to ticblas.h for detailed documentation.\r
115  *============================================================================*/\r
116 int tiCblasNew(void)\r
117 {\r
118   if(bli_init() == BLIS_SUCCESS) {\r
119     return(TICBLAS_SUCCESS);\r
120   }\r
121   else {\r
122     return(TICBLAS_ERROR_NEW);\r
123   }\r
124 }\r
125 \r
126 /*==============================================================================\r
127  * External API. Refer to ticblas.h for detailed documentation.\r
128  *============================================================================*/\r
129 int tiCblasDelete(void)\r
130 {\r
131   if(bli_finalize() == BLIS_SUCCESS) {\r
132     return(TICBLAS_SUCCESS);\r
133   }\r
134   else {\r
135     return(TICBLAS_ERROR_DELETE);\r
136   }\r
137 }\r
138 \r
139 /* Nothing after this line */\r