Fix concept proposal for DEVsetparam needed for 'alter' and 'resume' command support

This commit is contained in:
Francesco Lannutti 2018-04-28 12:29:15 +02:00 committed by rlar
parent d14f091a2f
commit 9bcc6dedee
9 changed files with 62 additions and 38 deletions

View File

@ -22,6 +22,10 @@ struct GENinstance {
IFuid GENname; /* pointer to character string naming this instance */ IFuid GENname; /* pointer to character string naming this instance */
int GENstate; /* state index number */ int GENstate; /* state index number */
#ifdef USE_CUSPICE
int GENcudaIndex ; /* device index for CUDA */
#endif
/* The actual device instance structs have to place their node elements /* The actual device instance structs have to place their node elements
* right after the the end of struct GENinstance * right after the the end of struct GENinstance
* where they will be accessed by generic GENnode()[] * where they will be accessed by generic GENnode()[]
@ -47,6 +51,8 @@ struct GENmodel { /* model structure for a resistor */
#ifdef USE_CUSPICE #ifdef USE_CUSPICE
unsigned int has_cuda:1 ; /* flag to indicate is the model supports CUDA */ unsigned int has_cuda:1 ; /* flag to indicate is the model supports CUDA */
unsigned int GENinitCUDA:1 ; /* flag to initialize CUDA data */
int GENnInstances ; /* number of instances for CUDA */
#endif #endif
}; };

View File

@ -47,17 +47,17 @@ GENmodel *inModel, CKTcircuit *ckt
/* Determining how many blocks should exist in the kernel */ /* Determining how many blocks should exist in the kernel */
thread_x = 1 ; thread_x = 1 ;
thread_y = 256 ; thread_y = 256 ;
if (model->n_instances % thread_y != 0) if (model->RESnInstances % thread_y != 0)
block_x = (int)((model->n_instances + thread_y - 1) / thread_y) ; block_x = (int)((model->RESnInstances + thread_y - 1) / thread_y) ;
else else
block_x = model->n_instances / thread_y ; block_x = model->RESnInstances / thread_y ;
dim3 thread (thread_x, thread_y) ; dim3 thread (thread_x, thread_y) ;
/* Kernel launch */ /* Kernel launch */
status = cudaGetLastError () ; // clear error status status = cudaGetLastError () ; // clear error status
cuRESload_kernel <<< block_x, thread >>> (model->RESparamGPU, ckt->d_CKTrhsOld, model->n_instances, cuRESload_kernel <<< block_x, thread >>> (model->RESparamGPU, ckt->d_CKTrhsOld, model->RESnInstances,
model->d_PositionVector, ckt->d_CKTloadOutput) ; model->d_PositionVector, ckt->d_CKTloadOutput) ;
cudaDeviceSynchronize () ; cudaDeviceSynchronize () ;

View File

@ -58,7 +58,7 @@ GENmodel *inModel
cudaError_t status ; cudaError_t status ;
RESmodel *model = (RESmodel *)inModel ; RESmodel *model = (RESmodel *)inModel ;
size = (long unsigned int) model->n_instances; size = (long unsigned int) model->RESnInstances ;
/* Space Allocation to GPU */ /* Space Allocation to GPU */
status = cudaMalloc ((void **)&(model->d_PositionVector), size * sizeof(int)) ; status = cudaMalloc ((void **)&(model->d_PositionVector), size * sizeof(int)) ;

View File

@ -48,7 +48,7 @@ GENmodel *inModel
cudaError_t status ; cudaError_t status ;
RESmodel *model = (RESmodel *)inModel ; RESmodel *model = (RESmodel *)inModel ;
size = (long unsigned int) model->n_instances; size = (long unsigned int) model->RESnInstances ;
/* DOUBLE */ /* DOUBLE */
status = cudaMemcpy (model->RESparamGPU.d_RESconductArray, model->RESparamCPU.RESconductArray, size * sizeof(double), cudaMemcpyHostToDevice) ; status = cudaMemcpy (model->RESparamGPU.d_RESconductArray, model->RESparamCPU.RESconductArray, size * sizeof(double), cudaMemcpyHostToDevice) ;

View File

@ -95,6 +95,11 @@ typedef struct sRESinstance {
BindElement *RESnegPosBinding ; BindElement *RESnegPosBinding ;
#endif #endif
#ifdef USE_CUSPICE
#define REScudaIndex gen.GENcudaIndex
#define RESnInstances gen.GENnInstances
#endif
} RESinstance ; } RESinstance ;
#ifdef USE_CUSPICE #ifdef USE_CUSPICE
@ -173,7 +178,7 @@ typedef struct sRESmodel { /* model structure for a resistor */
int *PositionVector ; int *PositionVector ;
int *d_PositionVector ; int *d_PositionVector ;
int n_instances ; #define RESinitCUDA gen.GENinitCUDA
#endif #endif
} RESmodel; } RESmodel;

View File

@ -12,6 +12,10 @@ Modified: Apr 2000 - Paolo Nenzi
#include "ngspice/missing_math.h" #include "ngspice/missing_math.h"
#include "ngspice/fteext.h" #include "ngspice/fteext.h"
#ifdef USE_CUSPICE
#include "ngspice/CUSPICE/CUSPICE.h"
#endif
int int
RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
{ {
@ -86,5 +90,19 @@ RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
return(E_BADPARM); return(E_BADPARM);
} }
RESupdate_conduct(here, FALSE); RESupdate_conduct(here, FALSE);
#ifdef USE_CUSPICE
int status ;
RESmodel *model ;
model = RESmodPtr(here) ;
if (model->RESinitCUDA) {
model->RESparamCPU.RESconductArray[here->REScudaIndex] = here->RESconduct;
status = cuREStemp ((GENmodel *)model);
if (status != 0)
return E_NOMEM;
}
#endif
return(OK); return(OK);
} }

