Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • pystencils pystencils
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pycodegen
  • pystencilspystencils
  • Merge requests
  • !4

Destructuring field binding

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Stephan Seitz requested to merge seitz/pystencils:destructuring-field-binding into master Jul 05, 2019
  • Overview 1
  • Commits 3
  • Pipelines 6
  • Changes 5

Add DestructuringBindingsForFieldClass to use pystencils kernels in a more C++-ish way

DestructuringBindingsForFieldClass defines all field-related variables in its subordinated block. However, it leaves a TypedSymbol of type Field for each field undefined. By that trick we can generate kernels that accept structs as kernelparameters. Either to include a pystencils specific Field struct of the following definition:

template<DTYPE_T, DIMENSION>
struct Field
{
    DTYPE_T* data;
    std::array<int64_t, DIMENSION> shape;
    std::array<int64_t, DIMENSION> stride;
}

or to be able to destructure user defined types like pybind11::array, at::Tensor, tensorflow::Tensor.

The test generates a kernel like that:

FUNC_PREFIX void kernel(Field<double, 2>& x, Field<double, 2>& y, Field<double, 2>& z)
{
   _stride_z_1 = z.stride[1];
   _size_x_0 = x.shape[0];
   _stride_x_1 = x.stride[1];
   _stride_z_0 = z.stride[0];
   _size_x_1 = x.shape[1];
   _stride_y_1 = y.stride[1];
   _data_x = x.data;
   _stride_x_0 = x.stride[0];
   _data_z = z.data;
   _stride_y_0 = y.stride[0];
   _data_y = y.data;
   {
      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];
         }
      }
   }
}
Edited Jul 05, 2019 by Stephan Seitz
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: destructuring-field-binding