Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Feb 25, 2025
1 parent a0c74d7 commit b3880ce
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 175 deletions.
27 changes: 13 additions & 14 deletions check/TestPdlp.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "HCheckConfig.h"
#include "HConfig.h"
#include "Highs.h"
#include "SpecialLps.h"
#include "catch.hpp"

#include "HConfig.h"

const bool dev_run = false;
const double double_equal_tolerance = 1e-3;

Expand Down Expand Up @@ -97,19 +96,19 @@ TEST_CASE("pdlp-distillation-lp", "[pdlp]") {
// optimal = false;
// }

run_status = highs.run();
if (dev_run) highs.writeSolution("", 1);
REQUIRE(std::abs(info.objective_function_value - optimal_objective) <
double_equal_tolerance);
if (optimal) {
REQUIRE(run_status == HighsStatus::kOk);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kOptimal);
} else {
REQUIRE(run_status == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kUnknown);
}
run_status = highs.run();
if (dev_run) highs.writeSolution("", 1);
REQUIRE(std::abs(info.objective_function_value - optimal_objective) <
double_equal_tolerance);
if (optimal) {
REQUIRE(run_status == HighsStatus::kOk);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kOptimal);
} else {
REQUIRE(run_status == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kUnknown);
}

// IG todo add iteration count
// IG todo add iteration count
// HighsInt pdlp_iteration_count = highs.getInfo().pdlp_iteration_count;
// REQUIRE(pdlp_iteration_count > 0);
// REQUIRE(pdlp_iteration_count == 160);
Expand Down
124 changes: 63 additions & 61 deletions check/cublas_example.cpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
//Example 2. Application Using C and cuBLAS: 0-based indexing
// Example 2. Application Using C and cuBLAS: 0-based indexing
//-----------------------------------------------------------
#include <cuda_runtime.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cuda_runtime.h>

#include "cublas_v2.h"
#define M 6
#define N 5
#define IDX2C(i,j,ld) (((j)*(ld))+(i))
#define IDX2C(i, j, ld) (((j) * (ld)) + (i))

static __inline__ void modify (cublasHandle_t handle, float *m, int ldm, int n, int p, int q, float alpha, float beta){
cublasSscal (handle, n-q, &alpha, &m[IDX2C(p,q,ldm)], ldm);
cublasSscal (handle, ldm-p, &beta, &m[IDX2C(p,q,ldm)], 1);
static __inline__ void modify(cublasHandle_t handle, float* m, int ldm, int n,
int p, int q, float alpha, float beta) {
cublasSscal(handle, n - q, &alpha, &m[IDX2C(p, q, ldm)], ldm);
cublasSscal(handle, ldm - p, &beta, &m[IDX2C(p, q, ldm)], 1);
}

int main (void){
cudaError_t cudaStat;
cublasStatus_t stat;
cublasHandle_t handle;
int i, j;
float* devPtrA;
float* a = 0;
a = (float *)malloc (M * N * sizeof (*a));
if (!a) {
printf ("host memory allocation failed");
return EXIT_FAILURE;
}
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
a[IDX2C(i,j,M)] = (float)(i * N + j + 1);
}
}
cudaStat = cudaMalloc ((void**)&devPtrA, M*N*sizeof(*a));
if (cudaStat != cudaSuccess) {
printf ("device memory allocation failed");
free (a);
return EXIT_FAILURE;
}
stat = cublasCreate(&handle);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("CUBLAS initialization failed\n");
free (a);
cudaFree (devPtrA);
return EXIT_FAILURE;
int main(void) {
cudaError_t cudaStat;
cublasStatus_t stat;
cublasHandle_t handle;
int i, j;
float* devPtrA;
float* a = 0;
a = (float*)malloc(M * N * sizeof(*a));
if (!a) {
printf("host memory allocation failed");
return EXIT_FAILURE;
}
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
a[IDX2C(i, j, M)] = (float)(i * N + j + 1);
}
stat = cublasSetMatrix (M, N, sizeof(*a), a, M, devPtrA, M);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("data download failed");
free (a);
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
modify (handle, devPtrA, M, N, 1, 2, 16.0f, 12.0f);
stat = cublasGetMatrix (M, N, sizeof(*a), devPtrA, M, a, M);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("data upload failed");
free (a);
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
cudaFree (devPtrA);
}
cudaStat = cudaMalloc((void**)&devPtrA, M * N * sizeof(*a));
if (cudaStat != cudaSuccess) {
printf("device memory allocation failed");
free(a);
return EXIT_FAILURE;
}
stat = cublasCreate(&handle);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("CUBLAS initialization failed\n");
free(a);
cudaFree(devPtrA);
return EXIT_FAILURE;
}
stat = cublasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("data download failed");
free(a);
cudaFree(devPtrA);
cublasDestroy(handle);
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
printf ("%7.0f", a[IDX2C(i,j,M)]);
}
printf ("\n");
}
return EXIT_FAILURE;
}
modify(handle, devPtrA, M, N, 1, 2, 16.0f, 12.0f);
stat = cublasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("data upload failed");
free(a);
return EXIT_SUCCESS;
cudaFree(devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
cudaFree(devPtrA);
cublasDestroy(handle);
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
printf("%7.0f", a[IDX2C(i, j, M)]);
}
printf("\n");
}
free(a);
return EXIT_SUCCESS;
}
139 changes: 69 additions & 70 deletions check/cublas_gpu_start.cpp
Original file line number Diff line number Diff line change
@@ -1,89 +1,88 @@
//Example 2. Application Using C and cuBLAS: 0-based indexing
// Example 2. Application Using C and cuBLAS: 0-based indexing
//-----------------------------------------------------------
#include <cuda_runtime.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <iostream>
#include <cuda_runtime.h>