View File

@ -80,28 +80,14 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
} }
#ifdef USE_CUSPICE #ifdef USE_CUSPICE
int i, j, status ; int j, status ;
/* Counting the instances */
for (model = (RESmodel *)inModel ; model != NULL ; model = RESnextModel(model))
{
i = 0 ;
for (here = RESinstances(model); here != NULL ; here = RESnextInstance(here))
{
i++ ;
}
/* How much instances we have */
model->n_instances = i ;
/* This model supports CUDA */
model->gen.has_cuda = 1 ;
}
/* loop through all the resistor models */ /* loop through all the resistor models */
for (model = (RESmodel *)inModel ; model != NULL ; model = RESnextModel(model)) for (model = (RESmodel *)inModel ; model != NULL ; model = RESnextModel(model))
{ {
/* This model supports CUDA */
model->gen.has_cuda = 1 ;
model->offset = ckt->total_n_values ; model->offset = ckt->total_n_values ;
j = 0 ; j = 0 ;
@ -122,7 +108,7 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
j++ ; j++ ;
} }
model->n_values = model->n_instances ; model->n_values = model->RESnInstances ;
ckt->total_n_values += model->n_values ; ckt->total_n_values += model->n_values ;
model->n_Ptr = j ; model->n_Ptr = j ;
@ -130,18 +116,20 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
/* Position Vector assignment */ /* Position Vector assignment */
model->PositionVector = TMALLOC (int, model->n_instances) ; model->PositionVector = TMALLOC (int, model->RESnInstances) ;
for (j = 0 ; j < model->n_instances ; j++) for (j = 0 ; j < model->RESnInstances ; j++)
model->PositionVector [j] = model->offset + j ; model->PositionVector [j] = model->offset + j ;
} }
/* loop through all the resistor models */ /* loop through all the resistor models */
for (model = (RESmodel *)inModel ; model != NULL ; model = RESnextModel(model)) for (model = (RESmodel *)inModel ; model != NULL ; model = RESnextModel(model))
{ {
status = cuRESsetup ((GENmodel *)model) ; status = cuRESsetup ((GENmodel *)model) ;
if (status != 0) if (status != 0)
return (E_NOMEM) ; return (E_NOMEM) ;
model->RESinitCUDA = 1 ;
} }
#endif #endif

View File

@ -30,10 +30,6 @@ REStemp(GENmodel *inModel, CKTcircuit *ckt)
/* loop through all the resistor models */ /* loop through all the resistor models */
for( ; model != NULL; model = RESnextModel(model)) { for( ; model != NULL; model = RESnextModel(model)) {
#ifdef USE_CUSPICE
int i = 0;
#endif
/* loop through all the instances of the model */ /* loop through all the instances of the model */
for (here = RESinstances(model); here != NULL ; for (here = RESinstances(model); here != NULL ;
here=RESnextInstance(here)) { here=RESnextInstance(here)) {
@ -53,12 +49,11 @@ REStemp(GENmodel *inModel, CKTcircuit *ckt)
RESupdate_conduct(here, TRUE); RESupdate_conduct(here, TRUE);
#ifdef USE_CUSPICE #ifdef USE_CUSPICE
model->RESparamCPU.RESposNodeArray[i] = here->RESposNode; model->RESparamCPU.RESposNodeArray[here->REScudaIndex] = here->RESposNode;
model->RESparamCPU.RESnegNodeArray[i] = here->RESnegNode; model->RESparamCPU.RESnegNodeArray[here->REScudaIndex] = here->RESnegNode;
model->RESparamCPU.RESconductArray[i] = here->RESconduct; model->RESparamCPU.RESconductArray[here->REScudaIndex] = here->RESconduct;
i++;
#endif #endif
} }
#ifdef USE_CUSPICE #ifdef USE_CUSPICE

View File

@ -176,8 +176,20 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, struct card *current)
/* create default R model */ /* create default R model */
IFnewUid(ckt, &uid, NULL, "R", UID_MODEL, NULL); IFnewUid(ckt, &uid, NULL, "R", UID_MODEL, NULL);
IFC(newModel, (ckt, type, &(tab->defRmod), uid)); IFC(newModel, (ckt, type, &(tab->defRmod), uid));
#ifdef USE_CUSPICE
tab->defRmod->GENnInstances = 0 ;
tab->defRmod->GENinitCUDA = 0 ;
#endif
} }
IFC(newInstance, (ckt, tab->defRmod, &fast, name)); IFC(newInstance, (ckt, tab->defRmod, &fast, name));
#ifdef USE_CUSPICE
fast->GENcudaIndex = tab->defRmod->GENnInstances ;
tab->defRmod->GENnInstances++ ;
#endif
if (error1 == 1) { /* was a r=val construction */ if (error1 == 1) { /* was a r=val construction */
val = INPevaluate(&line, &error1, 1); /* [<val>] */ val = INPevaluate(&line, &error1, 1); /* [<val>] */
#ifdef TRACE #ifdef TRACE