/* NON-COMMERCIAL, NON-EXCLUSIVE, NON-TRANSFERABLE SOFTWARE LICENSE
Copyright (c) 2021-24, Devito Codes Ltd, 1st Floor, Commerce House Raven Road,
London E18 1HB, United Kingdom.
Definitions:
* "Devito Codes": Refers to Devito Codes Ltd., a company incorporated and operating under the laws of England and Wales, and encompasses all its divisions, affiliates, and subsidiaries involved in the development and licensing of software products.
* "Software": Includes all software products developed by Devito Codes, such as Devito PRO, and any other software titles offered by Devito Codes, along with their associated materials, documentation, and software generated by their respective compilers or runtime environments.
* "Licensee": Denotes any individual, company, or entity that has legally acquired a copy or license of the Software under the terms specified in an Agreement with Devito Codes. This term also encompasses all employees, contractors, and agents acting within the scope of their engagement by the Licensee.
* "Agreement": Refers to the legally binding license agreement executed between the Licensee and Devito Codes, which outlines the terms and conditions under which the Licensee is authorized to use the Software. This Agreement may be specific to a single software product or may encompass multiple products offered by Devito Codes.
* "Protected Data/Software": Encompasses all data, software, algorithms, source and object code, documentation, proprietary methodologies, and intellectual property owned or developed by Devito Codes. This includes, without limitation, all versions and iterations of Devito PRO software, materials, and any output generated by Devito Codes' compilers or software, as well as any other proprietary software and tools developed by Devito Codes.
* "Unauthorized Use": Constitutes any action involving the Protected Data/Software that is not expressly permitted under the terms of the Agreement. This includes, but is not limited to, copying, modifying, distributing, selling, leasing, reverse engineering, decompiling, or incorporating the Protected Data/Software into any external system or software, including data retrieval systems, databases, generative AI models, machine learning models, Retrieval Augmented Generation (RAG) applications, or any form of technology or AI system, without the explicit written consent of Devito Codes.
* "Non-Commercial Use" refers to activities not intended for or directed towards commercial advantage or monetary compensation. This includes, but is not limited to, academic research, educational purposes, and personal projects.
Devito Codes provides the Software on the following terms:
1. Scope of License: The Licensee is hereby granted a non-commercial, non-exclusive, non-transferable license without the right to sublicense the Protected Data/Software for the purpose of internal evaluation, testing, and development within the Licensee's organization. This license explicitly excludes any commercial applications, product development for sale, or external consulting services.
2. Prohibition on Unauthorized Use: The Licensee shall not use, adapt, modify, or incorporate the Protected Data/Software into any software or hardware that is not explicitly authorized by this Agreement. This includes prohibitions against the use of the Protected Data/Software in the development, training, or operation of generative AI, machine learning models, RAG applications, or any form of AI that utilizes external data sources for augmentation without the prior written consent of Devito Codes.
3. Distribution and External Use: The Licensee agrees not to distribute, share, lease, or otherwise make the Protected Data/Software available to any third party, including through cloud services, Software as a Service (SaaS), or any form of redistribution mechanism. The Licensee also agrees not to use the Protected Data/Software to provide any service to external parties that involves the processing of data or computation using the Protected Data/Software.
4. The Licensee is prohibited from reverse engineering, decompiling, disassembling, or otherwise attempting to discover the source code of the Protected Data/Software. This prohibition extends to any form of reverse engineering or hacking intended to access or create unauthorized derivatives of the Software.
5. The Software is experimental and licensed "as is." The license of the Software does not include technical support.
6. The Licensee agrees that it will not license or sell the Software or any other Software, information, or data that incorporate any part of the Software, including derivative works ("Derivatives"), to any other parties.
7. Devito Codes will consider all requests for a commercial license but shall be under no obligation to grant such a license
8. Licensee agrees that any person within the Licensee utilizing the Software will be advised of, and is subject to, the conditions in the License.
9. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Devito Codes Ltd expressly disclaims all warranties, whether express, implied, statutory, or otherwise, with respect to the software provided hereunder, including any warranty of reliability, accuracy, or the absence of errors or defects, and the implied warranty arising from course of performance, course of dealing, or usage of trade. Devito Codes Ltd shall not be liable for any direct, indirect, incidental, special, consequential, or exemplary damages, including but not limited to, damages for loss of profits, goodwill, use, data, or other intangible losses (even if Devito Codes Ltd has been advised of the possibility of such damages), resulting from the use or the inability to use the Software. The Licensee acknowledges and agrees that the entire risk arising out of the use or performance of the Software remains with the Licensee. Notwithstanding any damages that the Licensee might incur for any reason whatsoever (including, without limitation, all damages referenced above and all direct or general damages), the entire liability of Devito Codes Ltd and any of its suppliers under any provision of this License and the Licensee's exclusive remedy for all of the foregoing shall be limited to the amount actually paid by the Licensee for the Software. The foregoing limitations, exclusions, and disclaimers shall apply to the maximum extent permitted by applicable law, even if any remedy fails its essential purpose.
10. All rights, title, and interest in and to all data, information, and inventions that result from the Software by the Licensee shall vest in and belong to the Licensee. Licensee agrees to provide Devito Codes with copies of publications referencing the Software and acknowledge Devito Codes in those publications.
11. The Licensee agrees to notify Devito Codes in writing of any known or suspected distribution or use of the Software not in compliance with the License requirements and to enforce the terms of the License.
12. The Licensee agrees to indemnify and hold harmless Devito Codes against any claims or damages arising from the Licensee's use of the Software, exceeding the scope of this License. This includes any third-party claims related to the Software's use.
13. Intellectual Property Rights: All intellectual property rights in the Protected Data/Software and any derivatives thereof shall remain with Devito Codes. The Licensee acknowledges that no ownership rights are transferred by this Agreement.
14. Compliance with Future Technologies: The Licensee commits to continuously ensuring that the use of the Software, including in the context of emerging technologies and computational techniques, adheres to the terms outlined in this License. Devito Codes will provide guidelines for compliance as new technologies develop, facilitating ongoing lawful use of the Software.
15. Notification of Unauthorized Use: The Licensee shall promptly notify Devito Codes of any unauthorized use, copying, or distribution of the Protected Data/Software, or any breach of this License, of which it becomes aware.
16. Where a clause in this License and the Agreement conflict, the clause in the Agreement will take precedence.
*/
#define _POSIX_C_SOURCE 200809L
#define START(S) struct timeval start_ ## S , end_ ## S ; gettimeofday(&start_ ## S , NULL);
#define STOP(S,T) gettimeofday(&end_ ## S, NULL); T->S += (double)(end_ ## S .tv_sec-start_ ## S.tv_sec)+(double)(end_ ## S .tv_usec-start_ ## S .tv_usec)/1000000;
#define uL0(t,x) u[(t)*x_stride0 + (x)]
#define vL0(t,x) v[(t)*x_stride0 + (x)]
#include "stdlib.h"
#include "math.h"
#include "sys/time.h"
#include "xmmintrin.h"
#include "pmmintrin.h"
#include "cblas.h"
#include "omp.h"
struct dataobj
{
void *restrict data;
int * size;
unsigned long nbytes;
unsigned long * npsize;
unsigned long * dsize;
int * hsize;
int * hofs;
int * oofs;
void * dmap;
} ;
struct profiler
{
double section0;
double section1;
} ;
int Kernel(struct dataobj *restrict A_vec, struct dataobj *restrict u_vec, struct dataobj *restrict v_vec, const float dt, const float h_x, const int time_M, const int time_m, const int x_M, const int x_m, const int nthreads, const int x_size, struct profiler * timers)
{
float *restrict tmp0_vec __attribute__ ((aligned (64)));
posix_memalign((void**)(&tmp0_vec),64,sizeof(float)*(long)x_size);
float *restrict tmp1_vec __attribute__ ((aligned (64)));
posix_memalign((void**)(&tmp1_vec),64,sizeof(float)*(long)x_size);
float *A __attribute__ ((aligned (64))) = (float *) A_vec->data;
float *restrict tmp0 __attribute__ ((aligned (64))) = (float (*)) tmp0_vec;
float *restrict tmp1 __attribute__ ((aligned (64))) = (float (*)) tmp1_vec;
float *u __attribute__ ((aligned (64))) = (float *) u_vec->data;
float *v __attribute__ ((aligned (64))) = (float *) v_vec->data;
const int x_fsz0 = v_vec->size[1];
const int x_stride0 = x_fsz0;
/* Flush denormal numbers to zero in hardware */
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
float r0 = 1.0F/(h_x*h_x);
for (int time = time_m, t0 = (time)%(2), t1 = (time + 1)%(2); time <= time_M; time += 1, t0 = (time)%(2), t1 = (time + 1)%(2))
{
START(section0)
#pragma omp parallel num_threads(nthreads)
{
#pragma omp for schedule(static,1)
for (int x = x_m; x <= x_M; x += 1)
{
tmp0[x] = vL0(t0, x + 2);
}
}
STOP(section0,timers)
cblas_sgemv(CblasRowMajor,CblasNoTrans,5,5,1,A,5,tmp0,1,0,tmp1,1);
START(section1)
#pragma omp parallel num_threads(nthreads)
{
#pragma omp for schedule(dynamic,1)
for (int x = x_m; x <= x_M; x += 1)
{
vL0(t1, x + 2) = dt*r0*tmp1[x] + vL0(t0, x + 2);
uL0(t1, x + 2) = dt*(r0*uL0(t0, x + 1) - 2.0F*r0*uL0(t0, x + 2) + r0*uL0(t0, x + 3)) + uL0(t0, x + 2);
}
}
STOP(section1,timers)
}
free(tmp0_vec);
free(tmp1_vec);
return 0;
}