#include "cublas_v2.h"
#define N 5

int main(void) {
cudaError_t cudaStat;
cublasStatus_t stat;
cublasHandle_t handle;
int i;
float* devPtrA;
float* a = 0;
a = (float*)malloc(N * sizeof(*a));
if (!a) {
printf("host memory allocation failed");
return EXIT_FAILURE;
}

int main (void){
cudaError_t cudaStat;
cublasStatus_t stat;
cublasHandle_t handle;
int i;
float* devPtrA;
float* a = 0;
a = (float *)malloc (N * sizeof (*a));
if (!a) {
printf ("host memory allocation failed");
return EXIT_FAILURE;
}
for (i = 0; i < N; i++) a[i] = (float)(i * N);
for (i = 0; i < N; i++) printf("%7.0f", a[(i)]);
std::cout << std::endl;

for (i = 0; i < N; i++)
a[i] = (float)(i * N);
for (i = 0; i < N; i++)
printf ("%7.0f", a[(i)]);
std::cout << std::endl;

cudaStat = cudaMalloc ((void**)&devPtrA, N*sizeof(*a));
if (cudaStat != cudaSuccess) {
printf ("device memory allocation failed");
free (a);
return EXIT_FAILURE;
}
stat = cublasCreate(&handle);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("CUBLAS initialization failed\n");
free (a);
cudaFree (devPtrA);
return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&devPtrA, N * sizeof(*a));
if (cudaStat != cudaSuccess) {
printf("device memory allocation failed");
free(a);
return EXIT_FAILURE;
}
stat = cublasCreate(&handle);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("CUBLAS initialization failed\n");
free(a);
cudaFree(devPtrA);
return EXIT_FAILURE;
}

stat = cublasSetVector(N, sizeof(*a), a, 1, devPtrA, 1);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("data download failed");
free (a);
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
stat = cublasSetVector(N, sizeof(*a), a, 1, devPtrA, 1);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("data download failed");
free(a);
cudaFree(devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}

float r;

cublasStatus_t status = cublasSnrm2(handle, N, devPtrA, 1, &r);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("error at dnorm");
free (a);
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
float r;

std::cout << "Snorm: " << r << std::endl << std::endl;
cublasStatus_t status = cublasSnrm2(handle, N, devPtrA, 1, &r);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("error at dnorm");
free(a);
cudaFree(devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}

float * b;
b = (float *)malloc (N * sizeof (*b));
std::cout << "Snorm: " << r << std::endl << std::endl;

stat = cublasGetVector(N, sizeof(*a), devPtrA, 1, b, 1);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("data upload failed");
free (a);
cudaFree (devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}
float* b;
b = (float*)malloc(N * sizeof(*b));

cudaFree (devPtrA);
stat = cublasGetVector(N, sizeof(*a), devPtrA, 1, b, 1);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf("data upload failed");
free(a);
cudaFree(devPtrA);
cublasDestroy(handle);
return EXIT_FAILURE;
}

for (i = 0; i < N; i++) {
printf ("%7.0f", b[(i)]);
}
printf ("\n");
cudaFree(devPtrA);
cublasDestroy(handle);

free(a);
return EXIT_SUCCESS;
for (i = 0; i < N; i++) {
printf("%7.0f", b[(i)]);
}
printf("\n");

free(a);
return EXIT_SUCCESS;
}
Loading

0 comments on commit b3880ce

Please sign in to comment.