<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ /* ******************************************************************************
  ~  *
  ~  *
  ~  * This program and the accompanying materials are made available under the
  ~  * terms of the Apache License, Version 2.0 which is available at
  ~  * https://www.apache.org/licenses/LICENSE-2.0.
  ~  *
  ~  *  See the NOTICE file distributed with this work for additional
  ~  *  information regarding copyright ownership.
  ~  * Unless required by applicable law or agreed to in writing, software
  ~  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  ~  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  ~  * License for the specific language governing permissions and limitations
  ~  * under the License.
  ~  *
  ~  * SPDX-License-Identifier: Apache-2.0
  ~  ******************************************************************************/
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.eclipse.deeplearning4j</groupId>
        <artifactId>nd4j-backend-impls</artifactId>
        <version>1.0.0-SNAPSHOT</version>

    </parent>

    <artifactId>nd4j-cuda</artifactId>

    <name>nd4j-cuda</name>

    <properties>
        <cuda.version>12.3</cuda.version>
        <cudnn.version>8.9</cudnn.version>
        <javacpp-presets.cuda.version>1.5.10</javacpp-presets.cuda.version>
        <javacpp.build.output.path>${project.build.directory}/classes/org/nd4j/linalg/jcublas/bindings/${javacpp.platform}${javacpp.platform.extension}</javacpp.build.output.path>
        <module.name>nd4j.cuda</module.name>
        <javacpp.compiler.options>-Wl,--no-undefined</javacpp.compiler.options>
        <libnd4j.functrace>OFF</libnd4j.functrace>

        <libnd4j.outputPath>${project.build.directory}/../../../../../libnd4j/blasbuild/cuda</libnd4j.outputPath>

    </properties>


    <dependencies>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>libnd4j</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-cuda-preset</artifactId>
            <version>${project.version}</version>
        </dependency>


        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <version>${javacpp.version}</version>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <version>${javacpp.version}</version>
            <classifier>${dependency.platform}</classifier>
        </dependency>

        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-native-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Automatic-Module-Name>${module.name}</Automatic-Module-Name>
                                </manifestEntries>
                            </archive>
                            <excludes>
                                <exclude>
                                    org/nd4j/linalg/jcublas/bindings/${javacpp.platform}${javacpp.platform.extension}/*
                                </exclude>
                                <exclude>lib/**</exclude>
                                <exclude>*.dll</exclude>
                                <exclude>*.dylib</exclude>
                                <exclude>*.so</exclude>
                                <exclude>META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</exclude>
                            </excludes>

                        </configuration>
                    </execution>
                    <execution>
                        <id>${javacpp.platform}${javacpp.platform.extension}</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Automatic-Module-Name>${module.name}.binary</Automatic-Module-Name>
                                </manifestEntries>
                            </archive>
                            <classifier>${javacpp.platform}${javacpp.platform.extension}</classifier>
                            <skipIfEmpty>true</skipIfEmpty>
                            <includes>
                                <include>
                                    org/nd4j/linalg/jcublas/bindings/${javacpp.platform}${javacpp.platform.extension}/*
                                </include>
                                <include>lib/**</include>
                                <include>META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>none</phase> </execution>

                    <execution>
                        <id>java-classes</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <packaging>jar</packaging>
                            <artifactId>${project.artifactId}</artifactId>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <file>${project.build.directory}/${project.build.finalName}.jar</file> </configuration>
                    </execution>

                    <execution>
                        <id>native-deps</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <packaging>jar</packaging>
                            <artifactId>${project.artifactId}</artifactId>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <classifier>${javacpp.platform}${javacpp.platform.extension}</classifier>
                            <file>${project.build.directory}/${project.build.finalName}-${javacpp.platform}${javacpp.platform.extension}.jar</file> </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>non-functrace</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <property>
                    <name>!libnd4j.calltrace</name> </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-cuda-preset</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-api</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>cuda</artifactId>
                                <version>${cuda.version}-${cudnn.version}-${javacpp-presets.cuda.version}</version>
                                <classifier>${dependency.platform}</classifier>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <properties>${javacpp.platform}</properties>
                            <propertyKeysAndValues>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${javacpp.platform.sysroot}</value>
                                </property>
                            </propertyKeysAndValues>
                            <classPaths>
                                <classPath>${project.build.outputDirectory}</classPath>
                            </classPaths>
                            <includePaths>
                                <includePath>${libnd4jhome}/blasbuild/cuda/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cuda/flatbuffers-src/include/</includePath>
                                <includePath>${libnd4jhome}/blas</includePath>
                                <includePath>${libnd4jhome}/include</includePath>
                                <includePath>${libnd4jhome}/include/helpers</includePath>
                                <includePath>${libnd4jhome}/include/array</includePath>
                                <includePath>${libnd4jhome}/include/cnpy</includePath>
                                <includePath>${libnd4jhome}/include/execution</includePath>
                                <includePath>${libnd4jhome}/include/exceptions</includePath>
                                <includePath>${libnd4jhome}/include/graph</includePath>
                                <includePath>${libnd4jhome}/include/indexing</includePath>
                                <includePath>${libnd4jhome}/include/memory</includePath>
                                <includePath>${libnd4jhome}/include/performance</includePath>
                            </includePaths>
                            <linkPaths>
                                <linkPath>${libnd4jhome}/blasbuild/cuda</linkPath> </linkPaths>
                            <compilerOptions>
                                <compilerOption>-std=c++17</compilerOption>
                                <compilerOption>-Wl,--no-undefined</compilerOption>
                                <compilerOption>-L${libnd4jhome}/blasbuild/cuda/blas</compilerOption> </compilerOptions>
                        </configuration>
                        <executions>
                            <execution>
                                <id>javacpp-parser</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.parser.skip}</skip>
                                    <deleteJniFiles>false</deleteJniFiles>
                                    <outputDirectory>${project.build.sourceDirectory}</outputDirectory> <classOrPackageName>org.nd4j.presets.cuda.Nd4jCudaPresets</classOrPackageName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>javacpp-compiler</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.compiler.skip}</skip>
                                    <classOrPackageName>org.nd4j.linalg.jcublas.bindings.Nd4jCuda</classOrPackageName>
                                    <copyLibs>true</copyLibs> <configDirectory>${project.build.directory}/classes/META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</configDirectory>
                                    <outputDirectory>${javacpp.build.output.path}</outputDirectory> </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>


        <profile>
            <id>functrace</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>libnd4j.calltrace</name>
                    <value>ON</value> </property>
            </activation>
            <properties>
                <libnd4j.functrace>ON</libnd4j.functrace>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-cuda-preset</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-api</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>cuda</artifactId>
                                <version>${cuda.version}-${cudnn.version}-${javacpp-presets.cuda.version}</version>
                                <classifier>${dependency.platform}</classifier>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <properties>${javacpp.platform}</properties>
                            <deleteJniFiles>false</deleteJniFiles>
                            <propertyKeysAndValues>
                                <property>
                                    <name>libnd4j.functrace</name>
                                    <value>${libnd4j.functrace}</value> </property>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${javacpp.platform.sysroot}</value>
                                </property>
                            </propertyKeysAndValues>
                            <classPaths>
                                <classPath>${project.build.outputDirectory}</classPath>
                            </classPaths>
                            <includePaths>
                                <includePath>${libnd4jhome}/blasbuild/cuda/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cuda/flatbuffers-src/include/</includePath>
                                <includePath>${libnd4jhome}/blas</includePath>
                                <includePath>${libnd4jhome}/include</includePath>
                                <includePath>${libnd4jhome}/include/helpers</includePath>
                                <includePath>${libnd4jhome}/include/array</includePath>
                                <includePath>${libnd4jhome}/include/cnpy</includePath>
                                <includePath>${libnd4jhome}/include/execution</includePath>
                                <includePath>${libnd4jhome}/include/exceptions</includePath>
                                <includePath>${libnd4jhome}/include/graph</includePath>
                                <includePath>${libnd4jhome}/include/indexing</includePath>
                                <includePath>${libnd4jhome}/include/memory</includePath>
                                <includePath>${libnd4jhome}/include/legacy</includePath>
                            </includePaths>
                            <linkPaths>
                                <linkPath>${libnd4jhome}/blasbuild/cuda/blas</linkPath> </linkPaths>
                            <compilerOptions>
                                <compilerOption>${javacpp.compiler.options}</compilerOption> <compilerOption>-finstrument-functions</compilerOption> <compilerOption>-rdynamic</compilerOption> <compilerOption>-ldl</compilerOption> <compilerOption>-lbfd</compilerOption> <compilerOption>-O0</compilerOption> <compilerOption>-DSD_GCC_FUNCTRACE=ON</compilerOption> <compilerOption>-v</compilerOption> <compilerOption>-lunwind</compilerOption> <compilerOption>-ldw</compilerOption> <compilerOption>-Bsymbolic</compilerOption>
                                <compilerOption>-fno-omit-frame-pointer</compilerOption>
                                <compilerOption>-fno-optimize-sibling-calls</compilerOption>
                                <compilerOption>-g</compilerOption> <compilerOption>-fPIC</compilerOption> <compilerOption>-std=c++17</compilerOption>
                                <compilerOption>-L${libnd4jhome}blasbuild/cuda/blas</compilerOption> </compilerOptions>

                        </configuration>
                        <executions>
                            <execution>
                                <id>javacpp-parser</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.parser.skip}</skip>
                                    <outputDirectory>${project.build.sourceDirectory}</outputDirectory>
                                    <classOrPackageName>org.nd4j.presets.cuda.Nd4jCudaPresets</classOrPackageName>
                                    <deleteJniFiles>false</deleteJniFiles>
                                </configuration>
                            </execution>
                            <execution>
                                <id>javacpp-compiler</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.compiler.skip}</skip>
                                    <classOrPackageName>org.nd4j.linalg.jcublas.bindings.Nd4jCuda</classOrPackageName>
                                    <copyLibs>true</copyLibs>
                                    <configDirectory>${project.build.directory}/classes/META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</configDirectory>
                                    <outputDirectory>${javacpp.build.output.path}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>msvc</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <configuration>
                            <compilerOptions>
                                <compilerOption>/MT</compilerOption> </compilerOptions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>libnd4j-assembly</id>
            <activation>
                <property>
                    <name>libnd4j-assembly</name>
                </property>
            </activation>
            <properties>
                <libnd4jhome>${project.build.directory}/libnd4j/</libnd4jhome>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.eclipse.deeplearning4j</groupId>
                    <artifactId>libnd4j</artifactId>
                    <version>${project.version}</version>
                    <type>zip</type>
                    <classifier>${javacpp.platform}-cuda-${cuda.version}</classifier>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>initialize</phase> <goals>
                                <goal>unpack</goal>
                            </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.eclipse.deeplearning4j</groupId>
                                            <artifactId>libnd4j</artifactId>
                                            <version>${project.version}</version>
                                            <type>zip</type>
                                            <classifier>${javacpp.platform}-cuda-${cuda.version}</classifier>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/libnd4j</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>