From 74f49da927277fa06c20e689541bea7e18a6fcbe Mon Sep 17 00:00:00 2001
From: Stephan Seitz <stephan.seitz@fau.de>
Date: Tue, 15 Oct 2019 16:56:54 +0200
Subject: [PATCH] Fix texture uploading

---
 src/pystencils_autodiff/backends/astnodes.py              | 2 ++
 src/pystencils_autodiff/framework_integration/astnodes.py | 7 ++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/pystencils_autodiff/backends/astnodes.py b/src/pystencils_autodiff/backends/astnodes.py
index 0e5bdd4..1dc2594 100644
--- a/src/pystencils_autodiff/backends/astnodes.py
+++ b/src/pystencils_autodiff/backends/astnodes.py
@@ -14,6 +14,7 @@ from os.path import dirname, exists, join
 
 from pystencils.astnodes import FieldPointerSymbol, FieldShapeSymbol, FieldStrideSymbol
 from pystencils.cpu.cpujit import get_cache_config
+from pystencils.include import get_pycuda_include_path, get_pystencils_include_path
 from pystencils_autodiff._file_io import read_template_from_file, write_file
 from pystencils_autodiff.backends.python_bindings import (
     PybindFunctionWrapping, PybindPythonBindings, TensorflowFunctionWrapping,
@@ -105,6 +106,7 @@ class TorchModule(JinjaCppFile):
         torch_extension = load(hash,
                                [file_name],
                                with_cuda=self.is_cuda,
+                               extra_cflags='--std=c++14',
                                extra_include_paths=[
                                    get_pycuda_include_path(), get_pystencils_include_path()])
         return torch_extension
diff --git a/src/pystencils_autodiff/framework_integration/astnodes.py b/src/pystencils_autodiff/framework_integration/astnodes.py
index 8565058..fdfe100 100644
--- a/src/pystencils_autodiff/framework_integration/astnodes.py
+++ b/src/pystencils_autodiff/framework_integration/astnodes.py
@@ -11,13 +11,14 @@ waLBerla currently uses `pystencils-walberla <https://pypi.org/project/pystencil
 """
 import itertools
 from collections.abc import Iterable
+from functools import reduce
 from typing import Any, List, Set
 
 import jinja2
 import numpy as np
-import sympy as sp
 
 import pystencils
+import sympy as sp
 from pystencils.astnodes import KernelFunction, Node, NodeOrExpr, ResolvedFieldAccess
 from pystencils.data_types import TypedSymbol
 from pystencils.kernelparameters import FieldPointerSymbol, FieldShapeSymbol, FieldStrideSymbol
@@ -95,7 +96,7 @@ class NativeTextureBinding(pystencils.backends.cbackend.CustomCodeNode):
 
 cudaTextureDesc {texture_desc}{{}};
 cudaTextureObject_t {texture_object}=0;
-cudaCreateTextureObject(&{texture_object}, &{resource_desc}, &texture_desc, null_ptr);
+cudaCreateTextureObject(&{texture_object}, &{resource_desc}, &{texture_desc}, nullptr);
 {texture_desc}.readMode = cudaReadModeElementType;
 auto {texture_object}Destroyer = [&](){{
    cudaDestroyTextureObject({texture_object});
@@ -153,7 +154,7 @@ auto {texture_object}Destroyer = [&](){{
             device_ptr=self._device_ptr,
             cuda_channel_format=self._get_channel_format_string(),
             bits_per_channel=self._dtype.itemsize * 8,
-            total_size="TODO!!!")
+            total_size=self._dtype.itemsize * reduce(lambda x, y: x*y, self._shape, 1))
         return code
 
 
-- 
GitLab