Skip to content

Commit

Permalink
apply new format
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSiebert1 committed Nov 12, 2024
1 parent fda5543 commit e3cdd14
Show file tree
Hide file tree
Showing 63 changed files with 3,131 additions and 3,136 deletions.
473 changes: 234 additions & 239 deletions ADOL-C/examples/additional_examples/cuda/liborgpu.cu

Large diffs are not rendered by default.

127 changes: 65 additions & 62 deletions ADOL-C/examples/additional_examples/cuda/traceless_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
ADOL-C -- Automatic Differentiation by Overloading in C++
File: traceless_cuda.cu
Revision: $Id$
Contents: computation of coordinate transform,
Contents: computation of coordinate transform,
cuda example described in the manual
Copyright (c) Andrea Walther, Alina Koniaeva
This file is part of ADOL-C. This software is provided as open source.
Any use, reproduction, or distribution of the software constitutes
Any use, reproduction, or distribution of the software constitutes
recipient's acceptance of the terms of the accompanying license file.
---------------------------------------------------------------------------*/

/****************************************************************************/
Expand All @@ -22,79 +22,82 @@

using namespace std;

__global__ void kernel(double* inx, double* outy, double* outderiv) {
__global__ void kernel(double *inx, double *outy, double *outderiv) {

const int index = threadIdx.x ;
const int index1 = threadIdx.y;
const int index2 = blockIdx.x;
const int dim = blockDim.x*blockDim.y;
const int index3 = blockDim.x;
const int index = threadIdx.x;
const int index1 = threadIdx.y;
const int index2 = blockIdx.x;
const int dim = blockDim.x * blockDim.y;
const int index3 = blockDim.x;

// Declare dependent and independent variables as adoubles
adtlc::adouble y[3];
adtlc::adouble x[3];
// Declare dependent and independent variables as adoubles
adtlc::adouble y[3];
adtlc::adouble x[3];

// Read out point for function evaluation
for(int i=0;i<3;i++)
x[i]=inx[index2*dim+index*3+i];
// Read out point for function evaluation
for (int i = 0; i < 3; i++)
x[i] = inx[index2 * dim + index * 3 + i];

// Set direction for calculation of derivatives
x[index1].setADValue(1);
// Set direction for calculation of derivatives
x[index1].setADValue(1);

// Function evaluation
y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]);
y[2] = atan(x[1]/x[0]);
// Function evaluation
y[0] = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
y[1] = atan(sqrt(x[0] * x[0] + x[1] * x[1]) / x[2]);
y[2] = atan(x[1] / x[0]);

for(int i=0; i<3; i++) outy[(index2*index3+index)*3+i]=y[i].getValue();
for(int i=0; i<3; i++) outderiv[(index2*dim+index*3+index1)*3+i]=y[i].getADValue();

