Skip to content

Add global_declarations to cbackend

Stephan Seitz requested to merge seitz/pystencils:global-declarations into master

This enables astnodes.Nodes to have a member required_global_declarations by which they can specify a global declaration required for their usage.

In the test, I added a AST-Node Bogus which requires a global declaration. The global declaration can define symbols required in the kernel that will then not appear in the kernel parameters

// Declaration would go here

FUNC_PREFIX void kernel(double * RESTRICT const _data_x, double * RESTRICT const _data_y, double * RESTRICT _data_z, int64_t const _size_1, int64_t const _stride_z_0, int64_t const _stride_z_1)
{
   for (int ctr_0 = 0; ctr_0 < _size_x_0; ctr_0 += 1)
   {
      double * RESTRICT _data_z_00 = _data_z + _stride_z_0*ctr_0;
      double * RESTRICT const _data_y_00 = _data_y + _stride_y_0*ctr_0;
      double * RESTRICT const _data_x_00 = _data_x + _stride_x_0*ctr_0;
      for (int ctr_1 = 0; ctr_1 < _size_x_1; ctr_1 += 1)
      {
         _data_z_00[_stride_z_1*ctr_1] = log(_data_x_00[_stride_x_1*ctr_1]*_data_y_00[_stride_y_1*ctr_1])*_data_y_00[_stride_y_1*ctr_1];
      }
   }
   // Bogus would go here
}

I used this code for my CudaBackend (instead of CBackend) to enable the forward declaration of textures and constant memory.

Merge request reports