-
Notifications
You must be signed in to change notification settings - Fork 945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAHOUT-1974 CUDA support #310
Open
nsakharnykh
wants to merge
14
commits into
apache:CUDA
Choose a base branch
from
nsakharnykh:mahout-1974
base: CUDA
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9706bb8
Initial version of CUDA bindings using JCuda
nsakharnykh ab5e635
[WIP]Quick unit test benchmarks.. have not installed cusparse library…
andrewpalumbo eaedfce
Fix parameter name in comments
andrewpalumbo 0d0b4e6
Added test to read env variables:
andrewpalumbo b06678d
add default run size (and a timer)
andrewpalumbo 2cfbf75
Fix error in hard coded unit test
andrewpalumbo 35c540e
Change geometry of test vars for a faster run.
andrewpalumbo 9cc58a6
add in some verbosity for cuda mmul test
andrewpalumbo dd561bc
Cosmetic changes to unit tests
andrewpalumbo cdb6ca0
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maho…
andrewpalumbo e72053d
cosmetic change for user defined variable run
andrewpalumbo 72bbf13
Supply default environment settings for tests.
andrewpalumbo 68e8400
Enable exceptions for JCuda libraries
nsakharnykh 67f41c0
Update version to 0.13.1
nsakharnykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
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. | ||
--> | ||
|
||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.mahout</groupId> | ||
<artifactId>mahout</artifactId> | ||
<version>0.13.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<properties> | ||
<jcuda.jcudaVersion>0.8.0</jcuda.jcudaVersion> | ||
</properties> | ||
|
||
<artifactId>mahout-native-cuda_${scala.compat.version}</artifactId> | ||
|
||
<name>Mahout Native CUDA Bindings</name> | ||
<description>Native Structures and interfaces to be used from Mahout math-scala. | ||
</description> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<!-- create test jar so other modules can reuse the native test utility classes. --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>add-scala-sources</id> | ||
<phase>initialize</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>scala-compile</id> | ||
<phase>process-resources</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>scala-test-compile</id> | ||
<phase>process-test-resources</phase> | ||
<goals> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!--this is what scalatest recommends to do to enable scala tests --> | ||
|
||
<!-- disable surefire --> | ||
<!--<plugin>--> | ||
<!--<groupId>org.apache.maven.plugins</groupId>--> | ||
<!--<artifactId>maven-surefire-plugin</artifactId>--> | ||
<!--<configuration>--> | ||
<!--<skipTests>true</skipTests>--> | ||
<!--</configuration>--> | ||
<!--</plugin>--> | ||
<!-- enable scalatest --> | ||
<plugin> | ||
<groupId>org.scalatest</groupId> | ||
<artifactId>scalatest-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>test</id> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<argLine>-Xmx4g</argLine> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.3</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>properties</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- copy jars to top directory, which is MAHOUT_HOME --> | ||
<plugin> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>1.4</version> | ||
<executions> | ||
<execution> | ||
<id>copy</id> | ||
<phase>package</phase> | ||
<configuration> | ||
<tasks> | ||
<copy file="target/mahout-native-cuda_${scala.compat.version}-${version}.jar" tofile="../mahout-native-cuda_${scala.compat.version}-${version}.jar" /> | ||
</tasks> | ||
</configuration> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
|
||
</build> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mahout-math-scala_${scala.compat.version}</artifactId> | ||
</dependency> | ||
|
||
<!-- 3rd-party --> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</dependency> | ||
|
||
<!-- scala stuff --> | ||
<dependency> | ||
<groupId>org.scalatest</groupId> | ||
<artifactId>scalatest_${scala.compat.version}</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.bytedeco</groupId> | ||
<artifactId>javacpp</artifactId> | ||
<version>1.2.4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jcuda</groupId> | ||
<artifactId>jcuda</artifactId> | ||
<version>${jcuda.jcudaVersion}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jcuda</groupId> | ||
<artifactId>jcusparse</artifactId> | ||
<version>${jcuda.jcudaVersion}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
<profiles> | ||
<profile> | ||
<id>mahout-release</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>generate-scaladoc</id> | ||
<goals> | ||
<goal>doc</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>attach-scaladoc-jar</id> | ||
<goals> | ||
<goal>doc-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>travis</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<!-- Limit memory for unit tests in Travis --> | ||
<argLine>-Xmx4g</argLine> | ||
<!--<argLine>-Djava.library.path=${project.build.directory}/libs/natives/linux-x86_64:${project.build.directory}/libs/natives/linux:${project.build.directory}/libs/natives/maxosx</argLine>--> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<!-- Limit memory for integration tests in Travis --> | ||
<argLine>-Xmx4g</argLine> | ||
<!--<argLine>-Djava.library.path=${project.build.directory}/libs/natives/linux-x86_64:${project.build.directory}/libs/natives/linux:${project.build.directory}/libs/natives/maxosx</argLine>--> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
83 changes: 83 additions & 0 deletions
83
cuda/src/main/scala/org/apache/mahout/cuda/CompressedMatrix.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
// Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
|
||
package org.apache.mahout.cuda | ||
|
||
import java.nio._ | ||
|
||
import jcuda.jcusparse.cusparseIndexBase.CUSPARSE_INDEX_BASE_ZERO | ||
import jcuda.jcusparse.cusparseMatrixType.CUSPARSE_MATRIX_TYPE_GENERAL | ||
import jcuda.jcusparse.cusparseOperation.CUSPARSE_OPERATION_NON_TRANSPOSE | ||
import jcuda.jcusparse.JCusparse._ | ||
import jcuda.jcusparse._ | ||
import jcuda.runtime.JCuda._ | ||
import jcuda.runtime.cudaMemcpyKind._ | ||
|
||
final class CompressedMatrix { | ||
|
||
var row_ptr = new jcuda.Pointer() | ||
var col_ind = new jcuda.Pointer() | ||
var vals = new jcuda.Pointer() | ||
|
||
var trans = CUSPARSE_OPERATION_NON_TRANSPOSE | ||
var descr = new cusparseMatDescr() | ||
|
||
var nrows = 0 | ||
var ncols = 0 | ||
var nonz = 0 | ||
|
||
def this(ctx: Context, nrow: Int, ncol: Int, nonzeros: Int = 0) { | ||
this() | ||
|
||
nrows = nrow | ||
ncols = ncol | ||
cudaMalloc(row_ptr, (nrow+1)*jcuda.Sizeof.INT) | ||
|
||
nonz = nonzeros | ||
if (nonzeros > 0) { | ||
cudaMalloc(col_ind, nonzeros*jcuda.Sizeof.INT) | ||
cudaMalloc(vals, nonzeros*jcuda.Sizeof.DOUBLE) | ||
} | ||
|
||
// create and setup matrix descriptor | ||
cusparseCreateMatDescr(descr) | ||
cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL) | ||
cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO) | ||
} | ||
|
||
def set(rowJumper: Array[Int], | ||
colIndices: Array[Int], | ||
elements: Array[Double], | ||
nrow: Int, | ||
ncol: Int, | ||
nonzeros: Int) { | ||
cudaMemcpy(row_ptr, jcuda.Pointer.to(rowJumper), (nrow+1)*jcuda.Sizeof.INT, cudaMemcpyHostToDevice) | ||
cudaMemcpy(col_ind, jcuda.Pointer.to(colIndices), (nonzeros)*jcuda.Sizeof.INT, cudaMemcpyHostToDevice) | ||
cudaMemcpy(vals, jcuda.Pointer.to(elements), (nonzeros)*jcuda.Sizeof.DOUBLE, cudaMemcpyHostToDevice) | ||
} | ||
|
||
def close() { | ||
cudaFree(row_ptr) | ||
if (nonz > 0) { | ||
cudaFree(col_ind) | ||
cudaFree(vals) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
// Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
|
||
package org.apache.mahout.cuda | ||
|
||
import jcuda.jcusparse.JCusparse._ | ||
import jcuda.jcusparse._ | ||
import jcuda.runtime.JCuda | ||
|
||
final class Context { | ||
|
||
// Enable exceptions for all CUDA libraries | ||
JCuda.setExceptionsEnabled(true) | ||
JCusparse.setExceptionsEnabled(true) | ||
|
||
// Initialize JCusparse library | ||
var handle: jcuda.jcusparse.cusparseHandle = new cusparseHandle() | ||
cusparseCreate(handle) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be
0.13.1-SNAPSHOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done