You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/11/23 11:20:53 UTC

[GitHub] [spark] zhengruifeng edited a comment on pull request #30468: [SPARK-33518][ML][WIP] Improve performance of ML ALS recommendForAll by GEMV

zhengruifeng edited a comment on pull request #30468:
URL: https://github.com/apache/spark/pull/30468#issuecomment-732093851


   [GEMV](https://github.com/apache/spark/pull/30468/commits/b6459683e734af3749be3b9ce6047ca22fabfdd9):
   ```
   val ratings = srcFactorsBlocked.crossJoin(dstFactorsBlocked)
         .as[(Array[Int], Array[Float], Array[Int], Array[Float])]
         .mapPartitions { iter =>
           var buffer: Array[Float] = null
           val pq = new BoundedPriorityQueue[(Int, Float)](num)(Ordering.by(_._2))
           iter.flatMap { case (srcIds, srcMat, dstIds, dstMat) =>
             require(srcMat.length == srcIds.length * rank)
             require(dstMat.length == dstIds.length * rank)
             val m = srcIds.length
             val n = dstIds.length
             if (buffer == null || buffer.length < n) {
               buffer = Array.ofDim[Float](n)
             }
   
             Iterator.range(0, m).flatMap { i =>
               BLAS.f2jBLAS.sgemv("T", rank, n, 1.0F, dstMat, 0, rank,
                 srcMat, i * rank, 1, 0.0F, buffer, 0, 1)
   
               pq.clear()
               var j = 0
               while (j < n) { pq += dstIds(j) -> buffer(j); j += 1 }
               val srcId = srcIds(i)
               pq.iterator.map { case (dstId, value) => (srcId, dstId, value) }
             }
           } ++ {
             buffer = null
             pq.clear()
             Iterator.empty
           }
         }
   ```
   
   Then I switch to GEMV, which brings siginificent speedup. The size of `buffer` is reduce to **n**.
   
   ![als_gemv_jobs_2020_11_23_16_55_10](https://user-images.githubusercontent.com/7322292/99955591-9236cb00-2dbf-11eb-84f2-3a2421412a48.png)
   
   ![als_gemv_exe_2020_11_23_16_57_13](https://user-images.githubusercontent.com/7322292/99955609-99f66f80-2dbf-11eb-8ba6-fa64d6e77fa8.png)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org