for (int i = 0; i < 3; i++)
outy[(index2 * index3 + index) * 3 + i] = y[i].getValue();
for (int i = 0; i < 3; i++)
outderiv[(index2 * dim + index * 3 + index1) * 3 + i] = y[i].getADValue();
}
cudaError_t kernellaunch(double* inx, double* outy, double* outderiv, int n) {
// Create 16 blocks
int Blocks=16;
// Two dimensional (M/Blocks) x 3 blocks
dim3 threadsPerBlock(n/Blocks,3);
// Call kernel function with 16 blocks with (M/Blocks) x 3 threads per block
kernel <<< Blocks, threadsPerBlock >>>( inx, outy, outderiv);
cudaError_t cudaErr = cudaGetLastError();

return cudaErr;

cudaError_t kernellaunch(double *inx, double *outy, double *outderiv, int n) {
// Create 16 blocks
int Blocks = 16;
// Two dimensional (M/Blocks) x 3 blocks
dim3 threadsPerBlock(n / Blocks, 3);

// Call kernel function with 16 blocks with (M/Blocks) x 3 threads per block
kernel<<<Blocks, threadsPerBlock>>>(inx, outy, outderiv);
cudaError_t cudaErr = cudaGetLastError();

return cudaErr;
}

int main() {

int M = 1024;
double *deriv = new double[9 * M];
double *y = new double[3 * M];
double *x = new double[3 * M];

int main(){
// Initialize x_i
for (int k = 0; k < M; k++) {
for (int i = 0; i < 3; ++i)
x[k * 3 + i] = i + 1 / (k + 1);
}

int M=1024;
double* deriv = new double[9*M];
double* y = new double[3*M];
double* x = new double[3*M];
// Allocate array for independent and dependent variables and Jacobian
// matrices on GPU
double *devx;
cudaMalloc((void **)&devx, 3 * M * sizeof(double));

// Initialize x_i
for(int k=0; k < M; k++){
for (int i=0; i<3; ++i)
x[k*3+i] =i + 1/(k+1);}
double *devy;
cudaMalloc((void **)&devy, 3 * M * sizeof(double));

// Allocate array for independent and dependent variables and Jacobian matrices on GPU
double * devx;
cudaMalloc((void**)&devx, 3*M*sizeof(double));
double *devderiv;
cudaMalloc((void **)&devderiv, 3 * 3 * M * sizeof(double));

double * devy;
cudaMalloc((void**)&devy, 3*M*sizeof(double));
// Copy values of independent variables from host to GPU
cudaMemcpy(devx, x, sizeof(double) * 3 * M, cudaMemcpyHostToDevice);

double * devderiv;
cudaMalloc((void**)&devderiv, 3*3*M*sizeof(double));
// Call function to specify amount of blocks and threads to be used
kernellaunch(devx, devy, devderiv, M);

// Copy values of independent variables from host to GPU
cudaMemcpy(devx, x, sizeof(double)*3*M, cudaMemcpyHostToDevice);

// Call function to specify amount of blocks and threads to be used
kernellaunch(devx, devy, devderiv,M);

// Copy values of dependent variables and Jacobian matrices from GPU to host
cudaMemcpy(y, devy, sizeof(double)*3*M, cudaMemcpyDeviceToHost);
// Copy values of dependent variables and Jacobian matrices from GPU to host
cudaMemcpy(y, devy, sizeof(double) * 3 * M, cudaMemcpyDeviceToHost);

cudaMemcpy(deriv, devderiv, sizeof(double)*M*3*3, cudaMemcpyDeviceToHost);
cudaMemcpy(deriv, devderiv, sizeof(double) * M * 3 * 3,
cudaMemcpyDeviceToHost);
}
4 changes: 2 additions & 2 deletions ADOL-C/examples/additional_examples/openmp_exam/liborpar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ using namespace std;
#include "adolc/adolc.h"

#ifdef _OPENMP
#include <adolc/adolc_openmp.h>
#include <omp.h>
#include <adolc/adolc_openmp.h>
#include <omp.h>
#endif

/* calculate path values */
Expand Down
12 changes: 6 additions & 6 deletions ADOL-C/include/adolc/adalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
----------------------------------------------------------------------------*/
#if !defined(ADOLC_ADALLOC_H)
#define ADOLC_ADALLOC_H 1
#define ADOLC_ADALLOC_H 1

#include <adolc/internal/common.h>
#include <adolc/internal/common.h>

/****************************************************************************/
/* Now the C THINGS */
Expand Down Expand Up @@ -57,9 +57,9 @@ ADOLC_DLL_EXPORT void myfree2_ulong(unsigned long int **);

END_C_DECLS

/****************************************************************************/
/* Now the C++ THINGS */
#if defined(__cplusplus)
/****************************************************************************/
/* Now the C++ THINGS */
#if defined(__cplusplus)

/*--------------------------------------------------------------------------*/
/* MEMORY MANAGEMENT UTILITIES */
Expand All @@ -71,7 +71,7 @@ inline void myfree(double *A) { myfree1(A); }
inline void myfree(double **A) { myfree2(A); }
inline void myfree(double ***A) { myfree3(A); }

#endif
#endif

/****************************************************************************/
#endif
86 changes: 43 additions & 43 deletions ADOL-C/include/adolc/adolc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,59 @@
----------------------------------------------------------------------------*/

#if !defined(ADOLC_ADOLC_H)
#define ADOLC_ADOLC_H 1
#define ADOLC_ADOLC_H 1

#include <adolc/internal/common.h>
#include <adolc/internal/common.h>

/****************************************************************************/
/* Now the pure C++ THINGS */
#if defined(__cplusplus)
/*--------------------------------------------------------------------------*/
/* Operator overloading things (active doubles & vectors) */
#include <adolc/adouble.h>
#include <adolc/checkpointing.h>
#include <adolc/edfclasses.h>
#include <adolc/externfcts.h>
#include <adolc/externfcts2.h>
#include <adolc/fixpoint.h>
#endif
/****************************************************************************/
/* Now the pure C++ THINGS */
#if defined(__cplusplus)
/*--------------------------------------------------------------------------*/
/* Operator overloading things (active doubles & vectors) */
#include <adolc/adouble.h>
#include <adolc/checkpointing.h>
#include <adolc/edfclasses.h>
#include <adolc/externfcts.h>
#include <adolc/externfcts2.h>
#include <adolc/fixpoint.h>
#endif

/****************************************************************************/
/* Now the C/C++ THINGS */
/****************************************************************************/
/* Now the C/C++ THINGS */

/*--------------------------------------------------------------------------*/
/* interfaces to basic forward/reverse routines */
#include <adolc/interfaces.h>
/*--------------------------------------------------------------------------*/
/* interfaces to basic forward/reverse routines */
#include <adolc/interfaces.h>

/*--------------------------------------------------------------------------*/
/* interfaces to "Easy To Use" driver routines for ... */
#include <adolc/drivers/drivers.h> /* optimization & nonlinear equations */
#include <adolc/drivers/odedrivers.h> /* ordinary differential equations */
#include <adolc/drivers/psdrivers.h> /* piecewise smooth functions */
#include <adolc/drivers/taylor.h> /* higher order tensors & inverse/implicit functions */
/*--------------------------------------------------------------------------*/
/* interfaces to "Easy To Use" driver routines for ... */
#include <adolc/drivers/drivers.h> /* optimization & nonlinear equations */
#include <adolc/drivers/odedrivers.h> /* ordinary differential equations */
#include <adolc/drivers/psdrivers.h> /* piecewise smooth functions */
#include <adolc/drivers/taylor.h> /* higher order tensors & inverse/implicit functions */

/*--------------------------------------------------------------------------*/
/* interfaces to TAPEDOC package */
#include <adolc/tapedoc/tapedoc.h>
/*--------------------------------------------------------------------------*/
/* interfaces to TAPEDOC package */
#include <adolc/tapedoc/tapedoc.h>

/*--------------------------------------------------------------------------*/
/* interfaces to SPARSE package */
#if defined(SPARSE_DRIVERS)
#include <adolc/sparse/sparse_fo_rev.h>
#include <adolc/sparse/sparsedrivers.h>
#endif
/*--------------------------------------------------------------------------*/
/* interfaces to SPARSE package */
#if defined(SPARSE_DRIVERS)
#include <adolc/sparse/sparse_fo_rev.h>
#include <adolc/sparse/sparsedrivers.h>
#endif

/*--------------------------------------------------------------------------*/
/* parameters */
#include <adolc/param.h>
/*--------------------------------------------------------------------------*/
/* parameters */
#include <adolc/param.h>

/*--------------------------------------------------------------------------*/
/* tape and value stack utilities */
#include <adolc/taping.h>
/*--------------------------------------------------------------------------*/
/* tape and value stack utilities */
#include <adolc/taping.h>

/*--------------------------------------------------------------------------*/
/* allocation utilities */
#include <adolc/adalloc.h>
/*--------------------------------------------------------------------------*/
/* allocation utilities */
#include <adolc/adalloc.h>

/****************************************************************************/
#endif
8 changes: 4 additions & 4 deletions ADOL-C/include/adolc/adolc_fatalerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#ifdef __cplusplus

#ifndef SWIG
#include <cstdio>
#include <exception>
#endif
#ifndef SWIG
#include <cstdio>
#include <exception>
#endif

class FatalError : public std::exception {
protected:
Expand Down
26 changes: 13 additions & 13 deletions ADOL-C/include/adolc/adolc_openmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
---------------------------------------------------------------------------*/
#if !defined(ADOLC_ADOLC_OPENMP_H)
#define ADOLC_ADOLC_OPENMP_H 1
#define ADOLC_ADOLC_OPENMP_H 1

#if !defined(__cplusplus)
#warning ADOLC_OPENMP IS ONLY USEFUL WHEN COMPILED WITH C++ !!!
#else
#if !defined(__cplusplus)
#warning ADOLC_OPENMP IS ONLY USEFUL WHEN COMPILED WITH C++ !!!
#else

#if !defined(_OPENMP)
#error OPENMP NOT ENABLED AT COMPILE TIME !!!
#else
#if !defined(_OPENMP)
#error OPENMP NOT ENABLED AT COMPILE TIME !!!
#else

#include <adolc/internal/common.h>
#include <adolc/internal/common.h>

extern void beginParallel();
extern void endParallel();
Expand Down Expand Up @@ -50,9 +50,9 @@ typedef struct ADOLC_OpenMP_NC {
extern ADOLC_OpenMP ADOLC_OpenMP_Handler;
extern ADOLC_OpenMP_NC ADOLC_OpenMP_Handler_NC;

#define ADOLC_OPENMP firstprivate(ADOLC_OpenMP_Handler)
#define ADOLC_OPENMP_NC firstprivate(ADOLC_OpenMP_Handler_NC)
#define ADOLC_OPENMP firstprivate(ADOLC_OpenMP_Handler)
#define ADOLC_OPENMP_NC firstprivate(ADOLC_OpenMP_Handler_NC)

#endif /* _OPENMP */
#endif /* __cplusplus */
#endif /* ADOLC_ADOLC_OPENMP_H */
#endif /* _OPENMP */
#endif /* __cplusplus */
#endif /* ADOLC_ADOLC_OPENMP_H */
Loading

0 comments on commit e3cdd14

Please sign in to comment.