Commit 6b86917b authored by karius's avatar karius

added cudatest stuff

parent e9a02bf6
......@@ -27,83 +27,94 @@
#define BATCH 1
#define NRANK 3
//
cudaError_t PerfCuFFT(int argc, char **argv, cufftDoubleComplex *h_a){
cudaError_t cudaStatus;
cufftHandle plan;
cufftDoubleComplex *data;
cufftDoubleComplex *result;
cufftDoubleComplex *d_a;
int n[NRANK] = { NX, NY, NZ };
// Choosing CUDA device with newer architect
int dev = findCudaDevice(argc, (const char **)argv);
// Array to read output data from device memory
result = (cufftDoubleComplex*)malloc(sizeof(cufftDoubleComplex)*(NX*NY*NZ)*BATCH);
cudaMalloc((void**)&data, sizeof(cufftDoubleComplex)*(NX*NY*NZ)*BATCH);
if (cudaGetLastError() != cudaSuccess){
fprintf(stderr, "Cuda error: Failed to allocate\n");
goto Error;
}
cudaMalloc((void**)&d_a, sizeof(cufftDoubleComplex)*NX*NY*NZ);
if (cudaGetLastError() != cudaSuccess){
fprintf(stderr, "Cuda error: Failed to allocate\n");
goto Error;
}
// Copy input vectors from host memory to GPU buffers.
cudaStatus = cudaMemcpy(d_a, h_a, sizeof(cufftDoubleComplex)*NX*NY*NZ, cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed!");
goto Error;
}
/* Create a 3D FFT plan. */
if (cufftPlanMany(&plan, NRANK, n,
NULL, 1, NX*NY*NZ, // *inembed, istride, idist
NULL, 1, NX*NY*NZ, // *onembed, ostride, odist
CUFFT_Z2Z, BATCH) != CUFFT_SUCCESS){
fprintf(stderr, "CUFFT error: Plan creation failed");
goto Error;
}
/* Use the CUFFT plan to transform the signal */
if (cufftExecZ2Z(plan, d_a, data, CUFFT_FORWARD) != CUFFT_SUCCESS){
fprintf(stderr, "CUFFT error: ExecZ2Z Forward failed");
goto Error;
}
// Copy output vector from GPU buffer to host memory.
cudaStatus = cudaMemcpy(result, data, sizeof(cufftDoubleComplex)*(NX*NY*NZ)*BATCH, cudaMemcpyDeviceToHost);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed!");
goto Error;
}
cudaStatus = cudaDeviceSynchronize();
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
goto Error;
}
cudaStatus = cudaGetLastError();
if (cudaStatus != cudaSuccess) {printf("cuda error: %s\n", cudaGetErrorString(cudaStatus)); }
for (int i = 0; i < NX; i++){
for (int j = 0; j < NY; j++) {
for (int k = 0; k < NZ; k++) printf("%f, %f ", result[((NZ*NY)*i)+(NZ*j)+k].x, result[((NY*NZ)*i)+(NZ*j)+k].y);
printf("\n");}
printf("\n"); }
Error:
cufftDestroy(plan);
cudaFree(data);
cudaFree(d_a);
return cudaStatus;
}
cudaError_t PerfCuFFT(int argc, char **argv, cufftDoubleComplex *h_a) {
cudaError_t cudaStatus;
cufftHandle plan;
cufftDoubleComplex *data;
cufftDoubleComplex *result;
cufftDoubleComplex *d_a;
int n[NRANK] = { NX, NY, NZ };
std::cout << "through1" << std::endl;
// Choosing CUDA device with newer architect
int dev = findCudaDevice(argc, (const char **) argv);
// Array to read output data from device memory
result = (cufftDoubleComplex*) malloc(
sizeof(cufftDoubleComplex) * (NX * NY * NZ) * BATCH);
std::cout << "through2" << std::endl;
cudaMalloc((void**) &data,
sizeof(cufftDoubleComplex) * (NX * NY * NZ) * BATCH);
if (cudaGetLastError() != cudaSuccess) {
fprintf(stderr, "Cuda error: Failed to allocate\n");
goto Error;
}
std::cout << "through3" << std::endl;
cudaMalloc((void**) &d_a, sizeof(cufftDoubleComplex) * NX * NY * NZ);
if (cudaGetLastError() != cudaSuccess) {
fprintf(stderr, "Cuda error: Failed to allocate\n");
goto Error;
}
// Copy input vectors from host memory to GPU buffers.
cudaStatus = cudaMemcpy(d_a, h_a, sizeof(cufftDoubleComplex) * NX * NY * NZ,
cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed!");
goto Error;
}
std::cout << "through4" << std::endl;
/* Create a 3D FFT plan. */
if (cufftPlanMany(&plan, NRANK, n,
NULL, 1, NX * NY * NZ, // *inembed, istride, idist
NULL, 1, NX * NY * NZ, // *onembed, ostride, odist
CUFFT_Z2Z, BATCH) != CUFFT_SUCCESS) {
fprintf(stderr, "CUFFT error: Plan creation failed");
goto Error;
}
/* Use the CUFFT plan to transform the signal */
if (cufftExecZ2Z(plan, d_a, data, CUFFT_FORWARD) != CUFFT_SUCCESS) {
fprintf(stderr, "CUFFT error: ExecZ2Z Forward failed");
goto Error;
}
// Copy output vector from GPU buffer to host memory.
cudaStatus = cudaMemcpy(result, data,
sizeof(cufftDoubleComplex) * (NX * NY * NZ) * BATCH,
cudaMemcpyDeviceToHost);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed!");
goto Error;
}
std::cout << "through5" << std::endl;
cudaStatus = cudaDeviceSynchronize();
if (cudaStatus != cudaSuccess) {
fprintf(stderr,
"cudaDeviceSynchronize returned error code %d after launching addKernel!\n",
cudaStatus);
goto Error;
}
cudaStatus = cudaGetLastError();
if (cudaStatus != cudaSuccess) {
printf("cuda error: %s\n", cudaGetErrorString(cudaStatus));
}
// for (int i = 0; i < NX; i++) {
// for (int j = 0; j < NY; j++) {
// for (int k = 0; k < NZ; k++)
// printf("%f, %f ", result[((NZ * NY) * i) + (NZ * j) + k].x,
// result[((NY * NZ) * i) + (NZ * j) + k].y);
// printf("\n");
// }
// printf("\n");
// }
Error: cufftDestroy(plan);
cudaFree(data);
cudaFree(d_a);
std::cout << "through6" << std::endl;
return cudaStatus;
}
CMrcReader::CMrcReader() {
// TODO Auto-generated constructor stub
......@@ -241,27 +252,29 @@ void CMrcReader::readData() {
std::cout << data[0] << " " << data[1] << " " << data[2] << " "
<< data[3] << " " << data[4] << " " << data[5] << std::endl;
std::cout << sum / volume << "<->" << bytes << std::endl;
cufftDoubleComplex *Full = new cufftDoubleComplex[volume];
for (int i = 0; i < volume; i++) {
Full[i].x = data[i];
Full[i].y = 0;
}
int argc = 0;
char ** argv;
cudaError_t cudaStatus = PerfCuFFT(argc, argv, Full);
}
// (should) match the order of data "presented" in the matlab script:
float a[] = {2, 5, 6, 9, 4, 6, 4, 6, 8, 5, 0, 3, 3, 7, 9, 1, 8, 6, 5, 8, 9, 5, 2, 3, 4, 8, 0, 5, 7, 9, 5, 9, 8, 7, 1, 3, 6, 8, 1, 6, 5, 2, 7, 6, 9, 1, 2, 0, 6, 9, 5, 4, 7, 3, 5, 7, 8, 2, 9, 3};
// assert((sizeof(a)/sizeof(a[0])) == NX*NY*NZ);
cufftDoubleComplex *Full = new cufftDoubleComplex[NX*NY*NZ] ;
for (int i = 0; i < NX*NY*NZ; i++) {Full[i].x = a[i]; Full[i].y = 0;}
// Running FFT
int argc=0;
char ** argv;
cudaError_t cudaStatus = PerfCuFFT(argc, argv, Full);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "CuFFT failed!");
// return 1;
}
cudaStatus = cudaDeviceReset();
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaDeviceReset failed!");
// return 1;
}
// (should) match the order of data "presented" in the matlab script:
// Running FFT
//
// if (cudaStatus != cudaSuccess) {
// fprintf(stderr, "CuFFT failed!");
//// return 1;
// }
//
// cudaStatus = cudaDeviceReset();
// if (cudaStatus != cudaSuccess) {
// fprintf(stderr, "cudaDeviceReset failed!");
//// return 1;
// }
}
......@@ -270,15 +283,15 @@ CMrcReader::~CMrcReader() {
}
/**
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
////////////////////////////////////////////////////////////////////////////////
//
......@@ -290,7 +303,6 @@ CMrcReader::~CMrcReader() {
// Lecture83.pdf
//
////////////////////////////////////////////////////////////////////////////////
//
//
//
......@@ -301,7 +313,7 @@ CMrcReader::~CMrcReader() {
// cufftDoubleComplex *Full = new cufftDoubleComplex[NX*NY*NZ] ;
// for (int i = 0; i < NX*NY*NZ; i++) {Full[i].x = a[i]; Full[i].y = 0;}
// // Running FFT
// cudaError_t cudaStatus = PerfCuFFT(argc, argv, Full);
// cudaError_t cudaStatus = PerfCuFFT(argc, argv, std::cout << "through" << std::endl; Full);
// if (cudaStatus != cudaSuccess) {
// fprintf(stderr, "CuFFT failed!");
// return 1;
......@@ -316,4 +328,3 @@ CMrcReader::~CMrcReader() {
// return 0;
//}
No preview for this file type
File added
#include <stdio.h>
// 2D float texture
texture<float, cudaTextureType2D, cudaReadModeElementType> texRef;
// Simple transformation kernel
__global__ void transformKernel(float* output, int width, int height,
float theta) {
// Calculate normalized texture coordinates
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
float u = x / (float) width;
float v = y / (float) height;
// Transform coordinates
u -= 0.5f;
v -= 0.5f;
float tu = u * cosf(theta) - v * sinf(theta) + 0.5f;
float tv = v * cosf(theta) + u * sinf(theta) + 0.5f;
// Read from texture and write to global memory
output[y * width + x] = tex2D(texRef, tu, tv);
}
// Host code
int main() {
int width = 3, height = 3;
float h_data[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
h_data[i][j] = i * j;
int size = width * height * sizeof(float);
// Allocate CUDA array in device memory
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0,
cudaChannelFormatKindFloat);
cudaArray* cuArray;
cudaMallocArray(&cuArray, &channelDesc, width, height);
// Copy to device memory some data located at address h_data
// in host memory
cudaMemcpyToArray(cuArray, 0, 0, h_data, size, cudaMemcpyHostToDevice);
// Set texture reference parameters
texRef.addressMode[0] = cudaAddressModeWrap;
texRef.addressMode[1] = cudaAddressModeWrap;
texRef.filterMode = cudaFilterModeLinear;
texRef.normalized = true;
// Bind the array to the texture reference
cudaBindTextureToArray(texRef, cuArray, channelDesc);
// Allocate result of transformation in device memory
float* output;
cudaMalloc(&output, width * height * sizeof(float));
// Invoke kernel
dim3 dimBlock(16, 16);
dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x,
(height + dimBlock.y - 1) / dimBlock.y);
transformKernel<<<dimGrid, dimBlock>>>(output, width, height,
90);
printf ("\n After operation \n ");
for ( int i =0 ; i<3 ; i++ )
{
for ( int j = 0 ; j<3; j++ )
printf ("%f ", h_data [i][j] );
printf ("\n");
}
// Free device memory
cudaFreeArray(cuArray);
cudaFree(output);
return 0;
}
/*
* CudaTest.h
*
* Created on: Jun 25, 2019
* Author: kkarius
*/
#ifndef CUDATEST_H_
#define CUDATEST_H_
class CudaTest {
public:
CudaTest();
virtual ~CudaTest();
};
#endif /* CUDATEST_H_ */
File added
......@@ -17,8 +17,8 @@ LIBS = $(BLAST_THIRD_PARTY_LIBS) $(CMPRS_LIBS) $(NETWORK_LIBS) $(DL_LIBS) $(ORIG
# These settings are necessary for optimized WorkShop builds, due to
# BLAST's own use of them.
CXXFLAGS = $(FAST_CXXFLAGS)
#CPPFLAGS = $(FAST_CPPFLAGS) -I/usr/local/cuda-10.0/include/ -I./cuda_util_include/
CXXFLAGS = $(FAST_CXXFLAGS) -I/usr/local/cuda-10.0/include/ -I./cuda_util_include/
#CPPFLAGS = $(FAST_CPPFLAGS)
### LOCAL_LDFLAGS automatically added
LDFLAGS = $(LOCAL_LDFLAGS) $(FAST_LDFLAGS) -v
......
CC=nvcc
CFLAGS=-I.
all: CudaTest.cu
$(CC) -o CudaTest CudaTest.cu
\ No newline at end of file
No preview for this file type
......@@ -77,7 +77,7 @@
#include <cstdio>
#include <unistd.h>
#include <CXlinkRegister.h>
//#include <CMrcReader.h>
#include <CMrcReader.h>
USING_NCBI_SCOPE;
USING_SCOPE(blast);
......@@ -206,29 +206,30 @@ int CBlastDemoApplication::Run(void) {
// xlr.addXlinkFile(p);
// xlr.addXlinkFile(p2);
// xlr.showSeqEntryRegister();
ProjectManager pm(
"/home/kkarius/git/PFCmodeling/topological_modeling/data/");
pm.alignPdbs();
pm.addManualPdbLocation("lcl|NHistagPaf1w",
boost::filesystem::path(
"/home/kkarius/git/PFCmodeling/topological_modeling/data/pdb/Paf1_Leo1.6gmh.pdb"),"C",371,492);
pm.addManualPdbLocation("lcl|Leo1w",
boost::filesystem::path(
"/home/kkarius/git/PFCmodeling/topological_modeling/data/pdb/Paf1_Leo1.6gmh.pdb"),"D",198,337);
// ProjectManager pm(
// "/home/kkarius/git/PFCmodeling/topological_modeling/data/");
// pm.alignPdbs();
// pm.addManualPdbLocation("lcl|NHistagPaf1w",
// boost::filesystem::path(
// "/home/kkarius/git/PFCmodeling/topological_modeling/data/pdb/Paf1_Leo1.6gmh.pdb"),"C",371,492);
// pm.addManualPdbLocation("lcl|Leo1w",
// boost::filesystem::path(
// "/home/kkarius/git/PFCmodeling/topological_modeling/data/pdb/Paf1_Leo1.6gmh.pdb"),"D",198,337);
// pm.printPdbLocations();
// pm.addAlternatives( { { "Chd1_on5o9g_W.model.pdb" }, {
// "Chd1_conformation2_3mwy.pdb" } });
// pm.addAlternatives( { { "Ctr9.on6gmh_P_autoSwissModel.pdb" }, {
// "Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.pdb" }, {
// "Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.half1.pdb",
// "Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.half2.pdb" } });
// pm.addAlternatives( { { "Paf1_Leo1.6gmh.pdb" }, {
// "Paf1_Leo1.autoSwissModel_on4m6t.pdb" } });
CMrcReader mrcreader;
mrcreader.readHeader("/data/eclipse-workspace/fitter/test/TauA_3.47A_map.mrc");
mrcreader.printHeader();
mrcreader.readData();
// pm.createIMPTopologyAlternatives(boost::filesystem::path("/home/kkarius/git/PFCmodeling/topological_modeling/topology_files/test/"),"all_combis_22.05.19");
// pm.printPdbLocations();
pm.addAlternatives( { { "Chd1_on5o9g_W.model.pdb" }, {
"Chd1_conformation2_3mwy.pdb" } });
pm.addAlternatives( { { "Ctr9.on6gmh_P_autoSwissModel.pdb" }, {
"Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.pdb" }, {
"Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.half1.pdb",
"Ctr9_Cdc73_Paf1_model_on6af0.autoSwissModel.half2.pdb" } });
pm.addAlternatives( { { "Paf1_Leo1.6gmh.pdb" }, {
"Paf1_Leo1.autoSwissModel_on4m6t.pdb" } });
// CMrcReader mrcreader;
// mrcreader.readHeader("/data/eclipse-workspace/fitter/test/TauA_3.47A_map.mrc");
// mrcreader.readData();
pm.createIMPTopologyAlternatives(boost::filesystem::path("/home/kkarius/git/PFCmodeling/topological_modeling/topology_files/test/"),"all_combis_22.05.19");
pm.printPdbLocations();
// pm.printPdbConfiguration("Chd1_conformation2_3mwy.pdb_Ctr9.on6gmh_P_autoSwissModel.pdb_Paf1_Leo1.6gmh.pdb_");
// pm.addXlinkfile("/home/kkarius/git/PFCmodeling/topological_modeling/data/xls/PFC_all_merged.renumbered.csv");
// pm.alignXlinkSignals();
......
......@@ -1650,4 +1650,5 @@ blast_demo.o blast_demo.d : $(wildcard blast_demo.cpp) $(wildcard /usr/include/s
$(wildcard $(includedir)/objects/general/general_macros.hpp) \
$(wildcard CXlinkRegister.h) $(wildcard $(includedir)/util/row_reader_iana_csv.hpp) \
$(wildcard $(includedir)/serial/objistrasnb.hpp) \
$(wildcard $(includedir)/serial/impl/objistrasnb.inl) $(wildcard CPdbIfstream.h)
$(wildcard $(includedir)/serial/impl/objistrasnb.inl) $(wildcard CMrcReader.h) \
$(wildcard CPdbIfstream.h)
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment