]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - blasblisacc/src/ti_cblas_mem_config.c
Reverted blas acc wrapper code by removing changes made to debug OpenCL crash problem.
[dense-linear-algebra-libraries/linalg.git] / blasblisacc / src / ti_cblas_mem_config.c
1 /******************************************************************************
2  * Copyright (c) 2013-2015, Texas Instruments Incorporated - http://www.ti.com/
3  *   All rights reserved.
4  *
5  *   Redistribution and use in source and binary forms, with or without
6  *   modification, are permitted provided that the following conditions are met:
7  *       * Redistributions of source code must retain the above copyright
8  *         notice, this list of conditions and the following disclaimer.
9  *       * Redistributions in binary form must reproduce the above copyright
10  *         notice, this list of conditions and the following disclaimer in the
11  *         documentation and/or other materials provided with the distribution.
12  *       * Neither the name of Texas Instruments Incorporated nor the
13  *         names of its contributors may be used to endorse or promote products
14  *         derived from this software without specific prior written permission.
15  *
16  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  *   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  *   THE POSSIBILITY OF SUCH DAMAGE.
27  *****************************************************************************/
29 /*#include <stdio.h>*/
30 #include "../../ticblas/ticblas.h"
31 #include <libarch.h>
33 #define BLIS_L3_DDR_SIZE_ZERO (0)
35 extern void bli_init();
36 extern void bli_finalize();
38 int bli_l3_mem_config(double *msmc_buf, size_t msmc_buf_size, size_t *l1D_SRAM_size_orig, size_t *l2_SRAM_size_orig)
39 {
40     size_t smem_size_vfast, smem_size_fast, smem_size_med, smem_size_slow;
41     void *l1d_SRAM_ptr, *l2_SRAM_ptr;
42     int l1d_cfg_err, l2_cfg_err;
43     
44     /* First, verify the provided/available memory meet requirements */
45     tiCblasGetSizes(&smem_size_vfast, &smem_size_fast, &smem_size_med, &smem_size_slow);
47     if(  (smem_size_vfast> lib_get_L1D_total_size()) /* total available L1D  */
48        ||(smem_size_fast > lib_get_L2_total_size())  /* total available L2   */
49        ||(smem_size_med  > msmc_buf_size)            /* provided MSMC memory */                 
50        ||(smem_size_slow > BLIS_L3_DDR_SIZE_ZERO)    /* DDR not used         */
51       ) {                                                            
52         return(TICBLAS_INIT_ERROR);
53     }
54     
55     /* Configure L1D if necessary */
56     *l1D_SRAM_size_orig = lib_get_L1D_SRAM_size(); /* get current L1D SRAM size  */
57     l1d_cfg_err = LIB_CACHE_SUCCESS;
58 /*      
59         printf("Original L1D SRAM size is: %d\n", *l1D_SRAM_size_orig);
60         printf("Required L1D SRAM size is: %d\n", smem_size_vfast);
61 */      
62     if(*l1D_SRAM_size_orig < smem_size_vfast) {    /* configure L1D if needs more SRAM */
63       /*printf("Configuring L1D SRAM on all cores.\n");*/
64       #pragma omp parallel                         
65       {
66         l1d_cfg_err = lib_L1D_config_SRAM(smem_size_vfast);  
67       }
68     }  
69 /*
70     #pragma omp parallel                         
71     {
72       int core_id = lib_get_coreID();
73           printf("New L1D SRAM size from core %d is: %d\n", core_id, lib_get_L1D_SRAM_size());
74     }
75 */
76     /* Configure L2 if necessary */
77     *l2_SRAM_size_orig  = lib_get_L2_SRAM_size();   /* get current L2 SRAM size */
78     l2_cfg_err = LIB_CACHE_SUCCESS;
79 /*      
80     printf("Original L2 SRAM size is: %d\n", *l2_SRAM_size_orig);
81     printf("Required L2 SRAM size is: %d\n", smem_size_fast);
82 */      
83     if(*l2_SRAM_size_orig < smem_size_fast) {      /* configure L2 if needs more SRAM */
84       #pragma omp parallel
85       { 
86         l2_cfg_err  = lib_L2_config_SRAM(smem_size_fast);    
87       }
88     }
89     
90     if(l1d_cfg_err || l2_cfg_err) {
91       return(TICBLAS_INIT_ERROR);        
92     }
93 /*
94         printf("New L2 SRAM size is: %d\n", lib_get_L2_SRAM_size());
95 */    
96     /* get L1D and L2 SRAM base address */
97     l1d_SRAM_ptr = lib_get_L1D_SRAM_base();  
98     l2_SRAM_ptr  = lib_get_L2_SRAM_base();   
99 /*  
100         printf("L1D SRAM base address is 0x%x.\n", (unsigned int)l1d_SRAM_ptr);
101         printf("L2  SRAM base address is 0x%x.\n", (unsigned int) l2_SRAM_ptr);
102 */      
103     /* pass allocated memories for heap initialization */
104     return(tiCblasInit(l1d_SRAM_ptr,  smem_size_vfast,
105                        l2_SRAM_ptr,   smem_size_fast,
106                        msmc_buf,      msmc_buf_size, 
107                        NULL,          BLIS_L3_DDR_SIZE_ZERO));
108 } /* bli_l3_mem_config */
110 /*==============================================================================
111  * This function reconfigures L1D and L2 after processing is finished
112  *============================================================================*/
113 int bli_l3_mem_reconfig(size_t l1D_SRAM_size_orig, size_t l2_SRAM_size_orig)
115     int l1d_cfg_err, l2_cfg_err;
116     
117     /* configure L1D back */    
118     l1d_cfg_err = LIB_CACHE_SUCCESS;
119     if(l1D_SRAM_size_orig!=lib_get_L1D_SRAM_size()) {
120       #pragma omp parallel
121       {
122         l1d_cfg_err = lib_L1D_config_SRAM(l1D_SRAM_size_orig);    
123       }
124     }     
126     l2_cfg_err = LIB_CACHE_SUCCESS;
127     if(l2_SRAM_size_orig <= lib_get_L2_SRAM_size()) {
128       #pragma omp parallel
129       {
130         l2_cfg_err  = lib_L2_config_SRAM(l2_SRAM_size_orig);      
131       }
132     }
133     
134     /* configure L1D and L2 back */    
135     if(l1d_cfg_err || l2_cfg_err) {
136       return(-4);
137     }   
138     
139     return(TICBLAS_SUCCESS);            
140 } /* bli_l3_mem_reconfig */
142 /* This function will be removed. Function tiCblasNew() will be used instead. */
143 void ti_bli_init_dsp(char *l3_buf, char *l2_buf)
144 {       
145   printf("In function ti_bli_init_dsp, l3_buff is 0x%x, l2_buf is 0x%x.\n", (unsigned int)l3_buf, (unsigned int)l2_buf);
146   bli_init();
149 /* This function will be removed. Function tiCblasDelete() will be used instead. */
150 void ti_bli_finalize_dsp(void)
152   bli_finalize();